?
Solved

html data to pdf

Posted on 2009-02-18
7
Medium Priority
?
575 Views
Last Modified: 2012-05-06
hi,

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
0
Comment
Question by:eaweb
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23671763
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.
0
 
LVL 5

Expert Comment

by:WB-Internal
ID: 23671896
FPDF works well for me too :)
0
 

Author Comment

by:eaweb
ID: 23673027
do you guys have an example of coverting html data to pdf? the tutorials doesn't explain very much.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Accepted Solution

by:
golfDoctor earned 2000 total points
ID: 23673168
0
 
LVL 5

Expert Comment

by:WB-Internal
ID: 23673780
FPDF tutorial / manual / fucntion explanations have examples (or at least nearly all) ?

http://fpdf.org/ -> manual
0
 

Author Comment

by:eaweb
ID: 23675078
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

<?php
require("html2fpdf.php");
//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);
      
//fclose($file);
//Initialize class
//define RELATIVE_PATH,FPDF_FONTPATH if needed
$pdf=new HTML2FPDF();
$pdf->AddPage();
//Code below used only if you want relative links to be understood
//$pdf->setBasePath(dirname(__FILE__)."\".$htmlFile);//insert full path where
//html is
$pdf->WriteHTML($buffer);
$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?
0
 

Author Comment

by:eaweb
ID: 24043323
i used the product of
http://www.winnovative-software.com/

    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">
            <tr>
                <td align="center">                       
                      <font><strong> Error Number: Perr -- No PDF.</strong></font>
                  </td>
            </tr>
        </table>
    <%
    Else
       
        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)
        sw.Write(strPostData)
        sw.Close()

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

616 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