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.
Web SDK with Document Engine
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.
Web SDK
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 enables 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. Refer to the toolbar API to find out how to remove the print button when it’s disabled.
Print defaults and quality
Nutrient Web SDK defaults to NutrientViewer.PrintMode.DOM with printOptions.quality set to NutrientViewer.PrintQuality.LOW.
To improve quality in document object model (DOM) mode, set one of the following:
printOptions.quality = NutrientViewer.PrintQuality.MEDIUM(150 DPI)printOptions.quality = NutrientViewer.PrintQuality.HIGH(300 DPI)
For best print fidelity and performance on larger documents, consider switching to NutrientViewer.PrintMode.EXPORT_PDF if exposing direct PDF access in the print flow is acceptable.