Skip to content

Feature Request: Allow printing PDF without rendering <Viewer /> into the DOM #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rahitecho opened this issue May 21, 2025 · 0 comments

Comments

@rahitecho
Copy link

Hi, first of all—thanks for the great library! I'm using @react-pdf-viewer/print along with @react-pdf-viewer/core and everything works smoothly when rendering the PDF using the component.

However, I'd like to request a feature that allows printing a PDF without rendering it into the DOM using .

❓Use Case:
I have a use case where I want to programmatically print a PDF (e.g., shipping label) without showing it to the user in the interface. Currently, the printPlugin().print() method only works after has been rendered and loaded into the DOM. If Viewer is not mounted, print() doesn't do anything.

🧩 What I tried:
const printPluginInstance = printPlugin();
const { print } = printPluginInstance;
print(); // Doesn’t work unless is mounted

🛠️ Feature Suggestion:
Expose a method in the printPlugin that allows printing a PDF from a URL directly, without requiring to be rendered. Example API idea:

const printPluginInstance = printPlugin();
await printPluginInstance.printFromUrl(pdfUrl);

This could internally:

Use PDF.js to load the file

Render pages into an off-screen canvas or hidden iframe

Trigger the browser's print dialog

🔄 Workaround:
Right now, the only way to achieve this is by manually creating an iframe with the PDF URL and triggering iframe.contentWindow.print(), but this approach:

Has cross-origin limitations

Doesn’t allow control over page size or print layout

Doesn't benefit from the plugin’s customization options

✅ Expected Outcome:
Ability to print a PDF directly via plugin, without visually rendering it.

Works in headless or minimized UI workflows (e.g., batch label printing).

Let me know if this is feasible or if there’s any recommended workaround using existing APIs!

Thanks again for your great work 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant