Changing text line spacing

According to the PDF specification, the distance between the baseline of two lines is called the leading. In iText, the default leading is 1.5 times the size of the font. For instance: the default font size is 12 pt, hence the default leading is 18. You can change the leading of a Paragraph by using … Read more

compress pdf with large images via java

I used code below for a proof of concept… Works a treat 🙂 Thanks to Bruno for setting me on the right path 🙂 package compressPDF; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PRStream; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfNumber; import com.itextpdf.text.pdf.PdfObject; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import … Read more

Create Index File(TOC) for merged pdf using itext library in java

You’re asking for something that should be trivial, but that isn’t. Please take a look at the MergeWithToc example. You’ll see that your code to merge PDFs is correct, but in my example, I added one extra feature: chunk = new Chunk(String.format(“Page %d”, pageNo)); if (i == 1) chunk.setLocalDestination(“p” + pageNo); ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(chunk), … Read more

Where is the Origin (x,y) of a PDF page?

The dimensions of a page (aka the page boundaries) are defined in a page dictionary: /MediaBox: the boundaries of the physical medium (the page). This value is mandatory, so you’ll find it in every PDF. /CropBox: the region that is visible when displayed or printed. The /CropBox is equal to or smaller than the /MediaBox. … Read more

iTextSharp international text

The key for proper display of alternate characters sets (Russian, Chinese, Japanese, etc.) is to use IDENTITY_H encoding when creating the BaseFont. Dim bfR As iTextSharp.text.pdf.BaseFont bfR = iTextSharp.text.pdf.BaseFont.CreateFont(“MyFavoriteFont.ttf”, iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED) IDENTITY_H provides unicode support for your chosen font, so you should be able to display pretty much any character. I’ve used it for Russian, … Read more

iText create document with unequal page sizes

I’ve created an UnequalPages example for you that shows how it works: Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); Rectangle one = new Rectangle(70,140); Rectangle two = new Rectangle(700,400); document.setPageSize(one); document.setMargins(2, 2, 2, 2); document.open(); Paragraph p = new Paragraph(“Hi”); document.add(p); document.setPageSize(two); document.setMargins(20, 20, 20, 20); document.newPage(); document.add(p); document.close(); It is important to change … Read more

External signing PDF with iText

There are a number of issues in your code. First of all your code mixes different iText signing API generations. There is the older API generation which requires you to work very near to the PDF internals, and there is the newer (since version 5.3.x) API which is implemented as a layer over the older … Read more