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
19
votes
4 answers

Split PDF into multiple PDFs using iTextsharp

public int SplitAndSave(string inputPath, string outputPath) { FileInfo file = new FileInfo(inputPath); string name = file.Name.Substring(0, file.Name.LastIndexOf(".")); using (PdfReader reader = new…
Billy
  • 825
  • 6
  • 21
  • 36
19
votes
6 answers

How to merge multiple pdf files (generated in run time)?

How to merge multiple pdf files (generated on run time) through ItextSharp then printing them. I found the following link but that method requires the pdf names considering that the pdf files stored and this is not my case . I have multiple reports…
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
19
votes
6 answers

iTextSharp - Convert word doc/docx to pdf

I understand iTextSharp can be used for converting a document to pdf. But first we have to create a document from scratch using iTextSharp.text.Document and then adding elements to this document. What if I have an existing doc file, is it possible…
inutan
  • 10,558
  • 27
  • 84
  • 126
19
votes
5 answers

Using iText (iTextSharp) to populate XFA form fields in PDF?

I need to populate XFA form fields in a PDF (created with Adobe LiveCycle Designer). We're attempting to use iText (actually iTextSharp with C#) to parse the PDF, populate the XFA fields and then save the modified PDF back out. All the examples I…
Jay Stevens
  • 5,863
  • 9
  • 44
  • 67
18
votes
1 answer

Is it possible to get structural elements from a PDF file using iTextSharp?

We are using iTextSharp with a C# WinForms application to parse a PDF file. Using iTextSharp, I can easily extract the text data from the PDF file. Suppose a PDF file contains an image surrounded by two lines of text. In this case, I could not…
Saravanan
  • 11,372
  • 43
  • 143
  • 213
18
votes
3 answers

using ITextSharp to extract and update links in an existing PDF

I need to post several (read: a lot) PDF files to the web but many of them have hard coded file:// links and links to non-public locations. I need to read through these PDFs and update the links to the proper locations. I've started writing an app…
Andy Evans
  • 6,997
  • 18
  • 72
  • 118
18
votes
3 answers

Both landscape and portrait for pdf with Flying Saucer/iText

Is there a way to set different page styles with Flying Saucer/iText? I need to have the first couple of pages in landscape, then switch to portrait at a certain page and out. Any ideas?
peirix
  • 36,512
  • 23
  • 96
  • 126
18
votes
2 answers

How to write UTF-8 characters to a pdf file using itextsharp?

I have tried a lot on google but not able to find.. Any help is appreciated. Please find the code below:- protected void Page_Load(object sender, EventArgs e) { StreamReader read = new StreamReader(@"D:\queryUnicode.txt",…
teenup
  • 7,459
  • 13
  • 63
  • 122
18
votes
4 answers

iText: PdfTable cell vertical alignment

I'm trying to vertical align my headet cell text to be in the middle of the cell height. This is my code: PdfPCell c1 = new PdfPCell(cerate_phrase("" ,regular_bold )); c1.setHorizontalAlignment(Element.ALIGN_CENTER); …
user590586
  • 2,960
  • 16
  • 63
  • 96
18
votes
4 answers

iTextSharp how to rotate/switch page from landscape to portrait

I'm using iTextSharp to merge multiple PDF files into a single Pdf. I found a code sample or two on the web as to how to accomplish this task. They all work, with no apparent issues, as I'm able to merge multiple PDF files into a single PDF. The…
Riaan
  • 1,541
  • 2
  • 20
  • 31
18
votes
3 answers

Itextsharp text extraction

I'm using itextsharp on vb.net to get the text content from a pdf file. The solution works fine for some files but not for other even quite simple ones. The problem is that the token stringvalue is set to null (a set of empty square boxes) token =…
Pakhu
  • 191
  • 1
  • 1
  • 5
18
votes
7 answers

Is it possible to merge several pdfs using iText7

I have several datasheets for products. Each is a separate file. What I want to do is to use iText to generate a summary / recommended set of actions, based on answers to a webform, and then append to that all the relevant datasheets. This way, I…
Matt
  • 1,596
  • 2
  • 18
  • 32
18
votes
1 answer

iTextSharp: Any support for dotnet core (netstandard1.6)?

I've been using iTextSharp with regular dotnet applications for a while now. We're interested in using it with dotnet core. But it seems that the library is still not supported on the new dotnet core platform: Package iTextSharp 5.5.10 is not…
Pieter
  • 4,721
  • 6
  • 19
  • 18
18
votes
6 answers

iTextSharp creation of a pdf from a list of byte arrays

I've got a list of byte[] which i'd like to concatenate into one byte[] which will be the final PDf. On the "page = copy.GetImportedPage(new PdfReader(p), i); " i'm getting an "object reference not set to an instance error. I've got no clue of…
valin077
  • 885
  • 1
  • 8
  • 17
18
votes
1 answer

How to convert pdf Byte[] Array to downloadable file using iTextSharp

Hei guys I have this byte array i want to convert to pdf and make it available for download. Anybody has any idea how this is done? here is my Action Controller public ActionResult DownloadLabTestResult(string labTestResultID) { …
Ari
  • 271
  • 3
  • 5
  • 15