We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


html data to pdf

eaweb asked
Medium Priority
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
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

If you can use PHP, the FPDF class is an excellent way to make PDFs.  Check it out at FPDF.org and see what you think.  It gives control to the 1/100" level.
FPDF works well for me too :)


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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
FPDF tutorial / manual / fucntion explanations have examples (or at least nearly all) ?

http://fpdf.org/ -> manual


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
$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 FPDF.org 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 >> http://html2fpdf.sf.net) /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?


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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.