Skip to Content
Programming PHP
book

Programming PHP

by Rasmus Lerdorf, Kevin Tatroe
March 2002
Intermediate to advanced
528 pages
21h 29m
English
O'Reilly Media, Inc.
Content preview from Programming PHP

Text

Text is the heart of a PDF file. As such, there are many options for changing the appearance and layout of text. In this section, we’ll discuss the coordinate system used in PDF documents, functions for inserting text and changing text attributes, and font usage.

Coordinates

The origin ((0,0)) in a PDF document is in the bottom-left corner. All of the measurements are specified in DTP points. A DTP point is equal to 1/72 of an inch, or 0.35277777778 mm.

Example 10-2 puts text in the corners and center of a page.

Example 10-2. Demonstrating coordinates

<?php
 $pdf = pdf_new(  );
 pdf_open_file($pdf);
 pdf_set_info($pdf,"Creator","coords.php");
 pdf_set_info($pdf,"Author","Rasmus Lerdorf");
 pdf_set_info($pdf,"Title","Coordinate Test (PHP)");
 pdf_begin_page($pdf,612,792);

 $font = pdf_findfont($pdf,"Helvetica-Bold","host",0);
 pdf_setfont($pdf,$font,38.0);
 pdf_show_xy($pdf, "Bottom Left", 10, 10);
 pdf_show_xy($pdf, "Bottom Right", 350, 10);
 pdf_show_xy($pdf, "Top Left", 10, 752);
 pdf_show_xy($pdf, "Top Right", 420, 752);
 pdf_show_xy($pdf, "Center",612/2-60,792/2-20);

 pdf_end_page($pdf);
 pdf_set_parameter($pdf, "openaction", "fitpage");
 pdf_close($pdf);

 $buf = pdf_get_buffer($pdf);
 $len = strlen($buf);
 header("Content-Type: application/pdf");
 header("Content-Length: $len");
 header("Content-Disposition: inline; filename=coords.pdf");
 echo $buf;
 pdf_delete($pdf);
?>

The output of Example 10-2 is shown in Figure 10-2.

Figure 10-2. Coordinate demo output

It can be inconvenient to use ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming PHP, 3rd Edition

Programming PHP, 3rd Edition

Rasmus Lerdorf, Kevin Tatroe, Peter MacIntyre
Programming PHP, 2nd Edition

Programming PHP, 2nd Edition

Rasmus Lerdorf, Kevin Tatroe, Peter MacIntyre
Clean Code in PHP

Clean Code in PHP

Carsten Windler, Alexandre Daubois

Publisher Resources

ISBN: 1565926102Supplemental ContentCatalog PageErrata