Disable Print Options in PDFs Using JavaScript
Sometimes you won’t want your users to be able to print the content you serve. This guide outlines the default printing behavior and then shows a few ways to disable printing.
Server-Backed Mode
The printing toolbar item is enabled by default when the download
permission is granted in the JSON Web Token (JWT) used for authentication. This permission is required so that the client can access the raw PDF document needed.
Standalone Mode
The printing toolbar item is always enabled by default.
Enabling and Disabling Printing via the JavaScript API
It’s possible to enable or disable printing via instance.setViewState()
, which allows you to toggle the allowPrinting
flag.
Below is an example of how to disable printing:
instance.setViewState((state) => state.set("allowPrinting", false));
The button will be marked as disabled
in the main toolbar. Please refer to the Toolbar API to find out how to remove the print button when it’s disabled.
Disable High-Quality Printing
When PSPDFKit.PrintMode.DOM
is used as the print mode, the printed document will have a resolution of 300 DPI. You can reduce the resolution to 150 DPI by disabling high-quality printing.