Skip to content
Advertisement

PDFBox How to set PDF document security printing to low resolution

TL;DR; How can PDFBox be used to generate a PDF with “low resolution” under Document Seurity > Details > Printing?

I’m trying to create a PDF using Java and I’m trying to set the value of the printing property, under document security, to low resolution.

I’m trying to do this because the application I’m working on, stumbled across this chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=1307219 and I’m trying to understand which part of it is setting such value (and, of course, the part that manages PDFs is an old spaghetti code set of classes)

As far as I understood from PDFBox docs my goal should be achievable by playing with the AccessPermission class and setCanPrintDegraded()

I’ve created a simple class that generates PDFs using PDFBox, however, no matter what I try, every single PDF I create comes out with “high resolution”. Am I using the correct flag? Thanks!

enter image description here

JavaScript

Advertisement

Answer

Found the solution thanks to @TilmanHausherr (see the comments to the question).

In order to get ‘low quality’ under Document Security > Details > Printing

enter image description here

I had to apply the following changes to the original code:

  1. I’ve set the following permissions:

    AccessPermission permission = new AccessPermission(); permission.setCanPrint(true); permission.setCanPrintDegraded(false);

  2. I’ve encrypted the pdf

    Int keyLeght = 128 StandardProtectionPolicy policy = new StandardProtectionPolicy(“test”, “”, permission); policy.setEncryptionKeyLength(keyLength);

Here’s the updated code:

JavaScript
Advertisement