PDF Service : Url2Pdf at services.phpresgroup.org

Here’s the code of my Url2PdfReport PDF service at services.phpresgroup.org:


* Moderator, phpResource (http://groups.yahoo.com/group/phpresource/)
* URL: http://www.rupom.info
* @version : 1.0
* @date 06/05/2006
* Purpose : Generating Pdf Report from a Given URL
class Url2PdfReport
private $url;
private $pdfWidth = 850;
private $remoteApp = “http://services.phpresgroup.org/pdf/url2pdf/html2ps.php”;

* Sets URL that will be converted to PDF
* @param URL of the HTML file
* @return none
function setUrl($url)
$this->url = $url;

* Sets width of the PDF
* @param Integer pdf width
* @return none
function setPdfWidth($pdfWidth)
$this->pdfWidth = $pdfWidth;

* Gets PDF report
* @param none
* @return none
function getPdfReport()

$htmlUrl = $this->url;
$pdfFileName = basename($htmlUrl).’.pdf’;

// Outputting PDF Report
header(“Content-type: application/pdf”);

// It will be called basename($this->htmlUrl).pdf
header(“Content-Disposition: attachment; filename=”.$pdfFileName);

// The PDF source is the returned value of method generatePdfReport()
echo $this->generatePdfReport();

}//EO Method

* Generates PDF report from remote application
* @param none
* @return report data on PDF mode
function generatePdfReport()
$remoteApp = $this->remoteApp;
$waterMarkHtml = “phpresgroup.org”;//change it according to your need
$htmlUrl = urlencode($this->url);
$pdfWidth = $this->pdfWidth;

$requestString = “process_mode=single&URL=$htmlUrl&pixels=$pdfWidth

//Init the curl session
$ch = curl_init();
// set the post-to url (do not include the ?query+string here!)
curl_setopt ($ch, CURLOPT_URL, $remoteApp);
// Header control
curl_setopt ($ch, CURLOPT_HEADER, 0);
//Tell it to make a POST, not a GET
curl_setopt ($ch, CURLOPT_POST, 1);
// Put the query string here starting without “?”
curl_setopt ($ch, CURLOPT_POSTFIELDS, $requestString);
// This allows the output to be set into a variable
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// execute the curl session and return the output to a variable $response
$response = curl_exec ($ch);
// Close the curl session
curl_close ($ch);

return $response;
}//EO Method

* Debugs dump/data
* @param $dump
* @return none
function dBug($dump)
echo ‘

   	  echo '


}//EO Class

Here’s the usage.php code:


setUrl(“http://localhost/xampp/phpClasses/url2pdfreport/test.html”);//change this according to your URL

//gets the pdf report of the URL data

Also you can download it now from WeberDev:

Download Url2PdfReport Generator Class

Hope you will enjoy it.




4 thoughts on “PDF Service : Url2Pdf at services.phpresgroup.org

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.