Components for Developers
© 2000-2008, Two Pilots

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

PDF Creator Pilot documentation

Download CHM version of this manual.
PDF Creator Pilot 4
How to create PDF with PHP on the web server

See Also Example
Collapse All

Once you have installed PDF Creator Pilot to you system it is available for use from PHP.

You need to create a new COM object:

$PDF = new COM("PDFCreatorPilot.PDFDocument4");

Then you need to set license data and adjust other properties:

$PDF->SetLicenseData("demo", "demo");
$PDF->Compression = 1; // coFlate

Fill your document with some data:

$fnt = $PDF->AddBuiltInFont(1, false, false);
$PDF->UseFont($fnt, 14);
$PDF->ShowTextAt(30, 30, "Hello from PHP!");

Then you may save it to disk:

$PDF->SaveToFile("hello.pdf", false);

or send it directly to user output stream:

$size = $PDF->GetBufferSize();
$buffer = $PDF->GetBuffer();
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=test.pdf");
header("Content-Length: $size");

// $PDF->GetBuffer() returns VARIANT with a type VT_ARRAY
// so we need to convert all its elements to chars.
foreach ($buffer as $byte)
  echo chr($byte);

Thats it.

Example

Using PDF Creator Pilot in PHP page

PHP
[copy to clipboard]
<?
  $PDF = new COM("PDFCreatorPilot.PDFDocument4") or die("Unable to load instanciate.");
  $PDF->SetLicenseData("demo", "demo");
  $PDF->Compression = 1; // coFlate
  
  $fnt = $PDF->AddBuiltInFont(1, false, false);
  $PDF->UseFont($fnt, 14);
  $PDF->ShowTextAt(30, 30, "Hello from PHP!");

  //// you may save document to disk:
  //$PDF->SaveToFile("hello.pdf", false);

  // or send it directly to user
  $size = $PDF->GetBufferSize();
  $buffer = $PDF->GetBuffer();
  header("Content-type: application/pdf");
  header("Content-Disposition: attachment; filename=test.pdf");
  header("Content-Length: $size");

  // $PDF->GetBuffer() returns VARIANT with a type VT_ARRAY
  // so we need to convert all its elements to chars.
  foreach ($buffer as $byte)
    echo chr($byte);

  $PDF = null;
?>

See Also

Reference

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF Add-on History In the Lab

 

 

PDF Library | Virtual Printer | Converters to PDF

Support | Blog | Forum | Contacts

© 2000-2008, Two Pilots