PHP library generating PDF files from UTF-8 encoded HTML

Related tags

css html php pdf utf-8 cjk
Overview

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

  • mPDF >=7.0 is supported on PHP ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.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 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.

Online manual

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

For general questions or troubleshooting please use the mpdf tag at Stack Overflow (and not the project's issue tracker).

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.

Issues
  • PHP 8 support

    PHP 8 support

    At the moment, use dev-php8-support constraint in composer to use mpdf version with PHP8 support.


    Currently, mPDF works OK woth 8.0-alpha2 as-is, but testing is an issue as older Mockery version used for mocking in tests is no longer compatible (Reflection issues).

    Unless tests are fixed, support will not be official. There are a few possible approaches to address this:

    • Remove PHP 5.6 support and upgrade underlying libraries (not sure if sufficient with PHP 7.0 support)
    • Replace Mockery with another usable mocking framework (unlikely)
    • Fork Mockery and quickfix issues with Reflection (management issues)
    • Rewrite parts of mPDF (especially internal support classes dependencies on mPDF) to remove the need for mocking in tests; related #58 and #1262 (this would also solve other issues such as #1227)
    feature/enhancement 
    opened by finwe 60
  • Entire mPDF Manual Offline...

    Entire mPDF Manual Offline...

    Looks like Ian has shut down the mPDF website: http://www.mpdf1.com/mpdf/index.php

    It also appears the entire mPDF online documentation is now offline. What's the game plan? We need to have reliable online documentation. I see there's a full PDF version of the docs which will have to do for the moment, but it's not ideal.

    opened by jakejackson1 37
  • License issue: GPL v2 vs. ASL 2.0

    License issue: GPL v2 vs. ASL 2.0

    It's not really clear under which GPL version mPDF is released. On this page it seems like it is release under both. In the LICENSE.txt version 2 is declared. Somewhere in the source code only "GPL" without a version is used. So I guess it's version 2 atm.

    Anyhow, mPDF includes code which is released under the "Apache Software License 2.0" (classes from FPDI) which is incompatible to GPL v2 while it is compatible to GPL v3.

    This issue exists for several years now, but as I just updated the classes from FPDI (#16) I though it's time to move at least to GPL v3?

    question 
    opened by JanSlabon 33
  • refactor: split src/Tag.php into classes

    refactor: split src/Tag.php into classes

    As proposed in #551, this is an attempt to refactor src/Tag.php

    I took care of carefully migrating the code, tag by tag and separated my commits.

    I avoided changes to the maximum to keep this PR focused. It's basically the switch/case re-implemented in OOP by taking in accounts cases where there were no breaks, etc.

    Unit testing seems okay, but I'm wondering if there is a better way to validate that I didn't break things. Is there a reference PDF file with all what mPDF can produce somewhere, along with the script to generate it?

    opened by machour 24
  • Undesired mouseover effect on links in PDF

    Undesired mouseover effect on links in PDF

    Latest version of Chrome (Version 55.0.2883.95 (64-bit)) Mac OSX 10.10.5 MPDF 5.7.3

    With a Chrome upgrade am now seeing an ugly yellow box appear on mouseover of all links in generated PDFs. The PDFs are fine in other browsers and native viewers, but not so hot in Chrome

    I've attached a screenshot of the behaviour. It happens in new PDFs as well as ones created previously, so is Chrome related. Any thoughts on what could be causing it?

    pdfwot

    question wontfix/worksforme 
    opened by travelfish 22
  • WIP: add support for orphan and widow page breaking

    WIP: add support for orphan and widow page breaking

    To config min lines require before allowing a block orphan / widow update config.php:

    $this->minWidowLines = 3; $this->minOrphanLines = 3;

    a value of 0 here should result in current behavior without auto breaks.

    I have only so far tested with examples/example02_CSS_styles.php, and this is a bit of a hasty patch, so any help with testing, examples, and feedback (be critical, I can take it ;-) would be very much appreciated. I would be interested in the proper way to regression test and make sure I didn't break anything with these changes as well.

    feature/enhancement 
    opened by thnkloud9 21
  • Extra page in table of contents. (<tocpagebreak>)

    Extra page in table of contents. ()

    I have this problem/would like to have this functionality

    The table of contents has 2 pages by default. In a short document, this is not necessary. Is there a way to suppress this second page?

    mPDF version 6.0

    This is a HTML code snippet I use

    <body>
    <tocpagebreak></tocpagebreak>
    <page>
    <tocentry content="toc name" level="0"></tocentry>
    toc name
    </page>
    </body>
    
    opened by tomacadi 21
  • unreadable text in the table small mPDF

    unreadable text in the table small mPDF

    Error converting html to pdf tables, it turns out too small. The text is impossible to read, I have already tried the following methods to solve the problem:

    1. $ mpdf-> shrink_tables_to_fit = 0
    2. $ mpdf-> shrink_tables_to_fit = 1
    3. table autosize = "1"
    4. table autosize = "0"

    also applied styles to the table,

    1. page-break-inside: avoid

    All this did not help me solve the problem.

    A possible solution in this thread, but I did not understand how to apply it - https://github.com/mpdf/mpdf/issues/650


    header ('Content-Type: application / pdf'); require_once '/autoload.php'; $ mpdf = new \ Mpdf \ Mpdf ([ 'mode' => 'utf-8',

    'margin_left' => 5, 'margin_right' => 5, 'margin_top' => 5, 'margin_bottom' => 5,

    ]); $ mpdf-> SetTitle ('PDF'); $ stylesheet = file_get_contents ("/ stylempdf.css"); $ html = file_get_contents ("/ $ id_zapros.html");

    $ mpdf-> autoPageBreak = false;

    $ mpdf-> WriteHTML ($ stylesheet, \ Mpdf \ HTMLParserMode :: HEADER_CSS); $ mpdf-> WriteHTML ($ html, \ Mpdf \ HTMLParserMode :: DEFAULT_MODE);

    $ pdfFilePath = "123.pdf"; $ mpdf-> Output ($ pdfFilePath, "D");


    my html - https://cloud.mail.ru/public/LhSp/wjPgqRVQb my rezult Pdf - https://cloud.mail.ru/public/4Pri/tniujD5gN

    I need your help, thanks in advance

    opened by feniksbot 19
  • [PHP 7.1] Another numeric value error

    [PHP 7.1] Another numeric value error

    I have this problem/would like to have this functionality

    With our PDF files, we get this error.

    Warning: A non-numeric value encountered in /Users/xxx/PhpstormProjects/xxx/vendor/mpdf/mpdf/mpdf.php on line 25843

    Warning: A non-numeric value encountered in /Users/xxx/PhpstormProjects/xxx/vendor/mpdf/mpdf/mpdf.php on line 25848

    These are mPDF and PHP versions I am using

    7.0.0-beta2 dev-master (f3bbfc7133aed4b7bbdc22b243883bf552558211)

    This is a PHP code snippet I use

    <?php
    
    require __DIR__.'/../vendor/autoload.php';
    
    $pdfDir = '/Users/xxx/Downloads/pdfs';
    
    $pdfFilePaths = glob(sprintf('%s/*.pdf', $pdfDir));
    
    $mpdf = new  \Mpdf\Mpdf();
    $mpdf->debug = true;
    $mpdf->SetImportUse();
    
    foreach ($pdfFilePaths as $pdfFilePath) {
        $pagecount = $mpdf->SetSourceFile($pdfFilePath);
    
        for($i=0; $i < $pagecount; $i++){
            $mpdf->AddPage();
            $template = $mpdf->importPage($i+1, $pdfFilePath);
            $mpdf->useTemplate($template);
        }
    }
    
    $mpdf->Output();
    

    This is a HTML code snippet I use

    no HTML files

    We open existing PDF-files with 1 or several pages and merge them together to one pdf file.

    Solution

    I will create a pull request later with unit-tests.

    opened by sebastianblum 19
  • Feature: setasign/fpdi: 2.0 support

    Feature: setasign/fpdi: 2.0 support

    Please add support to setasign/fpdi: 2.0 version. For example I cannot use mPDF with newest version of iio/libmergepdf.

    feature/enhancement 
    opened by lpoczatek 18
  • Undefined offset: 0 in BaseWriter.php when adding columns

    Undefined offset: 0 in BaseWriter.php when adding columns

    I found this bug

    Undefined offset: 0 in BaseWriter.php when adding columns The bug is random and depends on the number of columns and also the number of elements to be rendered. For example, if $mpdf->SetColumns(3);, then the bug doesn't occur. Or if I lower the number of elements (60 instead of 100), the bug doesn't occur either. It also depends on the value of the vertical padding. I guess that there is some wrong calculation with the height of the columns due to the padding, and so the number of columns is affected somehow.

    This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

    mPDF 8.0.11 and PHP 7.4.14 (Apache server)

    This is the PHP code snippet I use

    <?php
     $html = "...";
    $mpdf = new \Mpdf\Mpdf([
        'mode' => 'utf-8'
    ]);
    $mpdf->shrink_tables_to_fit = 0;
    $mpdf->SetColumns(2);
    $mpdf->WriteHTML($html);
    $mpdf->Output();
    
    

    This is the HTML/CSS code snippet I use

    <?php
    $elementsCount = 100;
    ?>
    <div>
        <?php for ($i = 0; $i < $elementsCount; $i++) { ?>
    
            <?php if (!($i % 10)) { ?>
                <h2>Category Name</h2>
            <?php } ?>
    
            <?php if (!($i % 5)) { ?>
                <table style="width: 100%;page-break-inside: avoid;">
                    <tr style="background-color: #333;">
                        <!-- PADDING HERE -->
                        <td style="padding:10px 5px;">
                            Group Name
                        </td>
                    </tr>
                </table>
            <?php } ?>
    
            <table style="width:100%;border-collapse: collapse;page-break-inside: avoid">
                <tr>
                    <td style="width:20%;"> Article Name</td>
                    <td style="width:50%;"></td>
                    <td style="width:20%;"> Product</td>
                    <td style="width:10%;"> 10 €</td>
                </tr>
                <tr>
                    <td style="width:20%;"></td>
                    <td style="width:50%;"></td>
                    <td style="width:20%;"> Product 2</td>
                    <td style="width:10%;"> 5 €</td>
                </tr>
            </table>
        <?php } ?>
    </div>
    
    bug/fix notices-warnings 
    opened by Slayvin 0
  • PHP Warning: unpack() on ini mbstring.func_overload = 0 setting

    PHP Warning: unpack() on ini mbstring.func_overload = 0 setting

    This is similar to #91, but without the problematic setting described in that issue.

    mPDF is v8.0.11, PHP is v7.2.24. Characters that are covered by ASCII work fine. CJK characters do not, but I don't have fonts for those yet, so that isn't surprising.

    test.php:

    <?php
    require_once('./vendor/autoload.php');
    
    use \Mpdf\Mpdf;
    use \Mpdf\Config\ConfigVariables;
    use \Mpdf\Config\FontVariables;
    use \Mpdf\Output\Destination;
    
    $defaultConfig = (new ConfigVariables())->getDefaults();
    $fontDirs = $defaultConfig['fontDir'];
    
    $defaultFontConfig = (new FontVariables())->getDefaults();
    $fontData = $defaultFontConfig['fontdata'];
    $mpdf = new Mpdf(
    [
        'tempDir' => sys_get_temp_dir(),
        'mode' => 's',
        'fontDir' => array_merge($fontDirs, 
        [
            './static/fonts',
        ]),
        'fontdata' => $fontData +
        [
            'noto_sans' =>
            [
                'R' => 'NotoSans-Regular.ttf',
                'I' => 'NotoSans-Italic.ttf',
                'B' => 'NotoSans-Bold.ttf',
                'BI' => 'NotoSans-BoldItalic.ttf',
                'E' => 'NotoColorEmoji.ttf',
            ],
            'noto_color_emoji' =>
            [
                'R' => 'NotoColorEmoji.ttf',
            ],
        ],
        'default_font' => 'noto_sans',
        'backupSubsFont' =>
        [
            'noto_sans',
            'noto_color_emoji',
        ],
        'useSubstitutions' => true,
        'charset-in' => 'utf-8',
    ]);
    $mpdf->WriteHTML("😋");
    $temp_pdf_file = "./test.pdf";
    $mpdf->Output($temp_pdf_file, Destination::FILE);
    

    $ php test.php
    Output:

    PHP Notice:  Undefined offset: 48400 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
    PHP Notice:  Undefined offset: 48401 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
    PHP Notice:  Undefined offset: 21826 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
    PHP Notice:  Undefined offset: 21827 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
    PHP Notice:  Undefined offset: 53970 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
    PHP Notice:  Undefined offset: 53971 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
    PHP Notice:  Undefined offset: 18189 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
    PHP Notice:  Undefined offset: 18190 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
    PHP Notice:  Undefined offset: 48400 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
    PHP Notice:  Undefined offset: 48401 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
    PHP Notice:  Undefined offset: 21826 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
    PHP Notice:  Undefined offset: 21827 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
    PHP Notice:  Undefined offset: 53970 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
    PHP Notice:  Undefined offset: 53971 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
    PHP Notice:  Undefined offset: 18189 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
    PHP Notice:  Undefined offset: 18190 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
    

    test.pdf has a single "tofu" character.

    opened by kkjdroid 0
  • Parameter to disable distributing column content on last page

    Parameter to disable distributing column content on last page

    When columns are enabled and MPDF is printing the column buffer, it distributes the column content across all columns. For example, if a document has three columns and there is a total of four columns of content, MPDF will print three columns of content on page 1 and then spread the remaining content across three columns on page 2.

    I would like a parameter on SetColumns to turn this off since I don't want MPDF to distribute the column content. I want three columns of content on page 1 and then one column of content on page 2.

    The code that performs this function is in the printcolumnbuffer function and called "Now update the columns - divide into columns of approximately equal value". When I comment out this block of code, the column distribution function is disabled.

    There is already an option to turn off vertical justification, which apparently is something different, since the code for that is in the next block of code.

    An example of where this would be useful is mailing labels. On the last page of labels, I don't want to start using labels from column 2 or 3 unless all of the labels in column 1 have been used.

    feature/enhancement help wanted 
    opened by Michael-Labriola 0
  • div Tag causes line break after bullet point in PDF

    div Tag causes line break after bullet point in PDF

    I found this bug

    grafik

    I am using DokuWiki for documentation of our electronic devices. We have safety advices and other information that is shown in tables. Documents are exported through the Bookcreator Plugin which again uses mpdf.

    When using DokuWiki syntax for lists in a table an unexpected line break appears after the bullet point. I used to use a workaround with an inline HTML list. But this is somehow not what I want.

    Inspecting the generated HTML code showed that a div-Tag within the li-Tag causes the line break after the bullet point. This behaviour can also be induced by adding a div to the workaroud inline HTML.

    The div Tag should not cause a line break. Does this behaviour come from mpdf? Can it be avoided by CSS?

    This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

    mPDF 8.0.x

    This is the HTML/CSS code snippet I use

    <table class="infobox exttable">
    <tr>
    <td rowspan="2"><img src="/lib/exe/fetch.php?w=100&amp;tok=915f05&amp;media=media:common:iso_7010_w001.png" class="mediacenter" title=" Warning " alt=" Warning " width="100" /> </td>
    <th class="danger">Signal Word</th>
    </tr>
    <tr>
    <td> <strong>Type of danger and source</strong> <br/>
    <br/>
    Consequence of the danger <br/>
    <br/>
    
    </p>
    <ul>
    <li class="level1"><div class="li">Line break after bullet point</div>
    </li>
    </ul>
    
    <p>
    
    <ul>
    <li>HTML workaround</li>
    <li><div>DIV element inserted</li>
    <li>Instruction to avoid the danger</li>
    </ul>
    
    </td>
    </tr>
    </table>
    
    HTML/CSS support bug/fix help wanted 
    opened by arjay54 0
  • File handles not closed + solution

    File handles not closed + solution

    I found this bug

    Where file handles of imported PDFs are not closed after performing ->output(), nor does there seem to be a way to close them. This blocks me from deleting my source PDFs with the following exception unlink(xGf23CbyXDm3HKy8baZ8p2iITjgxWPGZIN6SoM6m.pdf): Text file busy

    This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

    mpdf/mpdf v8.0.11
    PHP 7.4.13 (cli) (built: Nov 24 2020 10:03:34) ( NTS )

    This is the PHP code snippet I use

    I also found the solution here https://github.com/Setasign/FPDI/blob/cddf43dcfe57337bbdc687cb929021174e6696da/src/FpdiTrait.php#L90-L107

    If I manually call this ->cleanUp(), I can delete my PDF without exceptions. However, there is another ->cleanup() method in Mpdf.php https://github.com/mpdf/mpdf/blob/58322c5cf83a5f86e0c5e2109af1e1ce47685b5d/src/Mpdf.php#L1549-L1553

    So I'm not sure where is the best place to add and call this new ->cleanUp() method.

    opened by bilogic 0
  • Fixed font Garuda.ttf problem with

    Fixed font Garuda.ttf problem with "k" character

    Hi

    This Garuda font maybe print is problem. 2021-05-20_143552

    Could your please update Garuda font, problem only with "k" character

    2021-05-20_143046

    Font fixed "Garuda.ttf" "k" cha , i'm not sure does it work. Garuda.zip

    Thank.

    bug/fix changes-update-requested missing sample / test 
    opened by mean-cj 3
  • mirrorMargins always sets Long Edge Binding even on portrait

    mirrorMargins always sets Long Edge Binding even on portrait

    DuplexFlipLongEdge incorrectly set

    Enabling mirrorMargins will always output the following Duplex setting:

    /Duplex /DuplexFlipLongEdge

    Long Edge Binding is only suitable for landscape printing, but this is set for both landscape and portrait. This setting overrides any duplex setting from Adobe Acrobat, so if trying (for example) to print a booklet from a PDF with mirrorMargins = true, every second page will be vertically flipped, nothing allows you to override this.

    Interestingly the relevant section in MetadataWriter.php (line 444) has a line to set short edge bindging for portrait commented out, and it has been commented out since first commit.

    suggested fix

    Change lines 444-448 in MetadataWriter.php to:

    // Duplex is PDF 1.7 spec.
    if ($this->mpdf->mirrorMargins && !$this->mpdf->PDFA && !$this->mpdf->PDFX) {
    	if ($this->mpdf->DefOrientation=='P') { $this->writer->write('/Duplex /DuplexFlipShortEdge'); } 
    	else { $this->writer->write('/Duplex /DuplexFlipLongEdge'); } // PDF v1.7+ 
    }
    

    This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

    MPDF 8.0.10, PHP 7.3.27

    This is the PHP code snippet I use

    $mpdf = new \Mpdf\Mpdf([
    	'mirrorMargins' => true
    ]);
    $mpdf->Output();
    
    bug/fix feature/enhancement help wanted 
    opened by hituro 1
  • "Send mail" to support PDF option

    Feature request

    A client of mine requested that their mpdf generated PDF form should have the "Send email" functionality on a button at the bottom of the page. We got it mostly working the way the client wants, setting up a form with action set to mailto:, and a simple submit button. However, the client needs to have the PDF sent as a PDF in the current state, and it seems it's only possible to send the form data in XFDF format.

    There is an option for this in Acrobat for example, I can edit the button generated from MPDF to send a PDF instead, so in my mind it's just passing some setting to the PDF via a MPDF setup, or some value on the form and/or submit button.

    If this feature is allready available, please point me in the right direction.

    feature/enhancement research needed 
    opened by fluzzywuzzy 2
  • css background color behind element template PDF

    css background color behind element template PDF

    Hello,

    since the last update MPDF, the css background color are behind element on imported template PDF : image

    .checkbox {
          margin: 0 0 0 178mm;
          width: 8mm;
          height: 5mm;
          font-size: 10pt;
          background-color: red;
        }
    
      $pagecount = $mpdf->setSourceFile($pathPdfs . 'cerfa_13753.pdf');
            $tplId = $mpdf->importPage(1);
            $mpdf->useTemplate($tplId)
    

    Thanks for help ^^

    changes-update-requested missing sample / test 
    opened by imajim 3
  • Absolute-positioned content handled as fixed-positioned when includes unclosed paragraphs

    Absolute-positioned content handled as fixed-positioned when includes unclosed paragraphs

    MPDF seems not working correctly when writing attached HTML document into PDF.

    Attached HTML document has following attributes:

    • HTML5 document
    • contains one top-level div element (class="infoBlock")
    • the infoBlock element is styled using position: absolute;
    • the infoBlock element contains two unclosed paragraphs

    Having described HTML document, mpdf stores content of infoBlock as fixed-positioned block: ["fixedPosBlock"]=> string(65) " <p>First testing paragraph. <p>Second testing paragraph. </div> "

    Rendered PDF doesn't contain the desired paragraphs then (as can be seen in the first screenshot).

    After closing the paragraphs, mpdf seems to work correctly and fixedPosBlock variable is empty: ["fixedPosBlock"]=> string(0) ""

    PDF is rendered correctly (as can be seen in the second screenshot).

    Implementation

    PHP

    <?php
    
    /** Require Composer autoload */
    require_once __DIR__ . '/vendor/autoload.php';
    
    $pdf = new \Mpdf\Mpdf();
    $pdf->WriteHTML(file_get_contents('./certificate-page1_2016.html'));
    $pdf->Output();
    exit;
    

    HTML

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width"/>
        <style type="text/css">
            .infoBlock {
                position: absolute;
                top: 780px;
                left: 130px;
                width: 550px;
                max-width: 550px;
                height: 270px;
                max-height: 270px;
                font-size: 11px;
            }
        </style>
    </head>
    <body>
    <div class="infoBlock">
        <p>First testing paragraph.
        <p>Second testing paragraph.
    </div>
    </body>
    </html>
    

    01 02

    HTML/CSS support bug/fix help wanted 
    opened by petrpondelik 5
Releases(v8.0.0)
  • v8.0.0(Mar 15, 2019)

    Version 8.0.0 contains code cleanups, a few minor fixes and features, and most importantly bump of internal dependency of the FPDI library to version 2.

    This introduces a few breaking changes.

    Method SetImportUse has been removed and ImportPage changed case to importPage and has a new signature:

    public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupXObject = true)
    

    Library generating QR codes has been split to a separate package mpdf/qrcode. This reduced package size by about 6 MB. The library will raise an exception hinting to install the package with composer when needed and not present.


    Complete changeset can be found in changelog and commit history.

    Upgrading from 7.x

    • If you use importing capabilities:
      • remove SetImportUse method calls
      • change ImportPage calls to the new signature
    • If you use QR codes
      • require mpdf/qrcode with composer and you're set

    Support our work

    Thank you for any work you put into mPDF - refactorings, bug fixes, new feature requests.

    We also welcome any donation.

    Yaaay! 5 200 000 downloads 🎉!

    Hope number of downloads will keep rising!

    Source code(tar.gz)
    Source code(zip)
  • v7.1.0(May 18, 2018)

    Version 7.1.0 contains large internal code cleanups, big refactoring of HTML tags handling (big kudos to @machour), fixes of many reported PHP notices, and other fixes (!important breaking size conversion, logger changes in internal services).

    As for new features, orientation constructor $config array can be used to specify page orientation (thanks, @Dasc3er). Headers and footers can be now positioned absolutely (thanks, @jakejackson1). QRCode can have a custom color (@achretien).

    Minor version bump justifies an added dependency of myclabs/deep-copy package needed for the fix of TOC pagination.

    Complete changeset can be found in commit history.

    Support our work

    Thank you for any work you put into mPDF - refactorings, bug fixes, new feature requests.

    We also welcome any donation.

    Yaaay! 3 000 000 downloads 🎉!

    It seems almost unbelievable to get a million downloads since the version 7.0, in a half a year. Thanks for using mPDF!

    Source code(tar.gz)
    Source code(zip)
  • v7.0.0(Oct 19, 2017)

    Version 7.0 is a large code cleanup release with introduction of namespaces, code structure cleanup, introduction of PSR compliant file structure and autoloading. It requires at least PHP 5.6 and is tested with up to PHP 7.2.

    See CHANGELOG for the complete list of changes, fixes and enhancements and README for the quick tour.

    See a documentation chapter on upgrading.

    Breaking changes & Removals

    Composer is now the only officially supported installation method. There are no pre-packaged library archives.

    All classes moved under Mpdf namespace. Main class renamed to Mpdf. Now accepts single $config array parameter in its constructor.

    Most side-effects of the former mpdf.php file were removed.

    Progressbar and graph features were removed.

    All global constants were removed in favor of class constants or configuration directives.

    All errors are now thrown as exceptions extending \Mpdf\MpdfException.

    Enhancements

    Support for up to PHP 7.2. File & directory structure cleanup, PSR-4 autoloading. Refactoring of many easy-to-separate code portions.

    Support for multiple font directories. PDF/A-3 associated files + additional xmp rdf support.

    Introduced PSR-3 logging.

    Library name

    There can be a bit of confusion about the library name casing with introduction of PSR-compliant class naming.

    The name of the library is still mPDF.

    Main namespace is Mpdf, FQN of the main class is \Mpdf\Mpdf, packagist package is mpdf/mpdf.

    Support our work

    We welcome any donation.

    Yaaay! 2 000 000 downloads 🎉!

    The mpdf/mpdf Packagist package surpassed the 2 milion downloads some time around October 14th. Thanks for showing us the appreciation this way.

    Future development

    The v7.0 is far from perfect. It retained many of 6.x branch flaws, incomplete CSS support, far-from-perfect architecture.

    The main goal of this version was to start giving the code a clean and defined structure and slowly starting decomposing it to smaller parts. This helped add support for newer PHP versions.

    There are many things to be done, some of them are laid out in the Issues tracker here on GitHub.

    mPDF now should follow semver. All reported notice and warning fixes will be continually solved in patch releases, smaller new functionality can be added in minor releases. Breaking changes will have to wait for major releases, in this case v8.

    Thanks

    Many thanks to all small contributors to the library mentioned in the changelog, sorry to anyone who was missed.

    Special thanks to @Klap-in for his extensive work on the documentation.

    Source code(tar.gz)
    Source code(zip)
  • v6.1.0(Apr 26, 2016)

    See CHANGELOG.txt for list of changes, fixes and enhancements.

    Composer package mpdf/mpdf is a recommended installation method:

    $ composer require mpdf/mpdf 6.1.0
    

    You can also choose from a variety of pre-packaged files which contain pregenerated autoload library from Composer, so you would then require autoload.php file:

    <?php
    
    require PATH_TO_MPDF . '/vendor/autoload.php';
    
    Source code(tar.gz)
    Source code(zip)
    01-mPDF-v6.1.0.zip(51.43 MB)
    02-mPDF-v6.1.0-without-examples.zip(47.68 MB)
    03-mPDF-v6.1.0-without-examples-and-fonts.zip(4.93 MB)
    04-mPDF-v6.1.0-examples.zip(3.74 MB)
    05-mPDF-fonts.zip(42.75 MB)
Laravel Snappy PDF

Snappy PDF/Image Wrapper for Laravel 5 and Lumen 5.1 This package is a ServiceProvider for Snappy: https://github.com/KnpLabs/snappy. Wkhtmltopdf Inst

Barry vd. Heuvel 2k Jun 8, 2021
Convert html to an image, pdf or string

Convert a webpage to an image or pdf using headless Chrome The package can convert a webpage to an image or pdf. The conversion is done behind the sce

Spatie 3.2k Jun 18, 2021
PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Snappy Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopd

KNP Labs 3.9k Jun 11, 2021
TCPDF - PHP PDF Library - https://tcpdf.org

tc-lib-pdf PHP PDF Library UNDER DEVELOPMENT (NOT READY) UPDATE: CURRENTLY ALL THE DEPENDENCY LIBRARIES ARE ALMOST COMPLETE BUT THE CORE LIBRARY STILL

Tecnick.com LTD 1k Jun 17, 2021
A DOMPDF Wrapper for Laravel

DOMPDF Wrapper for Laravel Laravel wrapper for Dompdf HTML to PDF Converter Require this package in your composer.json and update composer. This will

Barry vd. Heuvel 4.6k Jun 14, 2021
A PHP tool that helps you write eBooks in markdown and convert to PDF.

Artwork by Eric L. Barnes and Caneco from Laravel News ❤️ . This PHP tool helps you write eBooks in markdown. Run ibis build and an eBook will be gene

Mohamed Said 1.4k Jun 12, 2021
PHP library generating PDF files from UTF-8 encoded HTML

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 enhancement

null 3.2k Jun 10, 2021
HTML to PDF converter for PHP

Dompdf Dompdf is an HTML to PDF converter At its heart, dompdf is (mostly) a CSS 2.1 compliant HTML layout and rendering engine written in PHP. It is

null 8k Jun 18, 2021
A PHP report generator

PHPJasper A PHP Report Generator Docs About PHPJasper is the best solution to compile and process JasperReports (.jrxml & .jasper files) just using PH

PHPJasper 341 Jun 4, 2021
Official clone of PHP library to generate PDF documents and barcodes

TCPDF PHP PDF Library Please consider supporting this project by making a donation via PayPal category Library author Nicola Asuni [email protected] co

Tecnick.com LTD 2.9k Jun 14, 2021
PdfParser, a standalone PHP library, provides various tools to extract data from a PDF file.

PdfParser Pdf Parser, a standalone PHP library, provides various tools to extract data from a PDF file. Website : https://www.pdfparser.org Test the A

Sebastien MALOT 1.5k Jun 12, 2021
Adobe XDでデザインしてSVGでエクスポートしたテンプレートをもとに、A4サイズの帳票をHTMLで出力する機能のPHP(Laravel)による実装例です

svg-paper-example Adobe XDでデザインしてSVGでエクスポートしたテンプレートをもとに、A4サイズの帳票をHTMLで出力する機能のPHP(Laravel)による実装例です。 こちらで実際に動くデモが見られます ?? 実装内容についての詳細は こちらのブログ記事 で解説していま

Takashi Kanemoto 10 Jun 13, 2021
Convert HTML to PDF using Webkit (QtWebKit)

wkhtmltopdf and wkhtmltoimage wkhtmltopdf and wkhtmltoimage are command line tools to render HTML into PDF and various image formats using the QT Webk

wkhtmltopdf 11.2k Jun 19, 2021
Add better visible controls on Beaver Builder editor. Work by Matt Eastwood

Beaver Builder UI Enhancements Community Plugin by Matt Eastwood / Guy Barry / Didou Schol / Marleen Kiral Add extra styling when editing Beaver Build

Didou Schol 12 May 2, 2021