of generating a PDF file - on-the-fly - with PHP.
The samples that are presented can be run on astahost.com.
Why would we want to generate a PDF on-the-fly ?
Well, we might want to include in the PDF some data that
must be entered by our surfer, by means of a html form.
Or we might want to include in the PDF some data that comes
from a database that is updated by another process.
Or some other reason. You invent one. All reasons are legit!
(1)
The first thing to do, when we want to generate a PDF file
with PHP, is to check that the PHP libraries, that support the
creation of PDF files, are present and available to PHP.
When you install a PHP distribution on your own home test-machine,
you have to make shure that these PHP PDF libraries are available.
On the astahost.com server, they are available and active.
Here is how to check this:
- Create a new text file, let's name it phpinfo.php.
- Insert the following code:
- Upload it to your web site.
- Browse to your phpinfo.php file on your web site.
- Check the results.
The phpinfo() function generates a html page with all the information
about the PHP installation, including the information about the Apache
web server, the version and settings of the PHP compiler, and the
supplemental PHP libraries that are installed and activated.
We have to check the pdf libraries.
The results should look something like this:
PDF Support: enabled
PDFlib Gmbh Version: 5.0.3
Revision: $Revision: 1.112.2.11 $
(This is the result of astahost.com - your own home test-machine may show
a different result, depending on your PHP distribution.)
Now that we have confirmation that the PDF libraries for PHP are OK,
let's go on with our first PHP application:
(2)
A simple test.
The creation of a PDF with PHP takes place a the web server, in memory.
The first thing to do is to create a PHP PDF object,
and the last thing to do is to destroy it.
Here is that bit of code:
$mypdf = PDF_new();
PDF_delete($mypdf);
?>
In between these two instructions, we will insert the rest of the PHP code.
With this PHP PDF object, let's create a PDF file. In memory, not on the
file-system of the web-server.
The first thing to do is to open a PHP PDF file,
and the last thing to do is to close it.
Here is that bit of code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_close($mypdf);
PDF_delete($mypdf);
?>
In between these instructions, we will insert the rest of the PHP code.
Once the PHP PDF file is open, we can start writing PDF pages to it.
The first thing to do is to start a PHP PDF page,
and the last thing to do is to end it.
Here is that bit of code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
PDF_end_page($mypdf);
PDF_close($mypdf);
PDF_delete($mypdf);
?>
In between these instructions, we will insert the rest of the PHP code.
What do these two numbers (595 and 842) mean?
They are the size of the page, measured in 1/72 inch.
Our example specifies a width of 595 points = 595 x 1/72 inch = A4 paper
Our example specifies a height of 842 points = 842 x 1/72 inch = A4 paper
Your needs may vary...
Once the PHP PDF page has been started, we can start writing dots to it.
Let's write some text.
First we have to choose a text font, and a text font size, in points.
Here is that bit of code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_end_page($mypdf);
PDF_close($mypdf);
PDF_delete($mypdf);
?>
The PHP PDF function PDF_findfont() looks for the Times-Roman font,
and sets the $myfont PHP variable.
Then the PHP PDF function PDF_setfont() uses the PHP PDF object,
and the $myfont PHP variable to select a font text size of 10 points.
Our example can now start to show some text on the page.
Here is that bit of code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_end_page($mypdf);
PDF_close($mypdf);
PDF_delete($mypdf);
?>
The PHP PDF function PDF_show_xy() prints the text at the specified positions.
X=50 and Y=750 for the first text line, and
X=50 and Y=730 for the second text line.
Again, the values are in 1/72 inch.
The origin (0,0) is in the BOTTOM-lefthand corner!
So: Y=750 is ABOVE Y=730!
Now the PHP PDF file - in memory is complete.
How do we get it into the browser of our surfer?
We will use the PHP PDF function PDF_get_buffer() to obtain a copy of the PHP PDF object
in our own memory buffer, determine the length of it, create the http headers that are required
for a PDF file, and let the web server send everything to the browser of the surfer:
Here is that bit of code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen01.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen01.php.
- Upload it to your web site.
- Browse to your gen01.php file on your web site.
- Check the results.
- Your first PDF, generated by PHP, will show on your machine ! Congratulations !
So, where do we go from here?
Let's add some graphics to our PDF page.
PDF_place_image($mypdf, $myimage, 50, 650, 0.6);
The PHP PDF function PDF_open_image_file() looks for the specified image file on the web server,
and sets the $myimage PHP variable.
Then the PHP PDF function PDF_place_image() uses the PHP PDF object,
and the $myimage PHP variable to place a copy of the image onto the PDF page.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_show_xy($mypdf, "A JPEG image, on 60 % of its original size.", 50, 710);
$myimage = PDF_open_image_file($mypdf, "jpeg", "training_bground.jpg");
PDF_place_image($mypdf, $myimage, 50, 650, 0.6);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen02.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen02.php.
- Upload it to your web site.
- Browse to your gen02.php file on your web site.
- Check the results.
Of course you will have to upload the jpeg image also !!!!!
And we can add line-drawing functions too.
The PHP PDF function PDF_setcolor() takes several parameters.
The first parameter is the PHP PDF object.
The second parameter instructs that the color is used for drawing lines.
The third parameter indicates that the color definition will be in RGB (Red-Green-Blue).
The following parameters are the values for the Red, Green, and Blue components of the color.
Our example specifies 100% Red (1) - 0% Green (0) - 0% Blue (0).
Look, another PDF quirck: 1 means 100%.
The actual drawing is a three-stage process:
- Determine the first point. PDF_moveto()
- Determine the second pont. PDF_lineto()
- Draw. PDF_stroke()
PDF_lineto($mypdf, 575, 735);
PDF_stroke($mypdf);
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 12);
$myimage = PDF_open_image_file($mypdf, "jpeg", "training_bground.jpg");
PDF_place_image($mypdf, $myimage, 30, 750, 0.6);
// RGB colors: 1 = 100 % (255)
PDF_setcolor($mypdf, "stroke", "rgb", 1, 0, 0);
PDF_moveto($mypdf, 20, 735);
PDF_lineto($mypdf, 575, 735);
PDF_stroke($mypdf);
PDF_moveto($mypdf, 20, 55);
PDF_lineto($mypdf, 575, 55);
PDF_stroke($mypdf);
PDF_show_xy($mypdf, "A sample document.", 50, 40);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen03.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen03.php.
- Upload it to your web site.
- Browse to your gen03.php file on your web site.
- Check the results.
Besides lines, we can also draw rectangles and circles. And fill them with a color.
The sample PHP PDF function PDF_setcolor($mypdf, "fill", "rgb", 1, 1, 0);
prepares the fill color as yellow (Red = 100% - Green = 100% - Blue = 0%)
The sample PHP PDF function PDF_setcolor($mypdf, "stroke", "rgb", 0, 0, 0);
prepares the draw color as black (Red = 0% - Green = 0% - Blue = 0%)
The actual drawing is a two-stage process:
- Determine the area. PDF_rect() or PDF_circle()
- Draw. PDF_fill_stroke()
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Drawings in PDF.", 450, 765);
// RGB colors: 1 = 100 % (255)
PDF_setcolor($mypdf, "fill", "rgb", 1, 1, 0);
PDF_setcolor($mypdf, "stroke", "rgb", 0, 0, 0);
PDF_rect($mypdf, 50, 500, 200, 300);
PDF_fill_stroke($mypdf);
PDF_setcolor($mypdf, "fill", "rgb", 0, 1, 0);
PDF_setcolor($mypdf, "stroke", "rgb", 0, 0, 1);
PDF_circle($mypdf, 400, 600, 100);
PDF_fill_stroke($mypdf);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen04.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen04.php.
- Upload it to your web site.
- Browse to your gen04.php file on your web site.
- Check the results.
With the PHP instruction for () {} to do some repetitive things,
we can easily create a page that contains a matrix of small squares:
First the vertical lines, left to right:
{
PDF_moveto($mypdf, $x, 0);
PDF_lineto($mypdf, $x, 842);
PDF_stroke($mypdf);
}
Then the horizontal lines, bottom to top:
{
PDF_moveto($mypdf, 0, $y);
PDF_lineto($mypdf, 595, $y);
PDF_stroke($mypdf);
}
Moreover, let's make two pages, slightly different.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_parameter($mypdf, "openaction", "fitpage");
PDF_begin_page($mypdf, 595, 842);
PDF_setcolor($mypdf, "stroke", "rgb", 0.90, 0.90, 0.90);
for ($x=0; $x<=595; $x+=20)
{
PDF_moveto($mypdf, $x, 0);
PDF_lineto($mypdf, $x, 842);
PDF_stroke($mypdf);
}
for ($y=0; $y<=842; $y+=20)
{
PDF_moveto($mypdf, 0, $y);
PDF_lineto($mypdf, 595, $y);
PDF_stroke($mypdf);
}
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Drawingpaper.", 450, 765);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setcolor($mypdf, "stroke", "rgb", 0.725, 0.725, 0.725);
for ($x=0; $x<=595; $x+=50)
{
PDF_moveto($mypdf, $x, 0);
PDF_lineto($mypdf, $x, 842);
PDF_stroke($mypdf);
}
for ($y=0; $y<=842; $y+=50)
{
PDF_moveto($mypdf, 0, $y);
PDF_lineto($mypdf, 595, $y);
PDF_stroke($mypdf);
}
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen05.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen05.php.
- Upload it to your web site.
- Browse to your gen05.php file on your web site.
- Check the results.
Those of you who were very eager to learn, will have noticed one new PHP PDF function.
Read the previous code again and try to find it. (It's in the begining of the code.)
Or cheat and read the next paragraph.
The PHP PDF function PDF_set_parameter($mypdf, "openaction", "fitpage"); allows you
to have some influence over the behaviour of the Adobe Acrobat Reader,
when the PDF is shown to your surfer.
The setting of PDF parameters will be elaborated upon later in this post.
But now is the time to add some PDF properties to our PDF file:
The PHP PDF function PDF_set_info(); allows you to add meta information
to the PDF file. Meta information is information about information. The information we will
add will be visible with the full version of the Adobe Acrobat Reader, as document properties.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen06.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample with the Document Properties. Can be observed in the full Acrobat Reader.", 50, 750);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen06.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen06.php.
- Upload it to your web site.
- Browse to your gen06.php file on your web site.
- Check the results.
So, what have we learned so far?
- We create and destroy a PHP PDF object.
- We open and close a PHP PDF file - in memory.
- We start and end a PDF page.
- We select a text-font and a text-font-size.
- We draw text at a specified place on the page.
- We select a fill color and a stroke color.
- We draw lines, filled rectangles and circles.
- We have influence on the behaviour of the Adobe Acrobat Reader.
- We add meta data to the PDF file.
- We copy the PDF file into a PHP buffer and send this - via http - to the browser of the surfer.
Neat. What now?
Let's find out how many lines of text we can put on one page, shall we?
First approach: we use the PHP PDF function PDF_show_xy(); to draw the text,
and with the PHP instruction for () {} we determine the vertical position of the line.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen07.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
for ($y=820; $y>=00; $y-=15) {
PDF_show_xy($mypdf, $y, 50, $y);
PDF_show_xy($mypdf, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 70, $y);
}
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen07.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen07.php.
- Upload it to your web site.
- Browse to your gen07.php file on your web site.
- Check the results.
But why bother with calculating the vertical position ourselves?
What if we change the text font size?
Let's have the PHP PDF library do the hard work for us.
Second approach: we use the PHP PDF function PDF_continue_text(); to draw the text,
and we let the PHP PDF library calculate the exact vertical position of the line, according to
the selected text font size...
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen08.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_set_parameter($mypdf, "openaction", "fitpage");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Times-Roman; 10 points. First line on: x = 30; y = 830", 30, 830);
for ($y=0; $y<=80; $y++) {
PDF_continue_text($mypdf, "80 Lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
PDF_continue_text($mypdf, "Last line. (Line 82)");
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen08.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen08.php.
- Upload it to your web site.
- Browse to your gen08.php file on your web site.
- Check the results.
So, now we know that Times-Roman 10 point text fits 82 lines on a A4 page.
How about Times Roman 12 point?
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen09.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_set_parameter($mypdf, "openaction", "fitpage");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 12);
PDF_show_xy($mypdf, "Times-Roman; 12 points. First line on: x = 30; y = 830", 30, 830);
for ($y=0; $y<=66; $y++) {
PDF_continue_text($mypdf, "66 Lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
PDF_continue_text($mypdf, "Last line. (Line 68)");
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen09.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen09.php.
- Upload it to your web site.
- Browse to your gen09.php file on your web site.
- Check the results.
Yes, now we know that Times Roman 12 point text fits only 68 lines on a A4 page.
Let's compare three different text font sizes in one single PDF file, on three PDF pages.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen10.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_setcolor($mypdf, "stroke", "rgb", 1, 0, 0);
PDF_show_xy($mypdf, "Times-Roman; Page one", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 12);
PDF_setcolor($mypdf, "stroke", "rgb", 1, 0, 0);
PDF_show_xy($mypdf, "Times-Roman; Page two", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 14);
PDF_setcolor($mypdf, "stroke", "rgb", 1, 0, 0);
PDF_show_xy($mypdf, "Times-Roman; Page three", 50, 800);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen10.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen10.php.
- Upload it to your web site.
- Browse to your gen10.php file on your web site.
- Check the results.
Enough simple text PDF pages.
Ever wondered how they create these left-side "Bookmarks" and "Thumbnails" in PDF?
Well we can create that with PHP too !
Let's create the "Thumbnails" first.
The PHP PDF function PDF_add_thumbnail(); will create one "Thumnail" image
for the PDF page that we are creating. So, this function must be called for every PDF page.
When the Adobe Acrobat Reader presents the PDF file, your surfer will be able to click on one
of the "Thumbnail" images, and the Adobe Acrobat Reader will then jump to the appropriate PDF page.
Furthermore, we will use the PHP PDF function PDF_set_parameter($mypdf, "openmode", "thumbnails");
to instruct the Adobe Acrobat Reader to show the "Thumbnail" tab when the PDF file is opened.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen11.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_set_parameter($mypdf, "openmode", "thumbnails");
PDF_set_parameter($mypdf, "openaction", "fitpage");
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page one", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board1.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page two", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board2.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page three", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board3.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page four", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board4.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page five", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board5.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page six", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board6.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page seven", 50, 800);
$myimage = PDF_open_image_file($mypdf, "jpeg", "board7.jpg");
PDF_place_image($mypdf, $myimage, 90, 750, 0.5);
PDF_place_image($mypdf, $myimage, 90, 650, 0.5);
PDF_place_image($mypdf, $myimage, 90, 550, 0.5);
PDF_place_image($mypdf, $myimage, 90, 450, 0.5);
PDF_place_image($mypdf, $myimage, 90, 350, 0.5);
PDF_place_image($mypdf, $myimage, 90, 250, 0.5);
PDF_place_image($mypdf, $myimage, 190, 750, 0.5);
PDF_place_image($mypdf, $myimage, 190, 650, 0.5);
PDF_place_image($mypdf, $myimage, 190, 550, 0.5);
PDF_place_image($mypdf, $myimage, 190, 450, 0.5);
PDF_place_image($mypdf, $myimage, 190, 350, 0.5);
PDF_place_image($mypdf, $myimage, 190, 250, 0.5);
PDF_place_image($mypdf, $myimage, 290, 750, 0.5);
PDF_place_image($mypdf, $myimage, 290, 650, 0.5);
PDF_place_image($mypdf, $myimage, 290, 550, 0.5);
PDF_place_image($mypdf, $myimage, 290, 450, 0.5);
PDF_place_image($mypdf, $myimage, 290, 350, 0.5);
PDF_place_image($mypdf, $myimage, 290, 250, 0.5);
PDF_place_image($mypdf, $myimage, 390, 750, 0.5);
PDF_place_image($mypdf, $myimage, 390, 650, 0.5);
PDF_place_image($mypdf, $myimage, 390, 550, 0.5);
PDF_place_image($mypdf, $myimage, 390, 450, 0.5);
PDF_place_image($mypdf, $myimage, 390, 350, 0.5);
PDF_place_image($mypdf, $myimage, 390, 250, 0.5);
PDF_add_thumbnail($mypdf,$myimage);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen11.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen11.php.
- Upload it to your web site.
- Browse to your gen11.php file on your web site.
- Check the results.
Of course you will have to upload the jpeg images also !!!!!
And now is the time to create PDF bookmarks.
The PHP PDF function PDF_add_bookmark(); will create one "Bookmark"
for the PDF page that we are creating. So, this function must be called for every PDF page.
When the Adobe Acrobat Reader presents the PDF file, your surfer will be able to click on one
of the "Bookmark" lines, and the Adobe Acrobat Reader will then jump to the appropriate PDF page.
Furthermore, we will use the PHP PDF function PDF_set_parameter($mypdf, "openmode", "bookmarks");
to instruct the Adobe Acrobat Reader to show the "Bookmarks" tab when the PDF file is opened.
What is so special about the PDF bookmarks implementation, is the fact that the PDF bookmarks
are "hierarchical". This means that the PDF bookmarks view is like a tree view, with different levels.
Furthermore, some of these levels are visible, while other levels are invisible, or "collapsed".
The PHP PDF function PDF_add_bookmark(); takes the required parameters to
obtain these results.
- The first parameter is the PHP PDF object.
- The second parameter is the text of the bookmark.
- The third parameter is the level (0 for the highest level)
- The fourth parameter is 1 for children-are-visible, and 0 for children-are-invisible (collapsed).
Sample:
$mychild = PDF_add_bookmark($mypdf, "Second page", $mytopparent, 1);
$mytopparent = PDF_add_bookmark($mypdf, "Third page", 0, 1);
$mychild = PDF_add_bookmark($mypdf, "Fourth page", $mytopparent, 0);
$mygrandchild = PDF_add_bookmark($mypdf, "Fifth page", $mychild, 1);
$mygrandchild = PDF_add_bookmark($mypdf, "Sixth page", $mychild, 1);
$mytopparent = PDF_add_bookmark($mypdf, "Seventh page", 0, 1);
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen12.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
PDF_set_parameter($mypdf, "openmode", "bookmarks");
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page one", 50, 800);
$mytopparent = PDF_add_bookmark($mypdf, "First page", 0, 1);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page two", 50, 800);
$mychild = PDF_add_bookmark($mypdf, "Second page", $mytopparent, 1);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page three", 50, 800);
$mytopparent = PDF_add_bookmark($mypdf, "Third page", 0, 1);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page four", 50, 800);
$mychild = PDF_add_bookmark($mypdf, "Fourth page", $mytopparent, 0);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page five", 50, 800);
$mygrandchild = PDF_add_bookmark($mypdf, "Fifth page", $mychild, 1);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page six", 50, 800);
$mygrandchild = PDF_add_bookmark($mypdf, "Sixth page", $mychild, 1);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page seven", 50, 800);
$mytopparent = PDF_add_bookmark($mypdf, "Seventh page", 0, 1);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen12.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen12.php.
- Upload it to your web site.
- Browse to your gen12.php file on your web site.
- Check the results.
How about some Powerpoint Presentation Effects ?
The Adobe Acrobat Reader is capable of showing some nifty page-transition effects.
We will use PHP to add the instructions required for these effects into our PDF file.
The PHP PDF function PDF_set_parameter($mypdf, "transition", $effect); will be used.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen13.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Demonstration of PDF effects. Please Paginate.", 50, 800);
PDF_set_parameter($mypdf, "openaction", "fitpage");
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page one", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "split");
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page two", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page three", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "blinds");
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page four", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page five", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "box");
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page six", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page seven", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "wipe");
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page eight", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page nine", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "dissolve");
PDF_set_value($mypdf, "duration", 3);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page ten", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page eleven", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "glitter");
PDF_set_value($mypdf, "duration", 3);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page twelve", 50, 800);
PDF_end_page($mypdf);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Page thirteen", 50, 800);
for ($y=0; $y<=66; $y++) { PDF_continue_text($mypdf, "66 lines. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");}
PDF_set_parameter($mypdf, "transition", "replace");
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen13.pdf");
print $mybuf;
PDF_delete($mypdf);
?>
- Save this code as a new text file, let's name it gen13.php.
- Upload it to your web site.
- Browse to your gen13.php file on your web site.
- Check the results.
And one more particularity of the PDF file, is the possibility to add "notes".
The PHP PDF function PDF_add_note(); will be used.
When the Adobe Acrobat Reader presents the PDF file to your surfer, he/she will
have the possibility to open the note by double-clicking on the little note icon,
placed somewhere in the text of the PDF page.
Here is the complete code:
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_set_info($mypdf, "Creator", "gen14.php");
PDF_set_info($mypdf, "Author", "John");
PDF_set_info($mypdf, "Title", "Prototype (PHP)");
PDF_set_info($mypdf, "Subject", "Sample");
PDF_set_info($mypdf, "Keywords", "PHP PDF PDFlib");
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_begin_page($mypdf, 595, 842);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "When we look more closely at this way of working,", 50, 750);
PDF_add_note($mypdf, 245, 660, 550, 770, "Yes, what is going to happen here? We are not used to work that way, and now this statement stares at us ! ", "What do you mean, WORK ?", "note", 0);
PDF_show_xy($mypdf, "we can clearly see the more open side of this project.", 50, 730);
PDF_end_page($mypdf);
PDF_close($mypdf);
$mybuf = PDF_get_buffer($mypdf);
$mylen = s

