html data to pdf

Posted on 2009-02-18
Last Modified: 2012-05-06

i am using below code to send params to a page which in his turn returns me as response html data. like <html><body>blablabla</body></html>

here the code:

dim submittedaccountUserBankId, submittedaccountNumber

submittedaccountUserBankId = Request.Form("accountUBI")
submittedaccountNumber = Request.Form("accountNumber")
submittedaccountMonthDay = Request.Form("accountPMonthDay")

dim Getprint
Getprint = "accountUserBankId="&submittedaccountUserBankId&"&accountNumber="&submittedAccountNumber&"&accountPMonthDay="&submittedaccountMonthDay
dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",getValAndPriPdfUrl,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send Getprint
Response.ContentType = "text/html"
Response.Write xmlhttp.responsetext
Set xmlhttp = nothing

now this response i need to pdf it in A4 format etc.... on the fly.

how can i get the asp response and create a pdf file.
is there any php or preferable asp code to do this or what free codes are available to do this fast and easy in asp. it also need to process pdf of 300+ pages fast and easy
Question by:eaweb
    LVL 107

    Expert Comment

    by:Ray Paseur
    If you can use PHP, the FPDF class is an excellent way to make PDFs.  Check it out at and see what you think.  It gives control to the 1/100" level.
    LVL 5

    Expert Comment

    FPDF works well for me too :)

    Author Comment

    do you guys have an example of coverting html data to pdf? the tutorials doesn't explain very much.
    LVL 16

    Accepted Solution

    LVL 5

    Expert Comment

    FPDF tutorial / manual / fucntion explanations have examples (or at least nearly all) ? -> manual

    Author Comment

    hi i am trying to do it like this but i get an error:

    first i get the hatml data

    dim xmlhttp
    set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "POST",getValAndPriPdfUrl,false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send Getprint
    'Response.ContentType = "text/html"
    'Response.Write xmlhttp.responsetext
    posthtml = xmlhttp.responsetext
    Set xmlhttp = nothing

    then i post the html to the processing php which has to return me the pdf

    dim Getpdf
    Getpdf = "htmldata="&posthtml

    dim xmlhttppdf
    set xmlhttppdf = server.Createobject("MSXML2.ServerXMLHTTP")
    xmlhttppdf.Open "POST",getPdfUrl,false
    xmlhttppdf.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttppdf.send Getpdf
    'Response.ContentType = "text/html"
    Response.Write xmlhttppdf.responsetext
    Set xmlhttppdf = nothing

    the php code of "getPdfUrl" is like this

    //Get file contents
    //$htmlFile = "debugcases/test1.html";
    //$file = fopen($htmlFile,"r");
    //$size_of_file = filesize($htmlFile);
    $htmlToPdf  = $_POST['htmldata'];
    $buffer = $htmlToPdf  ;//fread($file, $size_of_file);
    //Initialize class
    //define RELATIVE_PATH,FPDF_FONTPATH if needed
    $pdf=new HTML2FPDF();
    //Code below used only if you want relative links to be understood
    //$pdf->setBasePath(dirname(__FILE__)."\".$htmlFile);//insert full path where
    //html is
    $pdf->Output(); //Read the manual to know the other options

    then as error i get the following

    Notice: Undefined variable: e in E:\HOA\STREQ\html2fpdf.php on line 1058

    Notice: Undefined index: s in E:\HOA\STREQ\html2fpdf.php on line 392
    %PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x???? ??|?7??6?TpR???((X ~}??]\.??????T?A)????}+???h ?im???- ??"?1Y??F%?g??C?a?!??`?_????u????a?????,?u ;b??)?b???Me??(G_Q?Jp?h?s}?"?U??? endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj <> >> endobj 8 0 obj << /Producer (FPDF 1.52) /Title (rate) /Creator (HTML2FPDF >> /CreationDate (D:20090218170504) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000000358 00000 n 0000000746 00000 n 0000000009 00000 n 0000000087 00000 n 0000000445 00000 n 0000000541 00000 n 0000000642 00000 n 0000000854 00000 n 0000001007 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1110

    what is wrong here?

    Author Comment

    i used the product of

        Dim subId, subber, subDay

        subId = Request.Form("aI")
        subber = Request.Form("ar")
        subDay = Request.Form("ay")

        If subber = "" Or subId = "" Or subDay = "" Then

            <table align="center">
                    <td align="center">                       
                          <font><strong> Error Number: Perr -- No PDF.</strong></font>
            Dim strURL As String = ""
            Dim strPostData As String = ""
            Dim strResult As String = ""
            Dim wbrq As HttpWebRequest
            Dim wbrs As HttpWebResponse
            Dim sw As StreamWriter
            Dim sr As StreamReader
            strURL = "http://3/IZ/RQ/gf.asp"
            strPostData = String.Format("acId={0}&acber={1}&acDay={2}", subId, subber, subDay)
            wbrq = WebRequest.Create(strURL)
            wbrq.Method = "POST"
            wbrq.ContentLength = strPostData.Length
            wbrq.ContentType = "application/x-www-form-urlencoded"
            sw = New StreamWriter(wbrq.GetRequestStream)

            wbrs = wbrq.GetResponse
            sr = New StreamReader(wbrs.GetResponseStream)
            strResult = sr.ReadToEnd.Trim
            textBoxWebPageURL.Text = strResult  
            prf() is the funtion i build using the winnovative dll

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Choose the older file FSO 6 20
    php session folder question (Code Igniter) 3 23
    PHP foreach DB query 4 21
    Issues with signature 19 19
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now