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
18
votes
9 answers

Convert HTML to PDF in MVC with iTextSharp in MVC Razor

I am trying to convert HTML to PDF with iTextSharp in MVC Razor, but everything I have tried has not worked. Does anyone know how to accomplish this?
Ravi
  • 233
  • 1
  • 3
  • 9
18
votes
1 answer

Repeat PdfPTable header in all the continuation pages using iText

How can I repeat the headings of a PdfPTable in all the pages if the length of the table exceeds one page?
SKK
  • 1,705
  • 3
  • 28
  • 50
18
votes
4 answers

iTextSharp - Is it possible to set a different font color for the same cell and row?

I am using the iTextSharp.dll with the following code: var Title = "This is title"; var Description = "This is description"; Innertable.AddCell(new PdfPCell(new Phrase(string.Format("{0} {1}", Title, Description.Trim()), listTextFont)) {…
Nick K
  • 379
  • 1
  • 3
  • 18
18
votes
10 answers

Adding a New Line in iTextSharp

I’ve been trying to solve this problem for a while now to no avail. I have some text in iTextSharp I’m trying to put on a newline. I’ve tried using the \n escape character, Environment.NewLine, and document.Add(new Phrase(Environment.NewLine))…
Andrew De Forest
  • 6,829
  • 14
  • 39
  • 50
17
votes
2 answers

iTextSharp Password Protected PDF

The following question and answer on StackOverflow show how to generate a PDF that cannot be opened without the appropriate password. Password protected PDF using C# I would like to use this framework similarly, but slightly altered to allow my…
Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
17
votes
3 answers

How to set PDF paragraph or font line-height with iTextSharp?

How can I change the line-height of a PDF font or paragraph using iTextSharp?
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
17
votes
1 answer

How can I repeat the headers of an iTextSharp PdfPTable on each page?

How can I get iTextSharp to repeat the headers of a PdfPTable on each page of the generated PDF?
user147031
  • 183
  • 1
  • 2
  • 6
17
votes
4 answers

How to flatten already filled out PDF form using iTextSharp

I'm using iTextSharp to merge a number of pdf files together into a single file. I'm using method described in iTextSharp official tutorials, specifically here, which merges files page by page via PdfWriter and PdfImportedPage. Turns out some of the…
andryuha
  • 1,526
  • 3
  • 15
  • 31
17
votes
3 answers

iTextSharp "The document has no pages."

I'm using iTextSharp to update A PDF's file properties: FileStream fs = File.Open(@"C:\Developer\C#Projects\BylawSearch\0001.pdf", FileMode.Open); Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document,…
witchlightning
  • 271
  • 1
  • 2
  • 10
17
votes
4 answers

iText / BouncyCastle throws "java.lang.VerifyError: class overrides final method equals"

We have an application that creates PDFs unsing jasperreports. It also manipulates said PDFs using iText after they have been created. We recently started using encryption on some PDF. That means before the app can handle the PDF after its creation,…
m00hk00h
  • 507
  • 2
  • 7
  • 21
16
votes
1 answer

Reading a PDF File using iText5 for .NET

I'm using C# as programming platform and iTextSharp to read PDF content. I have used the below code to read the content but it seems it read per page. public string ReadPdfFile(object Filename) { string strText =…
Mark
  • 314
  • 1
  • 5
  • 17
16
votes
5 answers

Rotating PDF in C# using iTextSharp

I am using the below function to split the pdf into two. Though it is spliting the pdf, the content is appearing upside down. How do I rotate it by 180 degrees. Please help. below is the code for the same private static void ExtractPages(string…
acadia
  • 2,301
  • 10
  • 40
  • 57
16
votes
8 answers

How do you combine PDFs in ruby?

This was asked in 2008. Hopefully there's a better answer now. How can you combine PDFs in ruby? I'm using the pdf-stamper gem to fill out a form in a PDF. I'd like to take n PDFs, fill out a form in each of them, and save the result as an n-page…
Paul Schreiber
  • 12,531
  • 4
  • 41
  • 63
16
votes
1 answer

XDocReport converting ODT to PDF with OSGI

To start to work with XDocReport I want to convert ODT to PDF. All my application is OSGi. So I install the following…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
16
votes
2 answers

Can itextsharp.xmlworker render embedded images?

I would like to create dynamic PDF documents using HTML and dynamic images. My code works fine with standard HTML and full paths for the images, but when I try to embed the image inline in the document I get the error Exception Details:…
David Silva Smith
  • 11,498
  • 11
  • 67
  • 91