How to improve this code in aspx ? RRS feed

  • Question

  • User-775831949 posted

    How to use belowto output the whole another aspx (say another.aspx) page as pdf ?
    What is the code? How to modify the code below ? replace "pdftable" below with something ?

    I think I need htmlworker or something but I dunno how...

    Pls help, Thanks

    Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
    using (MemoryStream memoryStream = new MemoryStream()) {
    	PdfWriter.GetInstance(pdfDocument, memoryStream);
    Wednesday, November 26, 2014 3:35 AM


All replies

  • User-775831949 posted


    I tried this code before already. It does not work.

    In line


    I get this error

    System.NullReferenceException: Object reference not set to an instance of an object.

    Would be glad if somebody focus in improving the code above instead of links if possible.


    Wednesday, November 26, 2014 5:09 AM
  • User1577371250 posted

    did you download the dlls and referenced in your project.

    iTextSharp dlls ??

    If not download here


    Wednesday, November 26, 2014 5:13 AM
  • User-775831949 posted

    I already have it and the #1 code is working for me. Now I only need to improve the code in #1. If switch to the code in the link, I get that error....

    From what I know, the code in that link work for the old version of dll.

    It does not work in the recent versions of dll.

    Pls help.... thanks

    Wednesday, November 26, 2014 5:38 AM
  • User-775831949 posted

    OK I found that I need to download XMLworker dll to work.

    I already added reference.

    However, the code still do not work. Anyone can help ?


    Tuesday, December 2, 2014 9:27 PM
  • User753101303 posted


    Try perhaps http://www.c-sharpcorner.com/UploadFile/9f0ae2/convert-aspx-page-into-pdf-in-Asp-Net/

    More likely the issue is rather to get the HTML markup you want to render and in the same context than the one you want...

    For now the error you have seems that you are using sr without it being initialized at all...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 3, 2014 12:31 PM
  • User-775831949 posted

    Thank. I used the code in this link and there is no error in running the aspx page and a pdf file is output and saved.

    However, the generated pdf has error, error occur once the pdf is opened in acrobat reader. It says the file is demaged.

    Do you know what happened ?


    Thursday, December 4, 2014 7:10 AM