Tech Off Thread

80 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Conversation Locked

This conversation has been locked by the site admins. No new comments can be made.

ASP.NET and iTextSharp (free PDF Generator for .NET)

Back to Forum: Tech Off
  • User profile image

    Hi, I'm using a PDF stamper to fill in form fields as suggested many times above.

    I also want to add an image whcih is created at runtime. Is there any way of using the stamper object for this (ie substitute a template field?) Or do I need to save the stamped PDF, and then run it back through the PDFWriter and add my image to the docuemnt.

    I'd be grateful if anyone can suggest some code for this....


    Many thanks


  • User profile image

    @robnisbet:hi, try using a watermark. i think it can be text or image... even with transparency. you need to know the exact coordinates. see my last post.

  • User profile image

    Thanks <itsnotabug> I read up a bit on watermarks etc and using the "UnderConent". My code now looks like this for anyone interested. I read the original PDF in, scale the image, find the last page and add the image, then save the pdf again to a different filename. Brilliant!


                PdfReader reader = new PdfReader(myoriginalPDFFileName);
                PdfStamper stamper = new PdfStamper(reader, new FileStream(
                    mynewPDFFileName, FileMode.Create));
                Single x=0;
                Single y=0;
                iTextSharp.text.Rectangle rect = reader.GetPageSizeWithRotation(1);
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(myImageName);
                if (img.Width > rect.Width || img.Height > rect.Height)
                    img.ScaleToFit(rect.Width, rect.Height);
                    x = (rect.Width - img.ScaledWidth) / 2;               
                    //y = (rect.Height - img.ScaledHeight) / 2;
                    y = 0; //Set at bottom
                    x = (rect.Width - img.Width) / 2;
                    y = (rect.Height - img.Height) / 2;
                img.SetAbsolutePosition(x, y);

                int pageCount = reader.NumberOfPages;
                PdfContentByte underContent = stamper.GetUnderContent(pageCount);


                // flatten form fields and close document
                stamper.FormFlattening = true;

  • User profile image

    @robnisbet:yes, after mucking with the pdfStamper (which is admittedly good if you have a solid template + key/value pairs), i prefer just watermarking the heck out of a pdf. you have much more control over the position, layout and can use images. you can use multiple watermarks per page, transparencies, easy as pie.

  • User profile image

    I can get itextsharp to work with the MS VS Web Development Server, no problem.  However, how to you get it to work with IIS7.5?  The same code that works with the WD Server, throws a BC30002: Type 'Document' is not defined. Error in this line...

    Dim document As New Document(PageSize.A4)

    I assume there is something that needs to be configured on the IIS 7.5 server, but so far I can't find any information on the subject.

    Thanks! McF

  • User profile image


    I am trying to find an open source/free class library that can convert Url to PDF. There are lots of paid libraries like, PDFDuo and ConvertApi that easily convert any Url to PDF.

    Can we convert Url to pdf with iTextSharp? I tried local with html files (physical/relative path), it works fine but it give some exception while converting an Internet url like to pdf.

    Can anyone helps?

  • User profile image


    Can anyone help me how to repeat the section of PDF dynamically in iTexSharp?
    Actually if am able to create the pdf with AcroFields and now i want to add the section of pdf dynamically if the user increases by 4 otherwise the pdf look as it is.

  • User profile image

    Please somebody help me.

    I would like to disable "Save" button of PDF using iTextSharp. I can hide the menu bar and toolbar but "Save" is still available.

    Thanks in advance.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.