Problem generating PDF with iTextSharp

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

  1. epiraux

    epiraux Wallonman

    Hello,

    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 : http://atschool.ericpiraux.be/atschool/Test/tabid/109/Default.aspx 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.

    Eric
     

    Attached Files:

  2. Ray

    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

    Hi,

    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;

    pdfDocument.Open();

    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.");

    pdfDocument.Add(paragraph);

    pdfDocument.Add(pharse);

    pdfDocument.Add(chunk);

    pdfDocument.Close();

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

    E.
     
  4. Ray

    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.

    E.
     
  6. Ray

    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 : http://atschool.ericpiraux.be/test
    You can find the code here: http://atschool.ericpiraux.be/test/website.zip

    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 : http://atschool.ericpiraux.be/atschool/pdf.aspx

    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:
    Code:
                Response.Clear();
                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:

    • web.zip
      File size:
      6.7 KB
      Views:
      229

Share This Page