Viewer preferences

This is a code example of iText PDF, discover more.

8th November 2015
admin-marketing

Switch code for this example

ChangeViewerPreference.java
  1. package sandbox.stamper;
  2.  
  3. import com.itextpdf.text.DocumentException;
  4. import com.itextpdf.text.pdf.PdfName;
  5. import com.itextpdf.text.pdf.PdfReader;
  6. import com.itextpdf.text.pdf.PdfStamper;
  7.  
  8. import java.io.File;
  9. import java.io.FileOutputStream;
  10. import java.io.IOException;
  11.  
  12. import sandbox.WrapToTest;
  13.  
  14. @WrapToTest
  15. public class ChangeViewerPreference {
  16.  
  17.     public static final String SRC = "resources/pdfs/united_states.pdf";
  18.     public static final String DEST = "results/stamper/us_duplex.pdf";
  19.  
  20.     public static void main(String[] args) throws IOException, DocumentException {
  21.         File file = new File(DEST);
  22.         file.getParentFile().mkdirs();
  23.         new ChangeViewerPreference().manipulatePdf(SRC, DEST);
  24.     }
  25.  
  26.  
  27.     public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
  28.         PdfReader reader = new PdfReader(src);
  29.         PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
  30.         stamper.addViewerPreference(PdfName.DUPLEX, PdfName.DUPLEXFLIPLONGEDGE);
  31.         stamper.close();
  32.         reader.close();
  33.     }
  34. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now