HTML to PDF along with user input RRS feed

  • Question

  • User-274148833 posted

    Hey guys,


    I am really tired running into problems on generating the PDF file form the HTML page.

    Can any1 help me generate a PDF file from the HTML page along with the user input. My Aspx page does not have tables and cells,

    It has combo box, text box and dropdowns just like a form used to enter details. I have a code right now working but it jus generates the PDF based on the URL. and my URL does not change for the values selected for each and every dropdowns, so it just simply generates the initial form without the inputs.

    I have tried using all the possible HTML to PDF converts and nothing works even itextSharp, nw i am using WnVhtmltopdf and running into the above mentioned issue.

    Can anyone look into my code and give me a solution on getting the PDF after the user input or suggest me with someother converter and working solution please..


    PdfConverter pdfConverter = new PdfConverter();

             pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;

             pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;

             pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;


             pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;


            pdfConverter.PdfDocumentOptions.ShowFooter = false;
            pdfConverter.PdfDocumentOptions.ShowHeader = false;

            pdfConverter.LicenseKey = "Q2hzY3Jjc2N3bXNjcHJtcnFtenp6eg==";

            string a = Request.Url.ToString();

           byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(a);       

            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;


            response.AddHeader("Content-Type", "binary/octet-stream");

            response.AddHeader("Content-Disposition","attachment; filename=" + "Rendered.pdf" + "; size=" + downloadBytes.Length.ToString());







    Thanks in advance


    Friday, February 25, 2011 2:47 PM

All replies

  • User1052258516 posted

    You will need to override the Render method and capture the markup of the page then you need to use a PDF component that can create a PDF from HTML.  I know that ABCPDF.NET can do this.  Some sample code below to get the page markup, you will need to implement a button to generate a postback and process the variable pageHtml contents.

    string pageHtml = "";

    protected override void Render(HtmlTextWriter writer) { // capture the current source with a temp writer using (TextWriter tw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(tw)) { base.Render(htw); // render the page pageHtml = tw.ToString(); // store the html markup writer.Write(pageHtml); // write the markup back to the page } } }

    Saturday, February 26, 2011 1:34 AM