PHP Classes

How to Use a PHP PDF to HTML Converter Class to Be Able to Display PDF Documents on HTML Web Pages Using the Package Laravel PDF2HTML: Convert PDF documents to HTML using poppler

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-01-15 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
laravelpdf2html 1.0MIT/X Consortium ...7HTML, Unix, PHP 7, Documents
Description 

Authors

Alberto Rial Barreiro
Jacobo Cantorna Cigarrán


Contributor

This package can convert PDF documents to HTML using poppler.

It provides classes that can parse a PDF document using the pdf2html tool of the poppler package and generates an HTML document from the PDF document content.

Currently, it can:

- Get the HTML as a string from the whole PDF document

- Get an array of HTML strings for all pages of the whole PDF document

- Get the HTML string from a specific page of the PDF document

Picture of Jacobo Cantorna Cigarrán
  Performance   Level  
Name: Jacobo Cantorna Cigarrán <contact>
Classes: 6 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 2x

Instructions

Please read this document to learn how to convert a PDF document to HTML using a PHP class.

Documentation

Laravel PDF to HTML Converter

A robust and dependency-free Laravel package to convert PDF files to HTML using poppler-utils (pdftohtml).

Features

  • Dependency Free: Does not rely on external PHP packages.
  • Laravel Integration: Automatic discovery, config publishing, and easy-to-use API.
  • Binary Auto-Discovery: Automatically finds `pdftohtml` and `pdfinfo` binaries on your system.
  • Customizable: Extensive options for zooming, image handling, and output formatting.
  • Inline Assets: Automatically inlines CSS and Images (Base64) for a self-contained HTML output.
  • Strict Types: Written with modern PHP standards and strict typing.

Requirements

  • PHP > 8.1
  • `poppler-utils` installed on your server (contains `pdftohtml` and `pdfinfo`).

Installation

  1. Install via Composer:

    composer require squareetlabs/laravel-pdf-to-html
    
  2. Install poppler-utils:

    - Ubuntu/Debian:
      sudo apt-get install poppler-utils
    
    - MacOS:
    
    brew install poppler
    - CentOS/RHEL:
    
    sudo yum install poppler-utils
  3. Publish Configuration (Optional):

    php artisan vendor:publish --provider="Squareetlabs\LaravelPdfToHtml\Providers\PdfToHtmlServiceProvider"
    

Usage

Basic Usage

use Squareetlabs\LaravelPdfToHtml\Pdf;

try {
    // Create a new instance
    $pdf = new Pdf('/path/to/document.pdf');
    
    // Get HTML content
    $html = $pdf->getHtml();
    
    // Get all pages content as an array
    $pages = $html->getAllPages();
    
    // Get specific page
    $page1 = $html->getPage(1);
    
    echo $page1;
    
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

Advanced Options

You can pass options to the constructor to customize the behavior:

$options = [
    'pdftohtml_path' => '/usr/custom/bin/pdftohtml', // Optional custom path
    'pdfinfo_path' => '/usr/custom/bin/pdfinfo',     // Optional custom path
    'generate' => [
        'singlePage' => false,      // Split pages (default)
        'imageJpeg' => true,        // Convert images to JPEG
        'ignoreImages' => false,    // Keep images
        'zoom' => 1.5,              // Zoom factor
        'noFrames' => true,         // Output without frames
    ],
    'html' => [
        'inlineCss' => true,        // Inline CSS into style attributes
        'inlineImages' => true,     // Convert images to Base64
        'onlyContent' => true,      // Return only body content
    ],
    'clearAfter' => true,           // Clear temp files after processing
];

$pdf = new Pdf('/path/to/document.pdf', $options);

Get PDF Info

$info = $pdf->getInfo();
// Returns array: ['pages' => 10, 'size' => '...', ...]

$count = $pdf->countPages();

Testing

composer test

License

MIT


  Files folder image Files (17)  
File Role Description
Files folder imageconfig (1 file)
Files folder imagesrc (2 files, 4 directories)
Files folder imagetests (3 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file MIGRATION.md Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (17)  /  config  
File Role Description
  Accessible without login Plain text file pdf-to-html.php Aux. Configuration script

  Files folder image Files (17)  /  src  
File Role Description
Files folder imageExceptions (3 files)
Files folder imageProviders (1 file)
Files folder imageServices (1 file)
Files folder imageSupport (1 file)
  Plain text file Html.php Class Class source
  Plain text file Pdf.php Class Class source

  Files folder image Files (17)  /  src  /  Exceptions  
File Role Description
  Plain text file BinaryNotFoundException.php Class Class source
  Plain text file PdfNotFoundException.php Class Class source
  Plain text file PdfToHtmlException.php Class Class source

  Files folder image Files (17)  /  src  /  Providers  
File Role Description
  Plain text file PdfToHtmlServiceProvider.php Class Class source

  Files folder image Files (17)  /  src  /  Services  
File Role Description
  Plain text file CssInliner.php Class Class source

  Files folder image Files (17)  /  src  /  Support  
File Role Description
  Plain text file Base.php Class Class source

  Files folder image Files (17)  /  tests  
File Role Description
  Plain text file CssInlinerTest.php Class Class source
  Plain text file PdfTest.php Class Class source
  Plain text file TestCase.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0