Questions tagged [itext]

Library to create and manipulate PDF documents in Java and C#. Use this tag for code using iText versions up to 5.5.x. For iText versions from 7.0.0 onwards a separate tag "itext7" is available. Remember to also add the tag for the language you're using.

iText is a library that allows you to create and manipulate PDF documents. It enables developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation. Developers can use iText to:

  • Serve PDF documents to a browser
  • Generate dynamic documents from XML files or databases
  • Use PDF's many interactive features
  • Add bookmarks, page numbers, watermarks, etc.
  • Split, concatenate, and manipulate PDF pages
  • Automate filling out of PDF forms
  • Add digital signatures to a PDF file

Typically, iText is used in projects that have one of the following requirements:

  • The content isn't available in advance: it's calculated based on user input or real-time database information.
  • The PDF files can't be produced manually due to the massive volume of content: a large number of pages or documents.
  • Documents need to be created in unattended mode, in a batch process.
  • The content needs to be customized or personalized; for instance, the name of the end user has to be stamped on a number of pages.

Often you'll encounter these requirements in web applications, where content needs to be served dynamically to a browser. Normally, you'd serve this information in the form of HTML, but for some documents, PDF is preferred over HTML for better printing quality, for identical presentation on a variety of platforms, for security reasons, or to reduce the file size.

iText is available in Java as well as in C#.

Official website: https://itextpdf.com/

Useful links

Important

All versions prior to iText 5 (released in December 2009) are obsolete. Commercial and AGPL licenses for iText5 are available from iText Group. According to them, older versions should no longer be used due to technical and legal issues (read the Legal section in The Best iText Questions on StackOverflow for their opinion).

About iText 4

When you look at the Change logs, you can see that iText 2.1.7 was released on July 7, 2009. It was followed by iText 5.0.0 on December 7, 2009. There was no official release of iText 3 or 4. As explained on the official web site, iText jumped from version 2.1.7 to 5.0.0 to synchronize the version numbers of iText and iTextSharp. iTextSharp was already at version 4 while iText was still on version 2.

iText 7

As iText version 7 is a complete rewrite of the API, an additional tag has been introduced to mark questions explicitly referring to iText 7 usage.

Related tags

, ,

13154 questions
20
votes
2 answers

Image Quality using Itext

Is possible to generate a PDF document using Itext which contains imgages with a resolution of 150 dpi. (Seems to be that Itext is reducing the quality of images to 72 dpi.) Thanks
Luixv
  • 8,590
  • 21
  • 84
  • 121
20
votes
6 answers

iTextSharp center align objects within the Document object

Is there a quick and simple way to center align objects within the Document object? Without performing any calculation logic, ie. Get width of page, get width of contents, divide by two, etc. I have a PdfPTable object within a Paragraph object,…
Since_2008
  • 2,331
  • 8
  • 38
  • 68
20
votes
6 answers

How to read PDF form data using iTextSharp?

I am trying to find out if it is possible to read PDF Form data (Forms filled in and saved with the form) using iTextSharp. How can I do this?
Bhuvan
  • 1,523
  • 4
  • 23
  • 49
20
votes
2 answers

Merging PDFs with ITextSharp

What is the optimum way to merge 2 PDF files with ITextSharp in C#? I'm using ASP.NET/.NET3.5.
LordHits
  • 5,054
  • 3
  • 38
  • 51
20
votes
2 answers

compress pdf with large images via java

Looking for a way to compress images in a pdf and to output a pdf for archiving. I cannot compress the images before creation as it would compromise the quality of the print. The size of each pdf is around 8MB with the bulk of this being made up of…
Daniel Mulcahy
  • 653
  • 1
  • 5
  • 14
20
votes
2 answers

How to convert HTML to PDF using iText

import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; public class GeneratePDF { public static void…
Aman Kumar
  • 323
  • 4
  • 5
  • 11
20
votes
6 answers

Right aligning text in PdfPCell

I have a C# application that generates a PDF invoice. In this invoice is a table of items and prices. This is generated using a PdfPTable and PdfPCells. I want to be able to right-align the price column but I cannot seem to be able to - the text…
colincameron
  • 2,696
  • 4
  • 23
  • 46
20
votes
3 answers

Adding absolute positioned text

I'm trying to generate a letter, leaving an empty spot and then paste over the top of it the address, depending on where the envelope window is going to be. So I start off doing this: Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72); var…
colinbashbash
  • 996
  • 2
  • 9
  • 19
20
votes
4 answers

iTextSharp exception: PDF header signature not found

I'm using iTextSharp to read the contents of PDF documents: PdfReader reader = new PdfReader(pdfPath); using (StringWriter output = new StringWriter()) { for (int i = 1; i <= reader.NumberOfPages; i++) …
broke
  • 8,032
  • 16
  • 54
  • 83
19
votes
4 answers

Use custom fonts when creating pdf using iReport

iReport Version : 3.7.1 I approached this problem in two ways. My first method I am creating a pdf page in iReport and I have one of the fields (from database) set to a font Gujarati-Salarl (A font for a regional language of India). This font is…
Sangeet Menon
  • 9,555
  • 8
  • 40
  • 58
19
votes
6 answers

How to solve pdf header signature not found error?

I'm using iText in my java program for editing an existing pdf.The generated pdf could not open and it shows pdf header signature not found error.I'm using both my input and output file in a same name. private static String INPUTFILE =…
BobDroid
  • 1,898
  • 5
  • 19
  • 39
19
votes
6 answers

Page count of Pdf with Java

at the moment I am using itext to read the page count of a pdf. This takes quite long because the lib seems to scan the whole file. Is the page information somewhere in the header of the pdf, or is a full filescan needed?
hans sausage
  • 221
  • 1
  • 3
  • 4
19
votes
4 answers

Creating a pdf file in android programmatically and writing in it

I'm trying to create a pdf file inside my app, save it on the external storage the open it. Saving a file isn't an issue for me, nor is opening one, my issue is with creating one and writing in it. So after some research online I found the following…
Husayn Hakeem
  • 4,184
  • 1
  • 16
  • 31
19
votes
2 answers

Changing text line spacing

I'm creating a PDF document consisting of text only, where all the text is the same point size and font family but each character could potentially be a different color. Everything seems to work fine using the code snippet below, but the default…
BenevolentDeity
  • 693
  • 1
  • 4
  • 18
19
votes
3 answers

itextsharp: what is the height of a regular PDF page in pixels?

What is the height of a regular PDF page in pixels? I heard it was something like this: Dim pgSize As New iTextSharp.text.Rectangle(595, 792) but I am adding an image that takes up maybe half the height, and even though pgSize looks like a full…
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062