How to Create PDF Files in PHP

PDF is one of the most popular electronic document formats due both to its safety and integrity of varying multimedia file types into one document. With the standardization of the PDF format in the past five years, support for creating PDF documents across operating systems and platforms has significantly increased. PDF files can now be created through web applications such as those driven by PHP.

Instructions

    • 1

      Download the freely available FPDP PHP library from the uniform resource locator (see Resources).

    • 2

      Create a file labeled "index.php" in your HTML or web editor. In the index file, include the following lines of code to let the web browser know what supporting files are needed to create the PDF document:
      $lt;?php
      require 'fpdf/fpdf.php';
      $author = "Me McMe";
      $x = 50;

    • 3

      Assign the information to be written to PDF. In this case, the information is hard-coded, but it could be substituted through dynamic assignment of the $text variable from user choice or action.
      $text =This is my test for making a PHP driven PDF File. EOT;

    • 4

      Create the PDF file and set the parameters for the font, size, and applicable format on the next two lines of code. Use the following PHP code as an example:
      $pdf = new FPDF('P', 'pt', 'Letter');
      $pdf->SetFont('Times', 'B', 24);

    • 5

      Add a page to the PDF document in order to write or assign your text and other information to the file using the Addpage method call.
      $pdf->addPage();
      $pdf->SetXY($x,50); (x and y are the coordinates)

    • 6

      Save the PDF file to disk with the Output method call using the following code:
      $pdf->Output('simple.pdf','F');

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured