Giter VIP home page Giter VIP logo

mpdf's Introduction

mpdf

Latest Stable Version License Total Downloads Monthly Downloads Daily Downloads


Use the mpdf/mpdf repo instead

Effective 08-Apr-2016, I am redirecting and encouraging folks to use the above repo - to ensure a single codebase for mpdf management in future. This repo was initially created since there was no other package having the 6.x release that could be installed via composer. For folks coming over from Yii, note that the yii2-mpdf extension has been modified to use the mpdf/mpdf repo


This is a fork of the mPDF library. mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements. It is slower than the original scripts e.g. HTML2FPDF and produces larger files when using Unicode fonts, but support for CSS styles etc. has been much enhanced.

This fork adds composer and packagist support.

Why this repo?

I needed this for building many of my dependent PHP based projects that use this wonderful PDF library. Managing package dependencies via a central repository was important for folks like me. I use composer to manage package dependencies via packages on packagist.org. This repository allows access to some specific features and needs:

  1. Adds ability to update library and manage dependencies via composer in your PHP based applications
  2. Uses the latest development version (v6.0beta) of the mPDF library. I needed the latest development version via composer, which was not found elsewhere. mPDF 6.0 can utilise OpenType layout tables to display complex scripts. It will be of most interest to those wishing to use Arabic or Indic scripts (as well as Khmer, Lao, Myanmar etc.). It will also improve the display of Thai, Vietnamese and Hebrew.
  3. This beta release (v6.0) contains fonts (open source) to cover almost every imaginable script / language. It also includes additional fonts for Chinese, Japanese, and Korean.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require mpdf/mpdf "@dev"

or add

"mpdf/mpdf": "@dev"

to the require section of your composer.json file.

Refer the readme instructions for other details on setting up the extension.

Usage

PHP 5.4 and later can use namespaces to access. Refer the documentation manual or the upstream mpdf site for further details and understanding of the library.

use \mPDF;

$pdf = new mPDF();

mpdf's People

Contributors

danielhjames avatar danik2592 avatar iddqdidkfa avatar kartik-v 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

Watchers

 avatar  avatar  avatar  avatar

mpdf's Issues

PHP 7.1: Illegal string offset 'ID'

Error has shown after php update to 7.1 version. On 7.0 it works fine.

       $mpdf = (new Pdf($this->pdfParams))->api;
       $mpdf->setAutoTopMargin = 'stretch';
       $mpdf->setAutoBottomMargin = 'stretch';
       $mpdf->SetFooter($footer); // error's here 
       $mpdf->WriteHTML($html);
       return $mpdf;

default

preg_replace(): Compilation failed: regular expression is too large at offset ...

There is an error in cssmgr.php:164 :

    if (preg_match('/@media/',$CSSstr)) { 
        preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
        for($i=0; $i<count($m[0]); $i++) {
            if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { 
                $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
            }
            else {
                $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
            }
        }
    }

On large CSS files with complicated rules it may cause regexp limit when replacing by preg_replace:

exception 'yii\base\ErrorException' with message 'preg_replace(): Compilation failed: regular expression is too large at offset 70187' in .../vendor/kartik-v/mpdf/classes/cssmgr.php:164

... but (as far as I can see) there is no real need in preg_replace() in this place. We have exact text, matched by preg_match_all() and now we can use str_replace() (or mb_str_replace()) to clear it out.

P.S. I don't offer pull request because I can miss something


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

extract message i18n fails

Extracting messages from ←[0m←[36mC:\xampp\htdocs\cis.wkt\vendor\kartik-v\mpdf\m
pdf.php←[0m...
PHP Fatal Error 'yii\base\ErrorException' with message 'Allowed memory size of 1
34217728 bytes exhausted (tried to allocate 36 bytes)'

in C:\xampp\htdocs\cis.wkt\vendor\yiisoft\yii2\console\controllers\MessageContro
ller.php:287

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

qrcode doesn't accepts line breaks

I tried with:
\r\n

a\r\nb\r\nc

\x0D\x0A

a\x0D\x0Ab\x0D\x0Ac

%0A in the query string...
?test=a%0Ab%0Ac and then

<barcode code="<?php print $_GET["test"]; ?>" type="QR" error="H" />

but nothing.
After the generation my phone scan it as "a b c".
How to solve it?

Thanks in advance


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Matrix equations are not working

Matrix equations are working in html page, but its not working in mpdf after submitting a form.

Example code :

\[ \left( \begin{array}{cc} 1 & 0 \\ 0 & 1 \end{array} \right) % \left( \begin{array}{cc} 1 & 0 \\ 0 & 1 \end{array} \right) \]

Remove unnecessary iccprofiles

Hi @kartik-v ,

I was looking into the size of the mpdf library and discovered that about 30Mb can be removed from the download file by removing the iccprofiles/CMYK directory.

The developer has removed these from the latest version. Would you like me to fork and send a pull request? Or would you like to leave it as is for now?

Cheers,

Tom

1.0.2 tag is missing

Or sg else gone wrong

Updating dependencies (including require-dev)
  - Updating kartik-v/mpdf (v1.0.1 => v1.0.2)
    Checking out cd239c6b4897302142316cdb01f32f5f57d9a108
    cd239c6b4897302142316cdb01f32f5f57d9a108 is gone (history was rewritten?)

exception 'ReflectionException' with message 'Class robregonm\pdf\PdfResponseFormatter does not exist

An Error occurred while handling another error:
exception 'ReflectionException' with message 'Class robregonm\pdf\PdfResponseFormatter does not exist' in /var/sentora/hostdata/zadmin/public_html/.../vendor/yiisoft/yii2/di/Container.php:422
Previous exception:
exception 'yii\base\ErrorException' with message 'file_put_contents(/var/sentora/hostdata/zadmin/public_html/.../vendor/mpdf/mpdf/ttfontdata/xbriyaz.GSUBGPOStables.dat): failed to open stream: Permission denied' in /var/sentora/hostdata/zadmin/public_html/.../vendor/mpdf/mpdf/classes/ttfontsuni.php:1264

Problem in generating link

When trying to generate link:

echo Html::a('www.aaaa.com', 'www.aaaa.com');

The generated link in PDF document became http://localhost/app/web/www.aaaa.com. Is it possible to generate external link without including application URL?

Unable to render HTML to PDF

I have created an HTML page using bootstrap and CSS. When I try to render it I am getting error

      `$content = $this->renderPartial('_bill', ['dataProvider' => $dataProvider]);

        $pdf = new Pdf([
            // set to use core fonts only
            'mode' => Pdf::MODE_UTF8,
            // A4 papr format
            'format' => Pdf::FORMAT_A4,
            // portrait orientation
            'orientation' => Pdf::ORIENT_PORTRAIT,
            // stream to browser inline
            'destination' => Pdf::DEST_DOWNLOAD,
            // your html content input
            'content' => $content,
            // format content from your own css file if needed or use the
            // enhanced bootstrap css built by Krajee for mPDF formatting
            //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            // any css to be embedded if required
            'cssInline' => '.kv-heading-1{font-size:14px}',
            // set mPDF properties on the fly
            'options' => ['title' => 'Bill'],
            // call mPDF methods on the fly
            'methods' => [
                'SetHeader' => ['Generated On: ' . date("Y-m-d h:i:sa")],
                'SetFooter' => ['{PAGENO}']
            ]
        ]);

        $pdf->filename = "Bill.pdf";

        try {
            return $pdf->render();
        } catch (MpdfException $e) {
            print_r('MPDF Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (CrossReferenceException $e) {
            print_r('Cross Reference Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (PdfTypeException $e) {
            print_r('Pdf Type Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (PdfParserException $e) {
            print_r('Pdf Parser Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (InvalidConfigException $e) {
            print_r('(Invalid Config Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        }
        `

image

Here is the Fiddle


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Invalid path check is_dir tmp file delete

Line 8354 mpdf.php

if (($file != "..") && ($file != ".") && !is_dir($file) && ((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && (substr($file, 0, 1) !== '.') && ($file !='dummy.txt')) { // mPDF 5.7.3

Invalid is_dir check file, there is no have path of this file/dir so it always return false, it must by like this:

if (($file != "..") && ($file != ".") && !is_dir(_MPDF_TEMP_PATH.$file) && ((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && (substr($file, 0, 1) !== '.') && ($file !='dummy.txt')) { // mPDF 5.7.3


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

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.