
#Pdf shrink blank area pdf#
pdf, as the PDF format often results in a smaller file size while maintaining the vector nature of line drawings. eps images, we recommend that they be converted to. png files if their file sizes are comparable, as the compile process then doesn't need to call libpng. pdf, in general.pdf images can also compile faster compared to. Line drawings, plots and diagrams are better saved as. jpg is usually a much more space-efficient format for photographs. png can also result in very large file sizes. On MacOS, the sips -Z command is very useful. You can do this with an image manipulation program or if you're using ImageMagick, you can use the convert command. This help article outlines some suggestions on handling large image files, and for choosing appropriate image file formats.įor large image files (where each is >1MB in size), we recommend that raster images (including raster PDF images) be resized, say to 1200px wide or high, so that the file sizes are smaller. Note: External Jar required (Download by clicking here).Overly large image files, or image files using inappropriate file formats, can significantly prolong the compilation process and potentially cause compile timeouts.

Copy the content from the original page using the method copyAsFormXObject(PdfDocument shrunkenDocument)(returns a PdfFormXObject) present in the PdfPage class.Add the above-created matrix with scaled downsizes to the empty canvas.Initialize the PdfCanvas object by passing in the empty page as the parameter.Import PdfCanvas from the package .canvas.Append the shrunken version of the original page to the empty PDF. The static method getScaleInstance(double width, double height) present in the AffineTransform class returns an AffineTransform object with scaled width and scaled height.ħ.New scaled height can be calculated using (emptyPageHeight/originalPageHeight)/2.New scaled width can be calculated using (emptyPageWidth/originalPageWidth)/2.Import AffineTransform from the package.Creating the shrunken version of the original page. addNewPage() methods returns a PdfPage object.Ħ. So to get the size, we add a new page to the empty PDF using the addNewPage() method present in the PdfDocument class.It is not possible to get the page size from an empty PDF.

Get the size of the page from the empty PDF. The method getPageSize() present in the PdfPage class returns a Rectangle object of the particular PdfPage object.ĥ.The method getPage(int pageNumber) present in the PdfDocumen t class returns a PdfPage object of the particular page specified.(PdfPage represents a particular page in a PDF) Get the size of the page from the original PDF. Initialize the PdfDocument by passing the PdfReader object.Ĥ.Pass the path of the original PDF to the PdfReader constructor.(PdfReader allows us to read the content on our PDF file) Assign the path of the original PDF to a String variable.Repeat the above steps for the original PDF.

