Skip to content

hamrak/laravel-pdf-to-html

 
 

Repository files navigation

Laravel - PDF to HTML

Latest Version on Packagist Total Downloads

Convert PDF to HTML by using pdftohtml on Your Laravel Apps. Special thanks to pdf-to-text (Spatie) package for inspiring this package.

Contents

Requirements

Behind the scene this package leverages pdftohtml. You can verify if the binary installed on your system by executing this command.

which pdftohtml

If it doesn't return the installed path of the binary, you can install the binary using the following command.

  • Ubuntu and Debian family
apt-get install poppler-utils
  • CentOS, Fedora, and RedHat family
yum install poppler-utils
  • Mac using brew
brew install poppler

Installation

You can install the package via composer:

composer require ibnuhalimm/laravel-pdf-to-html

Setting Up

Optionally, you can set the config in your .env file:

PDF_TO_HTML_PATH="/usr/bin/pdftohtml"
PDF_TO_HTML_OUTPUT_DIR="/var/www/html/app/public"
PDF_TO_HTML_INLINE_IMAGES=true

Usage

Set the file and get result

use Ibnuhalimm\LaravelPdfToHtml\Facades\PdfToHtml;

$sourceFile = '/path/to/your-file.pdf';
PdfToHtml::setFile($sourceFile)->result();

// It will return output file path
// e.g. : /var/www/html/storage/app/pdf-to-html/your-file.html

Save as the result file

use Ibnuhalimm\LaravelPdfToHtml\Facades\PdfToHtml;

$sourceFile = '/path/to/your-file.pdf';
PdfToHtml::setFile($sourceFile)
    ->saveAs('result-file')
    ->result();

// It will return output file path as
// e.g. : /var/www/html/storage/app/pdf-to-html/result-file.html

We can set config on-the-fly

use Ibnuhalimm\LaravelPdfToHtml\Facades\PdfToHtml;

$sourceFile = '/path/to/your-file.pdf';
PdfToHtml::setFile($sourceFile)
    ->setConfig([
        'bin_path' => '/usr/local/bin/pdftohtml',
        'output_dir' => public_path('/new-location'),
        'inline_images' => false
    ])
    ->result();

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

About

Convert PDF to HTML in Your Laravel Apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%