locked
Create and return PDF from WebPart? RRS feed

  • Question

  • Dear community!

    I was wondering if it is possible to create a control (a WebPart, or what else???) such that the returning data is not the HTML page but a PDF instead. The idea was to provide a link to a page which dynamically renders and returns a PDF (using C#and iTextSharp). Does anybody have an idea how to achieve this?

    Thanks a lot!
    Thursday, December 10, 2009 8:22 AM

Answers

  • Hi,

    The page will create or read pdf in memory stream and write to the response object as shown below:

    Response.ClearHeaders();
    Response.ContentType="application/pdf";
    ms.WriteTo(pdfOutputStream);


    This will prompt the user to open the pdf file. So though you have a link to aspx file the page will return pdf data will will prompt user to open pdf file.

    The code snippet in the following link shows how you can do this:

    http://support.microsoft.com/kb/306654
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    • Marked as answer by Chrysokomas Thursday, December 10, 2009 9:49 AM
    Thursday, December 10, 2009 9:45 AM

All replies

  • Hi,

    The page will create or read pdf in memory stream and write to the response object as shown below:

    Response.ClearHeaders();
    Response.ContentType="application/pdf";
    ms.WriteTo(pdfOutputStream);


    This will prompt the user to open the pdf file. So though you have a link to aspx file the page will return pdf data will will prompt user to open pdf file.

    The code snippet in the following link shows how you can do this:

    http://support.microsoft.com/kb/306654
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    • Marked as answer by Chrysokomas Thursday, December 10, 2009 9:49 AM
    Thursday, December 10, 2009 9:45 AM
  • Wow... That's great! Thank you very much for your answer!
    Thursday, December 10, 2009 9:51 AM