Giter VIP home page Giter VIP logo

mpdf-examples's Introduction

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML.

It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

Latest Stable Version Total Downloads License

⚠ If you are viewing this file on mPDF GitHub repository homepage or on Packagist, please note that the default repository branch is development which can differ from the last stable release.

Requirements

PHP versions and extensions

  • PHP >=5.6 <7.3.0 is supported for mPDF >= 7.0
  • PHP 7.3 is supported since mPDF v7.1.7
  • PHP 7.4 is supported since mPDF v8.0.4
  • PHP 8.0 is supported since mPDF v8.0.10
  • PHP 8.1 is supported as of mPDF v8.0.13
  • PHP 8.2 is supported as of mPDF v8.1.3
  • PHP 8.3 is supported as of mPDF v8.2.1

PHP mbstring and gd extensions have to be loaded.

Additional extensions may be required for some advanced features such as zlib for compression of output and embedded resources such as fonts, bcmath for generating barcodes or xml for character set conversion and SVG handling.

Known server caveats

mPDF has some problems with fetching external HTTP resources with single threaded servers such as php -S. A proper server such as nginx (php-fpm) or Apache is recommended.

Support us

Consider supporting development of mPDF with a donation of any value. Donation button can be found on the main page of the documentation.

Installation

Official installation method is via composer and its packagist package mpdf/mpdf.

$ composer require mpdf/mpdf

Usage

The simplest usage (since version 7.0) of the library would be as follows:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();

This will output the PDF inline to the browser as application/pdf Content-type.

Setup & Configuration

All configuration directives can be set by the $config parameter of the constructor.

It is recommended to set one's own temporary directory via tempDir configuration variable. The directory must have write permissions (mode 775 is recommended) for users using mPDF (typically cli, webserver, fpm).

Warning: mPDF will clean up old temporary files in the temporary directory. Choose a path dedicated to mPDF only.

<?php

$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);

By default, the temporary directory will be inside vendor directory and will have write permissions from post_install composer script.

For more information about custom temporary directory see the note on Folder for temporary files in the section on Installation & Setup in the manual.

If you have problems, please read the section on troubleshooting in the manual.

About CSS support and development state

mPDF as a whole is a quite dated software. Nowadays, better alternatives are available, albeit not written in PHP.

Use mPDF if you cannot use non-PHP approach to generate PDF files or if you want to leverage some of the benefits of mPDF over browser approach – color handling, pre-print, barcodes support, headers and footers, page numbering, TOCs, etc. But beware that a HTML/CSS template tailored for mPDF might be necessary.

If you are looking for state of the art CSS support, mirroring existing HTML pages to PDF, use headless Chrome.

mPDF will still be updated to enhance some internal capabilities and to support newer versions of PHP, but better and/or newer CSS support will most likely not be implemented.

Online manual

Online manual is available at https://mpdf.github.io/.

General troubleshooting

For general questions or troubleshooting please use Discussions.

You can also use the mpdf tag at Stack Overflow as the StackOverflow user base is more likely to answer you in a timely manner.

Contributing

Before submitting issues and pull requests please read the CONTRIBUTING.md file.

Unit Testing

Unit testing for mPDF is done using PHPUnit.

To get started, run composer install from the command line while in the mPDF root directory (you'll need composer installed first).

To execute tests, run composer test from the command line while in the mPDF root directory.

Any assistance writing unit tests for mPDF is greatly appreciated. If you'd like to help, please note that any PHP file located in the /tests/ directory will be autoloaded when unit testing.

mpdf-examples's People

Contributors

dezsi-istvan avatar finwe avatar jakejackson1 avatar janslabon avatar yagamidev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpdf-examples's Issues

MathJaxProcess.php doesn't work

Besides a syntax error in the file, the method $mpdf->ConvertSize() isn't available in latest development version of Mpdf.

Use static HTML for example files

Dynamic HTML (eg. random italics every 10-ish word in example14_page_numbers_ToC_Index_Bookmarks.php) makes comparing result files after codebase change rather difficult if not impossible.

Incorrect output data from database records

I have this string in a sentence stored in the database:
"vóór"

but it will display as:
"vÃ3Ã3r"

while the same string hard coded in the html will display correctly.

Any help with this issue will be appreciated

Franco

Bug In HTML Output When page Get's long

Hey Guys,

I found a possible bug in MPDF 7 where if we populate the PDF file with enough content to fit one page, whether it's one table or 7, it works without an issue, but as soon as my 3rd table for example reaches the end of the page (by which point it should create a second page), The script no longer generates the PDF file, and I am met with an error message which reads: must precede in a table

I did notice while playing around, if I add a page break tag right before the table, it generates the PDF fine without any issues...
From what I can see, it look's like the issue pops up as soon as the data becomes longer than 1 page, and the page is not broken by me, so it would appear to be a bug in the auto page break?

Please let me know if you need any more info from me, and/or what a possible solution to the issue might be?

What's wrong ?

I have read the readme file which says to install composer and I did. Then I ran the command 'composer install' which returned no error:

$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
$ echo $?
0

Then I ran the first script:

$ php ./example01_basic.php
PHP Warning:  require_once(/Users/xxx/Documents/www/pdf2/mpdf-examples/../../../vendor/autoload.php): failed to open stream: No such file or directory in /Users/xxx/Documents/www/pdf2/mpdf-examples/example01_basic.php on line 171

Warning: require_once(/Users/xxx/Documents/www/pdf2/mpdf-examples/../../../vendor/autoload.php): failed to open stream: No such file or directory in /Users/xxx/Documents/www/pdf2/mpdf-examples/example01_basic.php on line 171
PHP Fatal error:  require_once(): Failed opening required '/Users/xxx/Documents/www/pdf2/mpdf-examples/../../../vendor/autoload.php' (include_path='.:') in /Users/xxx/Documents/www/pdf2/mpdf-examples/example01_basic.php on line 171

Fatal error: require_once(): Failed opening required '/Users/xxx/Documents/www/pdf2/mpdf-examples/../../../vendor/autoload.php' (include_path='.:') in /Users/xxx/Documents/www/pdf2/mpdf-examples/example01_basic.php on line 171
$ echo $?
255

I get the same result in the browser...

Am I missing something?

Table with rounded border

My mpdf version is 6.0

I tried example05_tables.php worked fine but when I tried adding border-radius: 7px 7px 0 0; in style that didn't work. Is there anything else I need to add to add radius in table border? or this is a bug?

Just after installing mPDF in new server, loading same SVG file fails

We was using mPDF without issues in a server but needed to move to a new Debian 8 server, but now mPDF is unable to show the same SVG and throws next message:
error: Uncaught exception 'Mpdf\MpdfException' with message 'Cannot read an undeclared property Mpdf\Writer\BackgroundWriter::$gradients' in /var/www/mpdf/vendor/mpdf/mpdf/src/Strict.php:54 Stack trace: #0 /var/www/mpdf/vendor/mpdf/mpdf/src/Writer/BackgroundWriter.php(149): Mpdf\Writer\BackgroundWriter->__isset('gradients') #1 /var/www/mpdf/vendor/mpdf/mpdf/src/Writer/ResourceWriter.php(134): Mpdf\Writer\BackgroundWriter->writePatterns() #2 /var/www/mpdf/vendor/mpdf/mpdf/src/Mpdf.php(9838): Mpdf\Writer\ResourceWriter->writeResources() #3 /var/www/mpdf/vendor/mpdf/mpdf/src/Mpdf.php(2015): Mpdf\Mpdf->_enddoc() #4 /var/www/mpdf/vendor/mpdf/mpdf/src/Mpdf.php(9329): Mpdf\Mpdf->Close() #5 /var/www/mpdf/boletin_completo.php(335): Mpdf\Mpdf->Output('/var/www/mpdf/g...', 'F') #6 {main} thrown in /var/www/mpdf/vendor/mpdf/mpdf/src/Strict.php on line 54
What could be the problem? Any ideas?

Thank you

Images returned from tiger.php doesn't work

In example04_images.php, the images returned by tiger.php don't work.

When executing from the command line php example04_images.php > out.pdf, the file will contain [X] type of images, meaning that they failed to load.

When loading the script from the browser, it will get stuck forever loading.

Styling sup tags

Hello,

I'm have a difficult time trying to style a sup tag to fix line height issue. I see in your basic example https://github.com/mpdf/mpdf-examples/blob/development/pdf/sample_basic.pdf that the sup tag did not add any extra space above the line that its on. When I use tag in my html document I see extra spacing above the line that its on (see attachments). I have tried applying css to the mpdf stylesheet but it does not take effect, not even background color or borders work for me..

output from html page

output from mpdf pdf file

I have tried using this css code in the mpdf stylesheet but none of the properties take effect.

sup, .sup { line-height: .7em; top: -10px; font-size: 0.63em; padding-bottom: 20px; margin-bottom: 10px; border-bottom: solid 1px #000000; display: inline-block; background: yellow; }

Config error in example57_new_mPDF_v5-3_active_forms

The following properties are references in the example, but because of the refractor these are no longer directly accessible.

$mpdf->formUseZapD = false;

$mpdf->formUseZapD = false;
$mpdf->formSubmitNoValueFields = true;

$mpdf->formExportType = 'xfdf'; // 'html' or 'xfdf'
$mpdf->formSelectDefaultOption = true;	// for Select drop down box; if no option is explicitly maked as selected,
							// this determines whether to select 1st option (as per browser)
							// - affects whether "required" attribute is relevant
$mpdf->form_border_color = '0.0 0.820 0.0';
$mpdf->form_background_color = '0.941 0.941 0.941';
$mpdf->form_border_width = '1';
$mpdf->form_border_style = 'S';

$mpdf->form_radio_color = '0.0 0.820 0.0';
$mpdf->form_radio_background_color = '0.941 0.5 0.5';

$mpdf->form_button_border_color = '0.0 0.820 0.0';
$mpdf->form_button_background_color = '0.941 0.941 0.941';
$mpdf->form_button_border_width = '1';
$mpdf->form_button_border_style = 'S';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.