Printing

Print API

In addition to using the standard print button from the main toolbar, printing can be managed programmatically via the API.

We support two instance methods for starting and aborting a print task:

1
2
3
4
PSPDFKit.load(configuration).then(instance => {
  instance.print();
  instance.abortPrint();
});
1
2
3
4
PSPDFKit.load(configuration).then(function(instance) {
  instance.print();
  instance.abortPrint();
});

Note that abortPrint is only available for the PSPDFKit.PrintMode.DOM mode.

Print Modes

Our current solution supports two print options so you can make the tradeoff that’s right for your use case.

Choosing a Print Mode

The available modes are:

  • PSPDFKit.PrintMode.DOM
  • PSPDFKit.PrintMode.EXPORT_PDF

It’s possible to configure the printMode via the initial configuration:

1
2
3
PSPDFKit.load({
  printMode: PSPDFKit.PrintMode.EXPORT_PDF
});
1
2
3
PSPDFKit.load({
  printMode: PSPDFKit.PrintMode.EXPORT_PDF
});

It’s also possible to enforce a print mode when printing programmatically via the API:

1
instance.print(PSPDFKit.PrintMode.EXPORT_PDF);
1
instance.print(PSPDFKit.PrintMode.EXPORT_PDF);

PSPDFKit.PrintMode.DOM

PSPDFKit.PrintMode.DOM is the default print mode for PSPDFKit for Web because of its reliability and cross-browser support. This method will render all pages of the PDF document in advance before it sends the results to the printer. It is in all major browsers and will not give your users access to the source PDF file. However, it is CPU bound and memory usage scales with PDF size.

PSPDFKit.PrintMode.EXPORT_PDF

This method is resource efficient and lets you avoid having to render every page in advance, which could balloon memory usage to multiple GBs on PDFs with more than 100 pages.

Google Chrome and Microsoft Internet Explorer provide the APIs required to use the native renderer; meanwhile, as a fallback on other browsers, we generate and open a PDF in a new tab. This allows users to print the PDF in a native PDF reader which can, in contrast to browser-built implementations, talk directly to the connected printer. A drawback of this approach is that it might give users access to the source files.

Below is an overview of all supported browsers and their behaviors.

  • Google Chrome: This browser is fully supported. Printing a PDF page will use the native renderer that is part of the Chrome browser.
  • Internet Explorer 11: This browser is partially supported. In order to support printing, the Windows Media Feature Pack must be installed, which is the case on 99 percent of all Windows installations, unless you use the N or KN editions. If the Windows Media Feature Pack is installed, the browser will ask you to install the Adobe Reader PDF extension upon first use. With this extension enabled, printing works as expected and without opening a new tab.
  • Microsoft Edge: This browser opens a new tab and uses the built-in WinRT PDF Renderer (Windows.Data.Pdf) library. Edge no longer supports ActiveX and thus does not support third-party plugins such as Adobe Reader.
  • Apple Safari: This browser opens a new tab which loads either Apple’s Preview PDF renderer or the Adobe Reader plugin, if installed.
  • Mozilla Firefox: This browser opens a new tab, which renders the PDF via Mozilla’s JavaScript PDF renderer, albeit slowly.

Check out our API documentation for more information.

Enabling Printing

Server-Backed Deployment

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 Deployment

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 our JavaScript API, which allows you to toggle the PSPDFKit.ViewState.allowPrinting Boolean.

Below is an example of how to disable printing:

1
instance.setViewState(state => state.set("allowPrinting", false));
1
2
3
instance.setViewState(function(state) {
  return 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.