eaweb
asked on
html data to pdf
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</bod y></html>
here the code:
dim submittedaccountUserBankId , submittedaccountNumber
submittedaccountUserBankId = Request.Form("accountUBI")
submittedaccountNumber = Request.Form("accountNumbe r")
submittedaccountMonthDay = Request.Form("accountPMont hDay")
dim Getprint
Getprint = "accountUserBankId="&submi ttedaccoun tUserBankI d&"&accoun tNumber="& submittedA ccountNumb er&"&accou ntPMonthDa y="&submit tedaccount MonthDay
dim xmlhttp
set xmlhttp = server.Createobject("MSXML 2.ServerXM LHTTP")
xmlhttp.Open "POST",getValAndPriPdfUrl, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur lencoded"
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
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</bod
here the code:
dim submittedaccountUserBankId
submittedaccountUserBankId
submittedaccountNumber = Request.Form("accountNumbe
submittedaccountMonthDay = Request.Form("accountPMont
dim Getprint
Getprint = "accountUserBankId="&submi
dim xmlhttp
set xmlhttp = server.Createobject("MSXML
xmlhttp.Open "POST",getValAndPriPdfUrl,
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur
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
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 :)
ASKER
do you guys have an example of coverting html data to pdf? the tutorials doesn't explain very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FPDF tutorial / manual / fucntion explanations have examples (or at least nearly all) ?
http://fpdf.org/ -> manual
http://fpdf.org/ -> manual
ASKER
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("MSXML 2.ServerXM LHTTP")
xmlhttp.Open "POST",getValAndPriPdfUrl, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur lencoded"
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("MSXML 2.ServerXM LHTTP")
xmlhttppdf.Open "POST",getPdfUrl,false
xmlhttppdf.setRequestHeade r "Content-Type", "application/x-www-form-ur lencoded"
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_FONTPAT H if needed
$pdf=new HTML2FPDF();
$pdf->AddPage();
//Code below used only if you want relative links to be understood
//$pdf->setBasePath(dirnam e(__FILE__ )."\".$htm lFile);//i nsert 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?
first i get the hatml data
dim xmlhttp
set xmlhttp = server.Createobject("MSXML
xmlhttp.Open "POST",getValAndPriPdfUrl,
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-ur
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("MSXML
xmlhttppdf.Open "POST",getPdfUrl,false
xmlhttppdf.setRequestHeade
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_FONTPAT
$pdf=new HTML2FPDF();
$pdf->AddPage();
//Code below used only if you want relative links to be understood
//$pdf->setBasePath(dirnam
//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
Notice: Undefined index: s in E:\HOA\STREQ\html2fpdf.php
%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
what is wrong here?
ASKER
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}&ac ber={1}&ac Day={2}", subId, subber, subDay)
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
wbrq.ContentLength = strPostData.Length
wbrq.ContentType = "application/x-www-form-ur lencoded"
sw = New StreamWriter(wbrq.GetReque stStream)
sw.Write(strPostData)
sw.Close()
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetRespo nseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()
textBoxWebPageURL.Text = strResult
prf(strResult)
prf() is the funtion i build using the winnovative dll
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}&ac
wbrq = WebRequest.Create(strURL)
wbrq.Method = "POST"
wbrq.ContentLength = strPostData.Length
wbrq.ContentType = "application/x-www-form-ur
sw = New StreamWriter(wbrq.GetReque
sw.Write(strPostData)
sw.Close()
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetRespo
strResult = sr.ReadToEnd.Trim
sr.Close()
textBoxWebPageURL.Text = strResult
prf(strResult)
prf() is the funtion i build using the winnovative dll