How can I set the zoom level of a PDF using iText 7?

A simple iText 7 example showing how to set a specific magnification level for a PDF.

31st May 2016
iText PDF

You can use setOpenAction to open a document with a default display magnification level. The following code uses PdfDocument(), which has been initialized with a PdfWriter() to set a default magnification level of 75% when opening the document:

PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
        pdfDoc.getCatalog().setOpenAction(PdfExplicitDestination.createXYZ(pdfDoc.getPage(1), 0, pdfDoc.getPage(1).getPageSize().getHeight(), 0.75f));
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
            pdfDoc.GetCatalog().SetOpenAction(PdfExplicitDestination.CreateXYZ(pdfDoc.GetPage(1), 0, pdfDoc.GetPage(1).GetPageSize().GetHeight(), 0.75f));

The result is a PDF that opens with a zoom factor of 75%.

Alternatively, in iText 7 a similar method could be used with PdfLinkAnnotation, PdfScreenAnnotation or PdfWidgetAnnotation if you prefer. This uses annotations to trigger the display magnification action for the PDF.

Click this link if you want to see how to achieve the same thing in iText 5.


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