Change Viewer Preferences

Change the viewer preference

  1. Bind the source PDF to the PdfContentEditor facade.
  2. Read the current viewer preference value.
  3. Combine it with the desired additional flag and pass the result to changeViewerPreference(...).
  4. Save the updated PDF document.
public static void changeViewerPreferences(Path inputFile, Path outputFile) {
    PdfContentEditor editor = new PdfContentEditor();
    try {
        editor.bindPdf(inputFile.toString());
        editor.changeViewerPreference(editor.getViewerPreference() | 1);
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}