Fix printing on Mac desktop (#5920)

# Description of Changes
Fix #5164 

As I mentioned on the bug
https://github.com/Stirling-Tools/Stirling-PDF/issues/5164#issuecomment-4045170827,
it's impossible to print on Mac currently because
`iframe.contentWindow?.print()` silently does nothing in Tauri on Mac,
but [it seems unlikely that this will be
fixed](https://github.com/tauri-apps/tauri/issues/13451#issuecomment-4048075861).

Instead, I've linked directly to the Mac `PDFKit` framework in Rust to
use its printing functionality instead of Safari's. I believe that
`PDFKit` is what `Preview.app` is using and the print UI that it
generates seems to perform identically, so this should solve the issue
on Mac. Hopefully one day the TS iframe print API will be fixed and
we'll be able to get rid of this code, or [there'll be an official Tauri
plugin for printing which we can use
instead](https://github.com/tauri-apps/plugins-workspace/issues/293).

This implementation should be entirely Mac-specific. Windows & Linux
will continue to use their TS printing (which comes from EmbedPDF)
unless we have a good reason to change them to use a native solution as
well.
This commit is contained in:
James Brunton
2026-03-16 10:49:45 +00:00
committed by GitHub
parent f384e765fb
commit 971321fb19
12 changed files with 248 additions and 4 deletions
@@ -685,7 +685,11 @@ export function LocalEmbedPDF({ file, url, fileName, enableAnnotations = false,
<ExportAPIBridge />
<BookmarkAPIBridge />
<AttachmentAPIBridge />
<PrintAPIBridge />
<PrintAPIBridge
file={file}
url={pdfUrl}
fileName={fileName}
/>
<DocumentPermissionsAPIBridge />
<DocumentReadyWrapper
fallback={
@@ -3,10 +3,16 @@ import { usePrintCapability } from '@embedpdf/plugin-print/react';
import { useViewer } from '@app/contexts/ViewerContext';
import { useDocumentReady } from '@app/components/viewer/hooks/useDocumentReady';
export interface PrintAPIBridgeProps {
file?: File | Blob;
url?: string | null;
fileName?: string;
}
/**
* Connects the PDF print plugin to the shared ViewerContext.
*/
export function PrintAPIBridge() {
export function PrintAPIBridge(_props: PrintAPIBridgeProps) {
const { provides: print } = usePrintCapability();
const { registerBridge } = useViewer();
const documentReady = useDocumentReady();