http Interface

The http WebService of HTML2PDF may be used with the GET or POST method at this address:

http://online.htmltopdf.de/

These parameters will be consumed:

url

The URI string of the website that should be converted to PDF. This string may be up to 4096 characters long. The address has to start with http or https – other protocols are not supported currently.

license

The license key as string, if available. Otherwise simply skip this parameter.

header

If you have a license key, you can define an individual heading text here that is displayed on every page of the PDF. Without a license key a default text with a link to the WebService will be shown there. If you have no license key, you should skip this parameter.

orientation

Set this to „Portrait“ or „Landscape“ to define the page orientation.

background

Set this to „1“ or „0“ to en- or disable processing background colors and images.

print

Set this to „1“ or „0“ to en- or disable processing print media CSS.

plain

If this parameter contains the value „1“, the WebService will return the PDF data without base64 encoding in binary format. Then the browser may try to display the PDF with help of ActiveX components inline of the browser window. If you want to get the base64 encoded PDF data, simply skip this parameter.

filename

If you send the value „1“ in the parameter plain, you may define a file name for the PDF here. The browser will then normally display a file download dialog.

Return value

The WebService will return the base64 encoded data of the PDF per default. If there parameter plain was „1“, no base64 encoding will be done.

Example

An example for using the http WebService you may find here:

http://html2pdf.wan24.de/

This example also uses JavaScript to consume the http interface.

HTML example

This simple HTML code provides the http interface for URIs:

<form action="http://online.htmltopdf.de/" method="POST">
<input name="plain" type="hidden" value="1" />
<input name="filename" type="hidden" value="webseite.pdf" />
URL: <input name="url" size="80" type="text" value="http://www." /><input type="submit" value="PDF erzeugen" />
</form>

You can also simply place this HTML link on your homepage:

<a href="http://online.htmltopdf.de">PDF Download</a>

You really don’t need to do more! Click here to download this page as PDF.

PHP example

This is one way to use the http interface of HTML2PDF with PHP:

class HTML2PDF{
	public static $License=null;

	public static function CreatePDF($url,$header=null,$orientation='Landscape',$background='1',$print='0'){
		$license=$this->License;
		if(!is_null($license)&&$license!='')
			$license=sha1($url.$license);
		$param=Array(
			'url'			=>	$url,
			'license'		=>	$license,
			'header'		=>	$header,
			'orientation'	=>	$orientation,
			'background'	=>	$background,
			'print'			=>	$print,
			'plain'			=>	'1'
		);
		$temp=Array();
		foreach(array_keys($param) as $key)
			$temp[]=urlencode($key).'='.urlencode($param[$key]);
		return file_get_contents('http://online.htmltopdf.de/?'.implode('&',$temp));
	}
}

This is how this PHP class can be used in PHP code:

HTML2PDF::License='';// Enter the license key here, if available
// Create the PDF and write it to the file "demo.pdf"
file_put_contents('demo.pdf',HTML2PDF::CreatePDF('http://wan24.de'));