
- #Pdf shrink to fit how to#
- #Pdf shrink to fit pdf#
- #Pdf shrink to fit driver#
- #Pdf shrink to fit code#
BeginUpdate () PdfDocument doc = new PdfDocument () Hashtable ht = new Hashtable () for ( int i = 0 i doc. TableControl ) //Resize the column to fit in PDF.
#Pdf shrink to fit pdf#
Import .xobject.GridPDFConverter pdfConvertor = new GridPDFConverter () //Range of rows to be exported in a PDF file pdfConvertor.
#Pdf shrink to fit code#
Save this code in a file with name ShrinkingPDF.java. It creates a PDF document with name shrinkingPDF.pdf, shrinks the image in the pdf, and saves it in the path C:/itextExamples/
#Pdf shrink to fit how to#
The following Java program demonstrates how to shrink contents of a PDF page using the iText library. Instantiate the Document class by passing the object of the class PdfDocument, as shown below.ĭocument document = new Document(destpdf) Ĭlose the document using the close() method of the Document class, as shown below. One of the constructors of this class accepts an object of the class PdfDocument. The Document class of the package is the root element while creating a self-sufficient PDF. PdfFormXObject pageCopy = pyAsFormXObject(destpdf) If you have a short document that only has a small amount of text on the last page, you might be able to shrink it just enough to print on. Now, add the page copy to the canvas object of the destination PDF to the source document, as shown below. Concatenating the affine transform matrix to the current matrixĬncatMatrix(transformationMatrix) Page.getPageSize().getHeight()/ orig.getHeight()/2) Ĭoncatenate the affine transform matrix, created in the previous step, to the matrix of the canvas object of the destination PDF document, as shown below. Page.getPageSize().getWidth()/ orig.getWidth()/2, Shrink original page content using transformation matrixĪffineTransform transformationMatrix = AffineTransform.getScaleInstance( Using the getScaleInstance() method of the AffineTransform class, shrink the contents of a page of the source document, as shown below. Step 4: Shrinking the contents of the source pdf Rectangle orig = origPage.getPageSizeWithRotation() Using this object, get the size of the page of the source document, as shown below. Get a page from the source PDF using the getPage() method of the PdfPage class. Step 3: Opening a page from the existing PDF

#Pdf shrink to fit driver#
PdfDocument srcPdf = new PdfDocument(reader) The easiest way I can think of would be to print it to the Adobe PDF (Distiller) driver with Shrink to Fit turned on. Browse the most used size proportions for PDF files like A4, A5, letter, and more, or create a custom page size. Simply 'Upload' your PDF file, resize it on the web, and free of charge. PdfDocument destpdf = new PdfDocument(writer) You can likewise resize your PDF by moving PDF documents straightforwardly with CocoDoc.

To instantiate this class (in writing mode), you need to pass an object of the class PdfWriter to its constructor.Ĭreate source and destination PDF documents by passing the PdfWriter and PdfReader objects to the constructors, as shown below. The PdfDocument class is the class that represents the PDF Document in iText.

String src = "C:/itextExamples/pdfWithImage.pdf" To read data from an existing pdf, create a PdfReader object as shown below. String dest = "C:/itextExamples/shrinking.pdf" Instantiate the PdfWriter class by passing a string value (representing the path where you need to create a PDF) to its constructor, as shown below. To resolve this, uncheck all the scaling options in the Copies and Adjustments section in the Acrobat Print. The constructor of this class accepts a string, representing the path of the file where the PDF is to be created. This is because Acrobat is scaling the document. The PdfWriter class represents the DocWriter for a PDF. Step 1: Creating a PdfWriter and PdfReader object Shrinking the Content in a PDFįollowing are the steps to shrink the contents of a PDF page using iText library. In this chapter, we will see how to scale an image on a PDF document using the iText library.
