note 56866 added to ref.pdf
| From: | php-general at lists dot php dot net | Date: | Sat, 17 Sep 2005 18:26:47 +0000 |
| Subject: | note 56866 added to ref.pdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95334@lists.php.net to get a copy of this message | ||
some code that can be very helpful for starters.
<?php
// Declare PDF File
$pdf = pdf_new();
PDF_open_file($pdf);
// Set Document Properties
PDF_set_info($pdf, "author", "Alexander Pas");
PDF_set_info($pdf, "title", "PDF by PHP Example");
PDF_set_info($pdf, "creator", "Alexander Pas");
PDF_set_info($pdf, "subject", "Testing Code");
// Get fonts to use
pdf_set_parameter($pdf, "FontOutline", "Arial=arial.ttf"); // get a custom
font
$font1 = PDF_findfont($pdf, "Helvetica-Bold", "winansi", 0); // declare
default font
$font2 = PDF_findfont($pdf, "Arial", "winansi", 1); // declare custom font
& embed into file
/*
You can use the following Fontypes 14 safely (the default fonts)
Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique
Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
Symbol, ZapfDingbats
*/
// make the images
$image1 = PDF_open_image_file($pdf, "gif", "image.gif"); //supported
filetypes are: jpeg, tiff, gif, png.
//Make First Page
PDF_begin_page($pdf, 450, 450); // page width and height.
$bookmark = PDF_add_bookmark($pdf, "Front"); // add a top level bookmark.
PDF_setfont($pdf, $font1, 12); // use this font from now on.
PDF_show_xy($pdf, "First Page!", 5, 225); // show this text measured from the left
top.
pdf_place_image($pdf, $image1, 255, 5, 1); // last number will schale it.
PDF_end_page($pdf); // End of Page.
//Make Second Page
PDF_begin_page($pdf, 450, 225); // page width and height.
$bookmark1 = PDF_add_bookmark($pdf, "Chapter1", $bookmark); // add a nested bookmark.
(can be nested multiple times.)
PDF_setfont($pdf, $font2, 12); // use this font from now on.
PDF_show_xy($pdf, "Chapter1!", 225, 5);
PDF_add_bookmark($pdf, "Chapter1.1", $bookmark1); // add a nested bookmark (already in
a nested one).
PDF_setfont($pdf, $font1, 12);
PDF_show_xy($pdf, "Chapter1.1", 225, 5);
PDF_end_page($pdf);
// Finish the PDF File
PDF_close($pdf); // End Of PDF-File.
$output = PDF_get_buffer($pdf); // assemble the file in a variable.
// Output Area
header("Content-type: application/pdf"); //set filetype to pdf.
header("Content-Length: ".strlen($output)); //content length
header("Content-Disposition: attachment; filename=test.pdf"); // you can use inline or
attachment.
echo $output; // actual print area!
// Cleanup
PDF_delete($pdf);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.pdf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56866
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56866&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56866&report=yes
Search -- http://master.php.net/manage/user-notes.php