Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How do you create an image in itext?


Asked by Aliyah Bernard on Dec 05, 2021 FAQ



To create the image object, first of all, create an ImageData object using the create () method of the ImageDataFactory class. As a parameter of this method, pass a string parameter representing the path of the image, as shown below. Now, instantiate the Image class of the com.itextpdf.layout.element package.
One may also ask,
The following example demonstrate how to add an image into a PDF document using the iText library. Image is created using the com.itextpdf.text.Image class. To create an instance of image we can use the Image.getInstance () method. Below we create an image from an image file name an a URL that point to an image resource.
In this manner, iTextSharp supports all the main image types: jpg, tif, gif, bmp, png and wmf. There are a number of ways to create images with iTextSharp using the Image.GetInstance () method. Probably the most used option will be to pass a filesystem path and file name into the method:
Moreover,
To scale image, iText provides API as Image.scaleAbsolute and Image.scaleToFit. scaleAbsolute accepts absolute width and height. scaleToFit fits an image to given width and height. Find the output.
Also Know,
Add the table object created in the previous step using the add () method of the Document class, as shown below. Close the document using the close () method of the Document class, as shown below. The following Java program demonstrates how to add an image to a cell of a table in a PDF document using the iText library.