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

Yes there is. Check out the text.pdf.parser package, specifically LocationTextExtractionStrategy. Actually, that might not do the trick either. You’ll probably want to write your own TextExtractionStrategy to feed into PdfTextExtractor: MyTexExStrat strat = new MyTexExStrat(); PdfTextExtractor.getTextFromPage(reader, pageNum, strat); // get the strings-n-rects from strat. public class MyTexExStrat implements TextExtractionStrategy { void beginTextBlock() {} void endTextBlock() … Read more

Can itextsharp.xmlworker render embedded images?

We need to write our own ImageTagProcessor to support processing of base 64 images: public class CustomImageTagProcessor : iTextSharp.tool.xml.html.Image { public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) { IDictionary<string, string> attributes = tag.Attributes; string src; if (!attributes.TryGetValue(HTML.Attribute.SRC, out src)) return new List<IElement>(1); if (string.IsNullOrEmpty(src)) return new List<IElement>(1); if (src.StartsWith(“data:image/”, StringComparison.InvariantCultureIgnoreCase)) { // data:[<MIME-type>][;charset=<encoding>][;base64],<data> … Read more

Add Header and Footer for PDF using iTextsharp

As already answered by @Bruno you need to use pageEvents. Please check out the sample code below: private void CreatePDF() { string fileName = string.Empty; DateTime fileCreationDatetime = DateTime.Now; fileName = string.Format(“{0}.pdf”, fileCreationDatetime.ToString(@”yyyyMMdd”) + “_” + fileCreationDatetime.ToString(@”HHmmss”)); string pdfPath = Server.MapPath(@”~\PDFs\”) + fileName; using (FileStream msReport = new FileStream(pdfPath, FileMode.Create)) { //step 1 using (Document … Read more

iTextSharp – Sending in-memory pdf in an email attachment

Have you tried: PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream); // Build pdf code… writer.CloseStream = false; doc.Close(); // Build email memoryStream.Position = 0; mm.Attachments.Add(new Attachment(memoryStream, “test.pdf”)); If my memory serves me correctly, this solved a similar problem in a previous project. See http://forums.asp.net/t/1093198.aspx

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

The problem is this line: Response.OutputStream.Write(MS.GetBuffer(), 0, MS.GetBuffer().Length) The GetBuffer method returns the entire internal buffer which is larger that the actual content. The bad PDF has about 10kb of garbage content at the end (bytes of zero), the good PDF has only a few garbage bytes. Use the ToArray() method of the memory stream … Read more

Right aligning text in PdfPCell

I’m the original developer of iText, and the problem you’re experiencing is explained in my book. You’re mixing text mode and composite mode. In text mode, you create the PdfPCell with a Phrase as the parameter of the constructor, and you define the alignment at the level of the cell. However, you’re working in composite … Read more