Knowledge Base Nr: 00042 pdf_php_sample.php3 - http://www.swe-kaiser.de

Downloads:

PHP: PDF-Dokumente on-the-fly im Web generieren mit PHP (PDFLib und CLibPDF)

  
PDFlib:
=======

<?
$pdf = pdf_new();

if (!pdf_open_file($pdf, "")) {
print error;
exit;
};

pdf_set_parameter($pdf, "warning", "true");

pdf_set_parameter($pdf, "serial", "X43400-4321CD-2678EF-AD4988");

pdf_set_info($pdf, "Creator", "pdf_clock.php");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Analog Clock");

PDF_set_parameter($pdf, "resourcefile", "c:\php\fonts\pdflib.upr");
PDF_set_parameter($pdf, "prefix", "c:\php\fonts");

pdf_begin_page($pdf, 300, 200);

$font = pdf_findfont($pdf, "Times-Roman", "host");
pdf_setfont($pdf, $font, 15);

pdf_show_xy($pdf, "Das ist Times-Roman", 40, 230);
pdf_show_xy($pdf, "mit PDFlib", 40, 210);

pdf_end_page($pdf);

pdf_close($pdf);

$buf = pdf_get_buffer($pdf);
$len = strlen($buf);

#reihenfolge ist wichtig!
header("Pragma: no-cache");
header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");

echo ($buf);

pdf_delete($pdf);
?>

CLibPDF:
========

<?php
$pdf = cpdf_open(0);
cpdf_set_creator($pdf, "pdf_clock.php3");
cpdf_set_title($pdf, "Analog Clock");

cpdf_set_font_directories ($pdf, "C:\PHP\pdf-related", "C:\PHP\pdf-related");
cpdf_set_font_map_file ($pdf, "C:\PHP\pdf-related\pdflib.upr");

cpdf_page_init($pdf, 1, 0, 200, 200, 1.0);

cpdf_begin_text($pdf);
cpdf_set_font($pdf, "Times-Roman", 10, "WinAnsiEncoding");
for ($n = 0; $n < 20; $n++)
{
$p = $n*10;
cpdf_text($pdf, $p . ",". $p, $p, $p);
}
cpdf_end_text($pdf);

cpdf_finalize_page($pdf, 1);

cpdf_finalize($pdf);

#reihenfolge ist wichtig!
header("Pragma: no-cache");
header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");

cpdf_output_buffer($pdf);
cpdf_close($pdf);
?>