Tools

Tag: iText

You can use the Chunk‘s setUnderline(float thickness, float yPosition) method to add underline or strike through to a chunk. A negative value to the yPosition create an underline while a positive value will produce a strike through.

The following example you’ll see how to create a superscript and subscript text in the pdf document using iText. We can use the Chunk‘s class method called setTextRise(). A positive value will create a superscript text while a negative value will create a subscript text.

You can rotate images in the iText pdf document using the setRotation(final float r) or the setRotationDegrees(final float deg) methods of the com.itextpdf.text.Image class. This method sets the rotation in radian and in degree respectively. Let’s see an example below:

There some methods of the com.itextpdf.text.Image class that can be use to scale the image. These methods include the following: scaleAbsolute(), scaleAbsoluteWidth(), scaleAbsoluteHeight(), scalePercent() and scaleToFit().

To set the absolute position of an image you can use the setAbsolutePosition() method. This method takes two parameters the X and Y coordinate where the image will be placed. In the pdf document the 0, 0 coordinate is located at the left bottom corner of the document. Let’s see an example below:

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.

This example show you how to create nested table in iText. To create a nested table you can add a com.itextpdf.text.pdf.PdfPTable object into a cell using the com.itextpdf.text.pdf.PdfPCell‘s addElement() method.

This example demonstrate how to add an image into a cell in iText. One way to set image into cell’s content is by creating an instance of com.itextpdf.text.pdf.PdfPCell and pass an image object (com.itextpdf.text.Image) in the constructor parameter. The constructor also accept a boolean value whether the image will be fitted into the cell or not.

The following example show you how to set the cell’s border width and color attributes. We can set the width and color at once using the setBorderWidth() and setBorderColor(). Or you can set it individually for each side of the cell’s border. You can also set the background color of a cell using the setBackgroundColor() method.