If a value for the parameter is not specified, then the page viewport rectangle will be a centered rectangle with a width and length that is 90% of the page width and length. If the aspect ratios of the page viewport and the world viewport differ, then the lesser scaling factor will be chosen: data inside the world viewport will not be clipped and data outside the world viewport might become visible. The lower left corner of the page has coordinate (0,0) and the top right corner has coordinate (,) where these two values are the page size specified by the parameter Page Size. The format for the parameter is four integers separated by spaces describing the lower left corner and the upper right corner of the viewport/rectangle, specified in typographical points. Import .This parameter determines where to place the map on the page, and how large the map should be on the page. Save this code in a file with the name SettingPosition.java. It creates a PDF document with the name positionOfImage.pdf, adds an image to it, sets it nearer to the center of the page, and saves it in the path C:/itextExamples/ The following Java program demonstrates how to set an image at a desired position on a PDF document using the iText library. Now, add the image object, created in the previous step, using the add() method of the Document class, as shown below.Ĭlose the document using the close() method of the Document class, as shown below. Setting the position of the image to the center of the page Set the position of the image to the coordinates (100, 250) on the document using this method, as shown below. You can set the position of the image in a PDF document using the setFixedPosition() method of the Image. Step 5: Setting the position of the image While instantiating, pass the ImageData object as a parameter to its constructor, as shown below. Now, instantiate the Image class of the package. ImageData data = ImageDataFactory.create(imageFile) String imageFile = "C:/itextExamples/javafxLogo.jpg" As a parameter of this method, pass a string parameter representing the path of the image, as shown below. To create the image object, first of all, create an ImageData object using the create() method of the ImageDataFactory class. Instantiate the Document class by passing the object of the class PdfDocument created in the previous steps, as shown below.ĭocument document = new Document(pdfDoc) 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. Once a PdfDocument object is created, you can add various elements like page, font, file attachment, and event handler using the respective methods provided by its class. PdfDocument pdfDoc = new PdfDocument(writer) Instantiate the PdfDocument class by passing the above created PdfWriter object to its constructor, as shown below. To instantiate this class (in writing mode), you need to pass an object of the class PdfWriter to its constructor. The PdfDocument class is the class that represents the PDF Document in iText. When an object of this type is passed to a PdfDocument (class), every element added to this document will be written to the file specified. String dest = "C:/itextExamples/positionOfImage.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. The constructor of this class accepts a string, representing the path of the file where the PDF is to be created. The PdfWriter class represents the DocWriter for a PDF. You can insert the image in a desired position on the document using the method setFixedPosition() of the Image class.įollowing are the steps to set the position of an image in the PDF document. To add an image to the pdf, create and an object of the image that is required to be added and add it using the add() method of the Document class. While instantiating this class, you need to pass a PdfDocument object as a parameter to its constructor. You can create an empty PDF Document by instantiating the Document class. In this chapter, we will see how to set the position of an image in a PDF document using the iText library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |