Merging multiple PDFs using iTextSharp in c#.net

I found the answer: Instead of the 2nd Method, add more files to the first array of input files. public static void CombineMultiplePDFs(string[] fileNames, string outFile) { // step 1: creation of a document-object Document document = new Document(); //create newFileStream object which will be disposed at the end using (FileStream newFileStream = new FileStream(outFile, … Read more

Read PDF using itextsharp where PDF language is non-English

I inspected your file with a special focus on your sample “मतद|र” being extracted as “मतदरर” in the topmost line of the document pages. In a nutshell: Your document itself provides the information that e.g. the glyphs “मतद|र” in the head line represent the text “मतदरर”. You should ask the source of your document for … Read more

How can I insert an image with iTextSharp in an existing PDF?

If you want to change the contents of an existing PDF file and add extra content such as watermarks, pagenumbers, extra headers, PdfStamper is the object you need. I have successfully used the following code to insert an image into an existing pdf file to a given absolute position: using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; … Read more

How to return PDF to browser in MVC?

Return a FileContentResult. The last line in your controller action would be something like: return File(“Chap0101.pdf”, “application/pdf”); If you are generating this PDF dynamically, it may be better to use a MemoryStream, and create the document in memory instead of saving to file. The code would be something like: Document document = new Document(); MemoryStream … Read more

Convert arabic”unicode” content html or xml to pdf using itextsharp

You need to use container elements which support RunDirection, such as ColumnText or PdfPCell and then set their element.RunDirection = PdfWriter.RUN_DIRECTION_RTL List<IElement> list = HTMLWorker.ParseToList(new StringReader(resultCache), ST); doc.Open(); //Use a table so that we can set the text direction PdfPTable table = new PdfPTable(1); //Ensure that wrapping is on, otherwise Right to Left text will … Read more

Getting Coordinates of string using ITextExtractionStrategy and LocationTextExtractionStrategy in Itextsharp

Here is a very, very simple version of an implementation. Before implementing it is very important to know that PDFs have zero concept of “words”, “paragraphs”, “sentences”, etc. Also, text within a PDF is not necessarily laid out left to right and top to bottom and this has nothing to do with non-LTR languages. The … Read more

Page X of Y issue

Your second way is probably the simplest way. Below is a very, very slimmed down but working version: public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf.PdfPageEventHelper { public override void OnEndPage(PdfWriter writer, Document document) { ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_CENTER, new Phrase(writer.PageNumber.ToString()), 500, 140, 0); } } And to use it: //Create a file on our desktop string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), … Read more

Generate a PDF that automatically prints

Method 1: Using embedded javascript inside your PDF files You can try creating an iText PDFAction object with a javascript call this.print(false) (you can use new PdfAction(PdfAction.PRINTDIALOG) for this), and associate it with the OpenAction event of your pdf file. The code in iText Java should look like this: PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(“file.pdf”)); … Read more

ITextSharp HTML to PDF?

I came across the same question a few weeks ago and this is the result from what I found. This method does a quick dump of HTML to a PDF. The document will most likely need some format tweaking. private MemoryStream createPDF(string html) { MemoryStream msOutput = new MemoryStream(); TextReader reader = new StringReader(html); // … Read more