Print with embed (#5109)

This commit is contained in:
Reece Browne
2025-12-02 13:56:28 +00:00
committed by GitHub
parent 179b569769
commit c3456adc2b
9 changed files with 104 additions and 42 deletions

View File

@@ -18,6 +18,7 @@ import {
SearchActions,
ExportActions,
BookmarkActions,
PrintActions,
} from '@app/contexts/viewer/viewerActions';
import {
BridgeRef,
@@ -125,6 +126,7 @@ interface ViewerContextType {
searchActions: SearchActions;
exportActions: ExportActions;
bookmarkActions: BookmarkActions;
printActions: PrintActions;
// Bridge registration - internal use by bridges
registerBridge: <K extends BridgeKey>(
@@ -277,6 +279,7 @@ export const ViewerProvider: React.FC<ViewerProviderProps> = ({ children }) => {
searchActions,
exportActions,
bookmarkActions,
printActions,
} = createViewerActions({
registry: bridgeRefs,
getScrollState,
@@ -333,6 +336,7 @@ export const ViewerProvider: React.FC<ViewerProviderProps> = ({ children }) => {
searchActions,
exportActions,
bookmarkActions,
printActions,
// Bridge registration
registerBridge,

View File

@@ -65,6 +65,10 @@ export interface BookmarkActions {
setLocalBookmarks: (bookmarks: PdfBookmarkObject[] | null, error?: string | null) => void;
}
export interface PrintActions {
print: () => void;
}
export interface ViewerActionsBundle {
scrollActions: ScrollActions;
zoomActions: ZoomActions;
@@ -75,6 +79,7 @@ export interface ViewerActionsBundle {
searchActions: SearchActions;
exportActions: ExportActions;
bookmarkActions: BookmarkActions;
printActions: PrintActions;
}
interface ViewerActionDependencies {
@@ -332,5 +337,13 @@ export function createViewerActions({
api?.setLocalBookmarks?.(bookmarks ?? null, error);
},
},
printActions: {
print: () => {
const api = registry.current.print?.api;
if (api?.print) {
api.print();
}
},
},
};
}

View File

@@ -49,6 +49,10 @@ export interface SearchAPIWrapper {
goToResult: (index: number) => void;
}
export interface PrintAPIWrapper {
print: () => void;
}
export interface ThumbnailAPIWrapper {
renderThumb: (pageIndex: number, scale: number) => {
toPromise: () => Promise<Blob>;
@@ -132,6 +136,7 @@ export interface BridgeStateMap {
thumbnail: unknown;
export: ExportState;
bookmark: BookmarkState;
print: unknown;
}
export interface BridgeApiMap {
@@ -145,6 +150,7 @@ export interface BridgeApiMap {
thumbnail: ThumbnailAPIWrapper;
export: ExportAPIWrapper;
bookmark: BookmarkAPIWrapper;
print: PrintAPIWrapper;
}
export type BridgeKey = keyof BridgeStateMap;
@@ -164,6 +170,7 @@ export const createBridgeRegistry = (): ViewerBridgeRegistry => ({
thumbnail: null,
export: null,
bookmark: null,
print: null,
});
export function registerBridge<K extends BridgeKey>(