Disable Download and Print Options in Our JavaScript PDF Viewer

There are a few options in PSPDFKit for Web that make it possible to prevent or discourage your customers from printing or downloading your PDF documents.

Launch Demo

Printing

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.

You can read more examples on how to prevent printing in our disable printing guide.

Downloading

Due to the nature of the web, opening a PDF document in the browser involves sending its data over to the user’s browser, which makes it impossible to fully prevent the user from downloading it.

However, there are a few ways PSPDFKit for Web can make this more difficult, so as to discourage users who wish to do this.

Launch Demo

Disabling Exporting

You can prevent a user from using the export toolbar item to download your PDF by omitting it from the list of toolbar items provided in the configuration:

instance.setToolbarItems(items => items.filter((item) => item.type !== "export-pdf");

To read more about the download/export button, see our Download/Export Button guide.

Watermarking

You can use text annotations to render text in a PDF with a user’s details — such as their username — to discourage sharing of your document with other customers:

// Create a free text annotation.
const textAnnotation = new PSPDFKit.Annotations.TextAnnotation({
  boundingBox: new PSPDFKit.Geometry.Rect({
    left: 228,
    top: 924,
    width: 600,
    height: 80
  }),
  fontSize: 40,
  text: {
    format: "plain",
    value: `Generated For ${username}`,
  },
  pageIndex: 0
});

// Add the annotations to the document.
await instance.create(textAnnotation);

Using a Password

To prevent unauthorized exporting of your documents, PSPDFKit for Web supports the protection of documents with a password. When saving your PDF from your PDF authoring tool, set a password for it.

Server-Side Rendering

PSPDFKit for Web Server-Backed instances will use the Server to stream the pages it’s looking at as images instead of streaming the complete PDF document to the user’s browser.

Learn more about the PSPDFKit for Web Server-Backed operational mode.