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
16
votes
7 answers

java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException

I am trying to generate a dynamic PDF file through the following servlet. import java.io.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import…
Sagar patro
  • 445
  • 1
  • 5
  • 15
16
votes
2 answers

iTextSharp: SplitLate/SplitRows?

I have an issue where I have a table (PdfPTable) that may extend past the length of the page. I have tried looking up how to "split" a table onto more than one page but iTextSharp is pretty poorly documented in this area. Does anyone know how to do…
Jason
  • 51,583
  • 38
  • 133
  • 185
16
votes
3 answers

How to convert iTextPDF Document to Byte Array

I need to convert iTextPDF Document file to byte[] after it's created in memory. I have already tested that I've no problem with creating PDF properly. The problem is how to convert it to byte array to store in DB. Here's my code: Document…
talha06
  • 6,206
  • 21
  • 92
  • 147
16
votes
4 answers

How to change the font-size in PdfPTable?

I am using itextsharp to dynamically write on the pdf. I am creating a table in the pdf document which contains the values from the database. Can someone please tell how to modify the font-size of the values in the table.
Aada
  • 1,591
  • 7
  • 30
  • 57
16
votes
5 answers

How to Add Page number in Footer in PDF by Itextsharp

I am using iTextSharp DLL in ASP.NET code. I am fetching a data into dataset and Add the dataset into PDF table. If my dataset have more 100 rows then 100 rows will be added into PDF table and 3 or 4 page will be created in PDF file. How can I add…
himanshu soni
  • 161
  • 1
  • 1
  • 3
15
votes
4 answers

How to embed font in PDF created from HTML with iText and Flying Saucer?

I have problem with embedding Polish fonts into PDF converted from HTML. My HTML code have style in body: I tried 2 ways of converting such HTML into PDF: FOP with…
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
15
votes
2 answers

Downloaded PDF looks empty although it contains some data

I'm trying to implement a PDF file download functionality with JavaScript. As a response to a POST request I get a PDF file, in Chrome DevTools console it looks like (the oResult data container, fragment): "%PDF-1.4↵%����↵4 0…
Mike
  • 14,010
  • 29
  • 101
  • 161
15
votes
4 answers

Add a page to PDF document using iTextSharp

I would like to add a page to an existing PDF document containing simple text. I have tried the following code that I found on the internet, but so far I haven't got it to work: PdfReader reader = new PdfReader("1.pdf"); Document document = new…
Ahmad Hajou
  • 1,289
  • 5
  • 22
  • 39
15
votes
10 answers

Alternative for LineSeparator in iText old versions?

I'm trying to insert a line separator (you know, that horizontal line that runs across documents) into my document with iText. I've found some resources via Google that use com.lowagie.text.pdf.draw.LineSeparator but the version of iText that I'm…
Fran Fitzpatrick
  • 17,902
  • 15
  • 33
  • 34
15
votes
1 answer

iTextSharp - How to get the position of word on a page

I am using iTextSharp and the reader.GetPageContent method to pull the text out of a PDF. I need to find the rectangle/position for each word found in the document. Is there any way to get the rectangle/position of a word in a PDF using…
Dave
  • 1,721
  • 2
  • 23
  • 46
15
votes
4 answers

Using Fonts in System with iTextSharp

I want to use iTextSharp to write some text. I'm using this method: var font = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED); My question is: does iTextSharp support all fonts in the system fonts directory? Say I…
techno
  • 6,100
  • 16
  • 86
  • 192
15
votes
3 answers

iText(sharp) side margins width

It looks like I can't set left margin to be less then 42pt width. I am setting it to 0f but it always ends as 42pt. If I set margin to any number greater then 0 it just adds it to initial margin of 42pt. I am setting margin of document…
Velja Radenkovic
  • 716
  • 1
  • 6
  • 27
15
votes
4 answers

iText 5.0.0 where did RTF and HTML go?

This question may seem stupid, but, so be it! I have a stupid problem then :-). Well, my problem is this : using this code //PDF generation PdfWriter.getInstance(document, new FileOutputStream("PDFFile.pdf")); //RTF…
hypercube
  • 958
  • 2
  • 16
  • 34
15
votes
2 answers

Custom page size in iTextSharp in C#.NET

I want to create a custom page size which is (5"X2") PDF using iTextSharp in C#. Is there any way to do this? Document doc = new Document(iTextSharp.text.PageSize.A4, 15, 15, 0, 0);
senps
  • 584
  • 2
  • 10
  • 30
15
votes
3 answers

ItextSharp Error on trying to parse html for pdf conversion

I was using the ItextSharp module to convert the below listed html in to a pdf page.
mma
mmar


Click to View Pricing
karry
  • 3,270
  • 3
  • 18
  • 31