Zoom PDF using Java

This tutorial explains how to zoom PDF using Java. It has the IDE settings, a list of steps, and a sample code to apply custom PDF zoom size using Java. You will learn the impact of setting the initial zoom position and zoom factor while opening it in a PDF viewer.

Steps to Zoom PDF File using Java

  1. Establish the environment to use Aspose.PDF for Java to zoom PDF file
  2. Load the source PDF file into the Document object for setting the zoom level
  3. Create a GoToAction object
  4. Set the target page, view offset from the top-left corner, and zoom factor using the XYZExplicitDestination object
  5. Set this action to the loaded document
  6. Save the output PDF file with new zoom settings

Follow these steps to implement PDF Zoom out using Java. It requires setting the OpenAction of the target PDF file as we want when this output PDF file is opened in any PDF viewer, it should open the specific page with custom zoom settings. Use the GoToAction class to define the action by providing the required parameters and calling the setOpenAction() method.

Code to Zoom Out PDF using Java

This code demonstrates how to apply PDF Zoom in using Java with the desired settings when we open it. The XYZExplicitDestination object is used to set the custom settings like the page number, offset from the target page in terms of left-top points, and the zoom factor. The left and top values are referenced from the upper left corner of the page, say if we set the top as a positive value, it will start zooming above the target page. If you set it to some negative value, the initial zoom will start that points below on the target page.

This article has taught us how to zoom PDF when you open it in Acrobat Reader. If you want to rotate a PDF file, refer to the article on how to rotate PDF using Java.

 English