Problem generating PDF with iTextSharp

Discussion in 'Third-party applications' started by epiraux, Aug 3, 2010.

  1. epiraux

    epiraux Wallonman


    I've a "strange" issue with a page that generates PDF using the iTextSharp library : the pdf contains an empty page while it should contain a lot of text.

    You can see and reproduce the prob at : clicking on the "RĂ©pertoire 2009-2010" link.

    I made a lot of tests, see attached the documents.

    I've found few help while googling, except may be a suspect : iTextSharp writes in the document using the Fonts installed on the system. Is it autorized to get access to fonts folder? It it is, according to the Winhost support

    Note that it was working before the migration to Winhost platform.

    Thank you for you help.


    Attached Files:

  2. Ray


    I'm assuming that iTextSharp is suppose to capture some kind of input and transform it into a pdf file, is that correct? Where is the input suppose to go or is it suppose to connect to a database, grab data, and display it in a pdf file?
  3. epiraux

    epiraux Wallonman


    Here is the code (simplified):
    Logger.Debug("Creating the Pdf document");
    Document pdfDocument = new Document(PageSize.A4.Rotate());
    pdfDocument.AddAuthor("Eric Piraux");
    var writer = PdfWriter.GetInstance(pdfDocument, View.PdfOutputStream);
    writer.PageEvent = this;


    Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
    Phrase pharse = new Phrase("This is my second line using Pharse.");
    Chunk chunk = new Chunk(" This is my third line using Chunk.");





    where the View.PdfOutputStream is the Response Outputstream with a pdf mimetype

  4. Ray


    Can you make sure that your application is set to Full trust level?
  5. epiraux

    epiraux Wallonman

    I've set it twice to be sure : set to fulltrust - set to medium - set to fulltrust back. How can I be sure that's working? I'm using NHibernate (which needs fulltrust) and this is working -> I suppose that the fulltrust is set.

  6. Ray


    What platform where you using before. I'm really not familiar with iTextSharp and the sample code you posted is really not that helpful in diagnosing the problem. The problem is that its not throwing any error so we don't even know where to start. Can you make a simple app that builds a PDF file? It maybe alot easier to debug rather then debugging an entire application. You may also want to contact the vendor of iTextSharp and verify if their product works on a shared hosting environment. Verify if any components needs to be installed directly on the server.
  7. epiraux

    epiraux Wallonman

    I've found some interesting clues. It seems that the problem comes from the context of the application, I mean web.config, or dll's, or HttpResponse....

    Here is a working sample :
    You can find the code here:

    This excludes a server problem as it's working on the same server than the one that is not working.

    Both codes are identical, but one is still not working :

    Really, really weird.

    I've attached the web.config file, maybe is there something there?

    Here is also how I prepare the HttpResponse before sending back the pdf:
                Response.BufferOutput = true;
                Response.ContentType = "Application/pdf";
                Response.Cache.SetCacheability(HttpCacheability.Private); // set as private for HTTPS dowload issue with IE
                Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");

    Attached Files:

      File size:
      6.7 KB

Share This Page