Page 296 - Open Soource Technologies 304.indd
P. 296
Web Technologies-I
Notes Here is some typical begin/end page code:
<? php pdf_begin_page($pdf, 612, 792); // US-Letter // code to create actual page content
would go here
pdf_end_page($pdf); ?>
12.2.4 Outputting Basic Text
To put text on a page, you must select the font you want to use, set the default font to be that
font at a particular size, and then add the text. For example:
$font = pdf_findfont($pdf, “Times-Roman”, “host”, 0);
pdf_setfont($pdf, $font, 48);
pdf_show_xy($pdf, “Hello, World”, 200, 200);
With PDF documents, the (0, 0) coordinate indicates the bottom-left corner of the page.
12.2.5 Terminating and Streaming a PDF Document
Call pdf_close( ) to complete the PDF document. If no filename was provided in the pdf_open_
file( ) call, you can now use the pdf_get_buffer( ) function to fetch the PDF buffer from memory.
To send the file to the browser, you must send Content-Type, Content-Disposition, and Content-
Length HTTP headers. Finally, call pdf_delete( ) to free the PDF file once it’s sent to the browser.
Give the process of converting word file to pdf file.
12.3 Text
Text is the heart of a PDF file. As such, there are many options for changing the appearance
and layout of text. The coordinate system used in PDF documents, functions for inserting text
and changing text attributes, and font usage.
12.3.1 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.
Demonstrating coordinates
<?php
$pdf = pdf_new( );
pdf_open_file($pdf);
pdf_set_info($pdf,”Creator”,”coords.php”);
pdf_set_info($pdf,”Author”,”ABC”);
pdf_set_info($pdf,”Title”,”Coordinate Test (PHP)”);
pdf_begin_page($pdf,612,792);
$font = pdf_findfont($pdf,”Helvetica-Bold”,”host”,0);
290 LOVELY PROFESSIONAL UNIVERSITY