How to Create a PDF on the Fly Using PHP
- 1). Create a new PDF file. Two lines of code are required when creating the file. The first opens a PDF object, and the second line of code specifies the file name. The following code creates the PDF file:
$pdfObject = PDF_new();
PDF_open_file("pdffile.pdf", ""); - 2). Set the PDF font. You can use any installed font on the server. The set font is used in the page for your text. the following code sets your font:
$font= PDF_findfont($pdfObject, "Arial", "host", 0);
PDF_setfont($pdfObject, $font, 10); - 3). Write some text to the file. You can now write to the file. The following code writes a simple, one-line paragraph to the file:
PDF_show_xy($pdf, "PDF file created by PHP", 50, 750); - 4). Close the file once you are finished writing to it. The following code closes the file and releases the server's resources:
PDF_close($pdf);
Source...