Checking off pdf checkbox with itextsharp

You shouldn’t “guess” for the possible values. You need to use a value that is stored in the PDF. Try the CheckBoxValues example to find these possible values: public String getCheckboxValue(String src, String name) throws IOException { PdfReader reader = new PdfReader(SRC); AcroFields fields = reader.getAcroFields(); // CP_1 is the name of a check box … 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

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

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