How to Create a PDF with PHP on a Web Server
Knowledge Base :: PDF Creator Pilot 3 Knowledge Base

See Also Example
Collapse All

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

Create a new COM object.

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

Set license data and adjust other properties:

$PDF->StartEngine("demo", "demo");
$PDF->GenerateInMemoryFile = true;

Fill your document with some data:

$PDF->BeginDoc();
$PDF->PDFPAGE_SetActiveFont("Verdana", true, false, false, false, 14, 0);
$PDF->PDFPAGE_TextOut(10, 20, 0, "Hello from PHP!");
$PDF->EndDoc();

Then send it directly to an output stream.

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

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

Example

Using PDF Creator Pilot in a PHP Page

PHP
[copy to clipboard]
<?
  $PDF = new COM("PDFCreatorPilot.PDFDocument3") or die("Unable to load instance.");
  $PDF->StartEngine("demo", "demo");
  $PDF->GenerateInMemoryFile = true;

  $PDF->BeginDoc();
  $PDF->PDFPAGE_SetActiveFont("Verdana", true, false, false, false, 14, 0);
  $PDF->PDFPAGE_TextOut(10, 20, 0, "Hello from PHP!");
  $PDF->EndDoc();

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

  // $PDF->BinaryImage 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