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
27
votes
2 answers

iTextsharp landscape document

I am trying to create Landscape PDF using iTextSharp but It is still showing portrait. I am using following code with rotate: Document document = new Document(PageSize.A4, 0, 0, 150, 20); FileStream msReport = new…
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316
26
votes
7 answers

Align Paragraph at the center of the page

I am using itext to generate pdf file. I want to align my title in the middle of the page. Presently i am using like this Paragraph preface = new Paragraph(); for (int i = 0; i < 10; i++) { preface.add(new Paragraph(" ")); } Is it correct or…
PSR
  • 39,804
  • 41
  • 111
  • 151
25
votes
2 answers

iText cell borders cutting through text

I am writing a program that generates a pdf or rtf file with a table in it, using iText. I used the iText class table and cell, rather than the more specific RtfTable or pdfTable so that either file can be generated at the end. I needed to set the…
twpc
  • 709
  • 3
  • 16
  • 26
25
votes
11 answers

Generate PDF based on HTML code (iTextSharp, PDFSharp?)

Does the library PDFSharp can - like iTextSharp - generate PDF files *take into account HTML formatting *? (bold (strong), spacing (br), etc.) Previously I used iTextSharp and roughly handled in such a way (code below): string encodingMetaTag =…
TomashUfx
  • 251
  • 1
  • 3
  • 5
25
votes
2 answers

How can add space\margin between two elements in iTextSharp\iText?

I am pretty new in iTextSharpt (the iText porting for C#) and I have the following doubt. In my code I have something like it: iTextSharp.text.Paragraph titolo = new iTextSharp.text.Paragraph(currentVuln.Title, _fontTitolo0); titolo.Alignment =…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
25
votes
7 answers

iText Image Resize

I have a watermark that I would like to put into my pdf. The watermark is a .bmp image, and is 2290 x 3026. I am having a lot of trouble trying to resize this picture to fit the page, does anyone have any suggestions? Document document = new…
Failsafe
  • 750
  • 2
  • 7
  • 23
24
votes
3 answers

Converting HTML to PDF using iText

I am posting this question because many developers ask more or less the same question in different forms. I will answer this question myself (I am the Founder/CTO of iText Group), so that it can be a "Wiki-answer." If the Stack Overflow…
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
24
votes
2 answers

free alternative to iTextSharp

I have a project not open source and I need to use something like iTextSharp , because iTextSharp licence say it should only be used in open sources any alternative please
AMH
  • 6,363
  • 27
  • 84
  • 135
24
votes
5 answers

itext positioning text absolutely

In itext I have a chunk/phrase/paragraph (I dont mind which) and I want to position some where else on the page e.g. at 300 x 200. How would I do this?
Jack
  • 945
  • 4
  • 14
  • 21
24
votes
3 answers

How to calculate the string width in iText?

I am using iText to write a PDF. In some cases, I need to sign the PDF with the SetVisibleSignature function. With this function, we need to designate the rectangle that we will write the content into. But it's hard for me to calculate how wide the…
MemoryLeak
  • 7,322
  • 23
  • 90
  • 133
24
votes
7 answers

iTextSharp table width 100% of page

I'm trying to add a table to a document using iTextSharp. Here is an example: Document document = new Document(PageSize.LETTER,72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C:\\test.pdf",…
Kyle
  • 17,317
  • 32
  • 140
  • 246
23
votes
6 answers

Extract images using iTextSharp

I have been using this code with great success to pull out the first image found in each page of a PDF. However, it is now not working with some new PDFs for an uknown reason. I have used other tools (Datalogics, etc) that do pull out the images…
Dave
  • 1,721
  • 2
  • 23
  • 46
23
votes
5 answers

iTextSharp in version 4.1.6 (with previous licence conditions)

I have an old project that is using iTextSharp library for PDF generation. iTextSharp DLL is added as reference to the project. iTextSharp was originally available under the LGPL licence. Some time ago the licence has changed to be AGPL (in release…
Rasto
  • 17,204
  • 47
  • 154
  • 245
23
votes
2 answers

iTextSharp-generated PDFs now cause Save dialog in Adobe Reader X

I have been using iTextSharp to generate PDF documents for over a year. Unfortunately, with the release of Adobe Reader X, my PDFs now cause a "Do you want to Save?" dialog to appear when closing the PDF document. This does not happen with PDFs…
Jason
  • 233
  • 2
  • 4
23
votes
2 answers

How to position and wrap long text?

The PDF I can produce at the moment: (source: yart.com.au) I want the text to fill up the space in the lower left. How can I do that? Thanks! This is my code: private static void CreatePdf4(string pdfFilename, string heading, string text, string[]…
Aximili
  • 28,626
  • 56
  • 157
  • 216