$imagefile = “mybackground.tif”;
$outfilename = “”; //empty if you want to work in memory, else use filename
$p = PDF_new();
PDF_set_parameter($p, “license”, “your licensenr”);//call before anything else
PDF_set_parameter($p, “errorpolicy”, “return”);
PDF_set_parameter($p, “textformat”, “utf8″); // use utf8
//mysql_real_escape_string breaks variables with utf8 data
if (PDF_begin_document($p, $outfilename, “”) == 0) {
die(”Error: ” . PDF_get_errmsg($p));// if you can’t create the document return the error
}
PDF_set_info($p, “Creator”, “My name”);// place your name inside the pdf info
PDF_set_info($p, “Title”, “My title”); // give the pdf a title
PDF_begin_page_ext($p, 595, 842, “topdown”); // begin a page, these are settings for A4 size. coordinates start top left
$font = PDF_load_font($p, “Helvetica”, “unicode”, “”); // set the font
if ($font == 0) {
die(”Error: ” . PDF_get_errmsg($p)); // return errormessage if fontsettings are wrong
}
PDF_setfont($p, $font, 10);
/* place image in the background*/
$image = PDF_load_image($p, “auto”, $imagefile, “”);
if ($image == 0) {die(”Error: ” . PDF_get_errmsg($p));} // if failed, return the errormessage
PDF_fit_image($p,$image, 1, 842, “”); // place the image
PDF_close_image($p, $image);
/* textflow example*/
$mytext = “this is<nextline>some text<nextline>on multiple lines”;
$mytextflow = PDF_create_textflow($p,$mytext, “fontname=arial fontsize=8 encoding=unicode leading=12″);
PDF_fit_textflow($p, $mytextflow, 289, 122, 400, 400, “”);
/* working with fit_textline */
$optlist1= “boxsize={355 14} position={top left}”; // box is 355 width and 14 height, draw text top left
PDF_fit_textline($p,”test for fit_textline”, 36, 120, $optlist1);
/*draw rectangle*/
PDF_rect($p, 36, 755, 520, 107);
PDF_stroke($p);
PDF_end_page_ext($p, “”); // end of page
PDF_end_document($p, “”); // end of document
// $document = pdf_get_buffer($p); use this to capture the pdf from memory ->$outputfile should be empty
PDF_delete($p);