Create PDF via PHP

Native and high-performance PDF file creation without Adobe Acrobat installation using PHP

How to generate PDF File via PHP

In order to create a PDF file, we’ll use Aspose.PDF for PHP via Java API which is a feature-rich, powerful and easy-to-use document manipulation tool in php-java. Install Tomcat 9.0 version on any location, add Aspose.PDF.war, for more details check the GitHub page.

How to Create PDF via PHP


It is easy for the developers to create, load, modify and convert PDF files directly from PHP via Java application in just a few lines of code.

  1. Include the namespace in your class file
  2. Initialize the Document class object.
  3. Add a page using Pages.Add() method.
  4. Create a new TextFragment object and set its text.
  5. Add TextFragment to the Paragraphs collection of the page.
  6. Save the PDF using Save(String) method.

Following source code shows how to create a PDF file using PHP.

This sample code shows how to create PDF using PHP

    $document = new Document();    
    $page = $document->getPages()->add();
    $textFragment = new TextFragment("Hello World!");    
    $page->getParagraphs()->add($textFragment);
    $document->save($outputFile);