PDF Service : Url2Pdf at services.phpresgroup.org

June 10, 2006 § 4 Comments

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

————————Url2PdfReport.class.php———————

,
* 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)
{
if(is_numeric($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
&scalepoints=1&renderimages=1&renderlinks=1&renderfields=1&media=Letter
&cssmedia=screen&leftmargin=10&rightmargin=10&topmargin=15
&bottommargin=15&encoding=&headerhtml=&footerhtml=
&watermarkhtml=$waterMarkHtml&method=fpdf&pdfversion=1.3
&output=0&convert=Convert+File”;

//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 ‘

';
   	  print_r($dump);
   	  echo '

‘;
}

}//EO Class
?>
——————————————————————-

Here’s the usage.php code:

——————–usage.php———————————-

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

//gets the pdf report of the URL data
$obj->getPdfReport();
?>
————————————————————————

Also you can download it now from WeberDev:

Download Url2PdfReport Generator Class

Hope you will enjoy it.

Regards,

$Rupom

Advertisements

§ 4 Responses to 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

What’s this?

You are currently reading PDF Service : Url2Pdf at services.phpresgroup.org at Rupom Here.

meta

%d bloggers like this: