mpdf / mpdf Goto Github PK
View Code? Open in Web Editor NEWPHP library generating PDF files from UTF-8 encoded HTML
Home Page: https://mpdf.github.io
License: GNU General Public License v2.0
PHP library generating PDF files from UTF-8 encoded HTML
Home Page: https://mpdf.github.io
License: GNU General Public License v2.0
It saves paper to have two or more columns in the Table of Contents when there are hundreds of chapter names with short titles.
Currently, the HTML for the table of contents appears to switch columns off in the class tocontents (see lines 225-226 of https://github.com/mpdf/mpdf/blob/development/classes/tocontents.php):
if ($this->mpdf->ColActive) {
$this->mpdf->SetColumns(0);
The tag could have the parameters 'column-count', 'vAlign' and 'column-gap' to control the values nCols, vAlign and gap for SetColumns (see http://mpdf1.com/manual/index.php?tid=113 and http://mpdf1.com/manual/index.php?tid=139).
It is security issue. It changes sources of your application. Maybe it can be something like cli-only script.
I just use the Getting start from
http://mpdf1.com/manual/index.php?tid=106
$mpdf=new mPDF();
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output();
exit;
and got this error.
include(/var/www/svn_data/skeletonapp/mpdf/ttfontdata/dejavuserifcondensed.mtx.php): failed to open stream: No such file or directory
My css fails because body classes are getting removed, here is a demo/bodge of the affected area.
mpdf.php
if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
- $html = $m[2];
+ $html = '<div ' . $m[1] . '>' . $m[2] . '</div>';
}
``h1 + p {}`
doesn't seem to work
Gents, since it is clear the open source version of FDPI won't support the ability to read PDF 1.5+ in the near future I've been looking into the "hows" of developing an open source version the whole community can use (it involved a lot of laborious reading of the PDF spec).
I believe the current blockers are two-fold:
The support of new filters introduced in PDF 1.5.
ASCIIHexDecode - Already Support in FPDI
ASCII85Decode - Already Support in FPDI
LZWDecode - Already Support in FPDI
FlateDecode - Need to Implement
RunLengthDecode - Need to Implement
CCITTFaxDecode - Not sure about this yet
JBIG2Decode - Not sure about this yet
DCTDecode - Not sure about this yet
JPXDecode - Not sure about this yet
Crypt - Not sure about this yet
Assuming the licensing issue is resolved, we'll be able to borrow heavily from the TCPDF project which actually implements the FlateDecode and RunLengthDecode filters already. That makes that job a bit easier.
FPDI currently only supports standard xref tables. PDF 1.6 introduced xref cross reference streams which will need to be handled correctly. Again, the good news is the TCPDF project also implements this correctly in the getXrefData
/ decodeXrefStream
/ decodeXref
methods in their tcpdf_parser.php file.
There could be additional blockers preventing this feature being implemented but I won't know without some real-world testing.
This isn't currently a high priority, but I feel it's one of those must-have features the PHP PDF open-source community will greatly benefit from.
I'll be playing around with this possibility in my free time. If anyone would like to contribute it would be greatly appreciated.
How do you remove Page numbering from first page of single AddPage()?
Undefined variable: list_item_marker.
Variable $list_item_marker seems to be uninitialized.
(mpdf.php v6.0 Line: 19446)
SOLUTION:
Line 19446 :
$objattr['text'] = $list_item_marker;
have to be commented or deleted.
Language constructs are provided by the language itself so they are NOT function.
Such include require exit echo print return... unless you need to bundle a long input/string.
So it's better to remove ALL Parenthesis from them.
Separate all direct output from main mpdf class to conform with PSR-1.
I have imported mpdf class with composer (including it in composer.json) and I tried to use my own TrueType Fonts.
I know that I can modify config_fonts.php and copy my fonts to ttfonts directory, but when I tried to work with a repository (Here is where I needed composer.json) I couldn't find a solution to use my fonts.
I tried to solve this by the definition of the constants MPDF_SYSTEM_TTFONTS, MPDF_TTFONTPATHand MPDF_TTFONTDATAPATH but it didn't helped because my problem was config_fonts.php.
Then, I put this:
$pdf = new mPDF('utf-8','A4','','Foco',0,0,23,0,0,0,'');
$pdf->fontdata = array(
"foco" => array(
'R' => "Foco_Rg.ttf",
'B' => "Foco_0.ttf",
'I' => "Foco_Lt.ttf",
),
);
But when I tried to export my pdf file I got this error:
mPDF Error - Font is not supported - dejavusanscondensed
I searched but I didn't found how to solve it.
Repost from mPDF forum user TAlmasy:
When a tag is made with a 0 value inside it will not render.
This does NOT happen in 5.7, only in 6.0
<?php
$prob = 'hi<b>0</b><b>1</b>';
include_once($_SERVER['DOCUMENT_ROOT']."/mpdf60/mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($prob);
$mpdf->Output();
?>
This can be fixed by modifying line 21646 and adding the && $arrayaux[$i][0]!=='0'
bit.
// Remove empty items // mPDF 6
for($i=$array_size-1; $i > 0; $i--) {
if (empty($arrayaux[$i][0]) && $arrayaux[$i][0]!=='0' && $arrayaux[$i][16]!=='0' && empty($arrayaux[$i][7])) {
unset($arrayaux[$i]);
}
}
Repost from mPDF forum user TAlmasy:
Example code that displays problem:
<?php
$prob = '
<div style="width:100%;" id="ONEHUNDREDWIDTH">
<div style="float:right; width:70mm; height:30mm; background:rgba(0,0,0,0.5); font-size:15pt;" id="RIGHTFLOAT">right</div>
';
$letters = ['a','b','c','d','e'];
for($i=0;$i<4;$i++){
$prob .= '
<div style="float:left; " id="'.$bg[$i].'">
<div style="float:left; background:rgba(255,0,0,0.5); height:20mm; width:30%;" id="LETTER '.$letters[$i].'1">'.$letters[$i].'1</div>
<div style="float:left; background:rgba(255,0,0,0.5); height:20mm; width:49%;" id="LETTER '.$letters[$i].'1">'.$letters[$i].'2</div>
</div>
';
}
$prob .= '</div>';
include_once($_SERVER['DOCUMENT_ROOT']."/mpdf60/mpdf.php");
$mpdf=new mPDF('utf-8',[100,30], 0, 'times', 0, 0, 0, 0, 0, 0);
$mpdf->WriteHTML($prob);
$mpdf->Output();
?>
Notice how when the second set of divs appears on the page it doesn't expand to the page width?
Here's a workaround I found (it can probably be modified a bit so it only effects nested floated divs).
On line 14701 add block from the second line to end:
$this->OpenTag($tag,$attr,$a,$i); // mPDF 6
if( $this->blk[$this->blklvl]['NewPageStart'] == 'y'){
$i -= (count($this->blk)+1)/2;
$this->blklvl = 0;
$temp = $this->blk[0];
unset($this->blk);
$this->blk[0] = $temp;
continue;
};
And on line 17182 add the $currblk['NewPageStart'] = 'y';
and return
bit:
if (isset($properties['HEIGHT'])) {
$currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false);
if (($currblk['css_set_height'] + $this->y) > $this->PageBreakTrigger && $this->y > $this->tMargin+5 && $currblk['css_set_height'] < ($this->h - ($this->tMargin + $this->bMargin))) {
$currblk['NewPageStart'] = 'y';
$this->AddPage($this->CurOrientation);
return;
}
}
With the border spacing property applied to my table it prevented the table from breaking the rows between pages. It would simply cutoff the table and continue printing other content on the following pages with the rest of the table nowhere to be found.
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?
Error seen when rendering SVG as part of a PDF when using PHP 7.1.0-dev (cli) (built: Dec 7 2015 12:44:25)
Commenting out the break on line 3000 of classes/svg.php works around the problem, but is too hacky.
This code works
h2, h3, h4{
page-break-after: always;
}
but this doesn't
h2, h3, h4{
page-break-after: avoid;
}
Hi,
See the following php code:
<?php
require '../mpdf.php';
for ($index = 1; $index <= 5; $index++)
{
$mpdf=new mPDF('ar-s','A4','','');
$mpdf->SetDirectionality('rtl');
$mpdf->WriteHTML('سؤال');
$mpdf->Output('test'.$index.'.pdf','F');
}
?>
The first created PDF file is OK, but in the other files, the Arabic characters are not connected.
OK (PDF 1): سؤال
Not OK (PDF 2-5): س ؤال
(without the space after س
)
It would be good in the near future to start writing unit tests for mPDF and breaking down some of the methods into smaller, more manageable chunks. I had understood v6 was the last major release Ian was going to work on. If mPDF is to move forward as a community effort the first step would be to refractor the software. Writing unit tests would be stage 1 of this process.
Thoughts?
The output of <input />
or <textarea>
fields are black. There's no way to change their colour using CSS. You would expect the CSS property color
to control the output but that isn't the case.
Currently paths for temoprary and ttffontdata directory can be defined so that they can be placed outside the library itself for security purpose. This is a nice feature.
However, the path for graph_cache folder is fixed and can not be changed to external directory.
Can this be added as a feature in the same way as the above two folders are defined as follows
define("_MPDF_TEMP_PATH", DIR.'/../permitted/mpdf/tmp/');
define("_MPDF_TTFONTDATAPATH", DIR.'/../permitted/mpdf/ttfontdata/');
Repost from mPDF forum user TAlmasy:
<?php
$prob = '
<style>
tr:nth-child(odd) td:nth-child(2n+2){
background: yellow;
}
</style>
<table>';
for($i=1;$i<=4;$i++){
$prob .= '<tr>';
for($j=1;$j<=10;$j++){
$prob .= '<td>'.$j.'</td>';
}
$prob .= '</tr>';
}
$prob .= '</table>';
include_once($_SERVER['DOCUMENT_ROOT']."/mpdf60b/mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($prob);
$mpdf->Output();
?>
This code will not parse the td section correctly.
This can be fixed by commenting out line 251 in the css manager.
$tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD('.str_replace(' ','',$m[1]).')', $tg);
I'm not really even sure what this line is for. I can see why it is failing (the * is greedy and grabbing everything between the parenthesis), but for what purpose is it replacing the text?
After FPDF update mPDF will require some sort of autoloading anyway. Let composer make the work for external libraries and mpdf itself.
mPDF 6.0 has over 85 megs (uncompressed) of data in the ttfonts directory (out of 108 Megs). This has the benefit that a large number of languages are supported out of the box.
BuiltWith reports that Font Awesome is used by 22% of websites:
http://trends.builtwith.com/widgets/fonts
Glyphicons are in Bootstrap, which has a huge presence as well:
http://trends.builtwith.com/docinfo/Twitter-Bootstrap
http://getbootstrap.com/components/#glyphicons
So they definitely should be handled somehow. And perhaps other popular open fonts should be included as well (ex.: Glyphicons)
Thanks!
I have been trying to get PDF file with crop marks and custom headers on front matter and content pages. I have put all of my experiments (with code and output PDF files) here - https://github.com/booktype/mPDF-examples
My output files either have no visible page numbers or ToC is broken without page numbers for my chapters.
I am expecting to get this from the output:
I will also post message to Forum (I applied for an account) and see if someone had similar issue.
For version 7.0 I'd like to introduce mPDF namespace for all classes. So the main class would be \mPDF\mPDF, all other classes would be prefixed accordingly.
@finwe wrote: "I believe mPDF officially supports PHP 5.2, however it can be run on PHP 4 when not using many advanced features. In the first round of code cleanup, I would like to retain this compatibility." Source: #35 (comment)
@blueliquiddesigns wrote: "With this change it also would be good to decide on the minimum supported PHP version mPDF should support in the future. I'd recommend PHP5.3.2 which will allow us to take advantage of namespaces, autoloading, closures and SPL." Source:
#35 (comment)
@danielhjames wrote: " I suggest there would be one branch for fixes to 6.0 which could potentially be the basis of an official 6.1 release, with Ian's approval, as these changes should be relatively easy to review. There would be another branch for a future mPDF 7.0 release which was refactored, with all the improvements we would like to see." Source: #47 (comment)
PHP 5.4.x has reached end of life:
"Please note that according to the PHP version support timelines, PHP 5.4.45 is the last scheduled release of PHP 5.4 branch. There may be additional release if we discover important security issues that warrant it, otherwise this release will be the final one in the PHP 5.4 branch. If your PHP installation is based on PHP 5.4, it may be a good time to start making the plans for the upgrade to PHP 5.5 or PHP 5.6."
Source: http://php.net/archive/2015.php#id2015-09-04-4
The mPDF team should not spend additional time to support end-of-life versions of PHP. I propose that future major versions (ex.: mPDF 7) require a minimum of PHP 5.5, which offers significant performance gains:
https://thephp.cc/news/2013/06/php-5-5-out-of-the-box-bytecode-cache
And this will help with documented performance concerns:
http://mpdf1.com/manual/index.php?tid=266
http://mpdf1.com/manual/index.php?tid=408
Best regards,
M ;-)
I made some step-by-step test, where is problem with timezone on production server.
Server setting timezone "Europe\Prague"
date_default_timezone_get(); //Europe/Prague
Framework (Nette) setting timezone "Europe\Prague"
date_default_timezone_get(); //Europe/Prague
Loading mPdf by autoload
date_default_timezone_get(); //Europe/London
Comment lanes:
//if(function_exists("date_default_timezone_set")) {
//if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); }
//}
date_default_timezone_get(); //Europe/Prague
I am not able to find a way how to print out ToC without pagebreak.
The function WriteBarcode()
strips the hyphen character (-
) although the documentation says it is supported for Code39 and some other types.
If someone can explain to me why this character is removed, i will try to help providing a bugfix.
Hola como puedo instanciar mPDF en laravel 5.1 y si tienen algun ejemplo le estare muy agradecido
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.
"mPDF has limited scope to control when automatic page-breaks occur, and does not have 'widows' or 'orphans' protection."
Source: http://mpdf1.com/manual/index.php?tid=108
Other related links:
Using latest mPDF (6.0) is displaying 2 notices:
Undefined offset: 16 in mpdf.php on line 21162
This because $arrayaux[$i][16]
does not exist.
And
Undefined offset: 1 in mpdf.php on line 21193
Nearly the same: $arrayaux[$i]
Disabling any error output will work, but cannot be the solution.
This PR does most of the work #35
Converting is not that simple as some special characters would be owerwritten - a check and preferably a unit test would be in order. Changed characters can be seen in pull request #21
Before all orher code enhancements, I would like to enforce a coding standard on the project.
PSR-2 may be a nice choice, of course with some exceptions to maintain backwards compatibility.
When inside a frameset is a tag with any other font (like monotyp), in this case class="mono", the legend get the same font.
This is only if there is some content in the tag. If it is empty the font is arial (default/correct).
<div class="grid-66 mobile-grid-100 tablet-grid-100">
<fieldset class="sec">
<legend>Karosserie-Prüfung</legend>
<b style="margin-right: 10px;">Status</b> <span class="fakeinput mark_1">in Ordnung</span>
<br><div class="fakeinput"><pre class="mono"></pre></div>
</fieldset>
<br>
<fieldset class="sec">
<legend>Wartung laut DSR</legend>
<div>
<b style="margin-right: 10px;">Status</b> <span class="fakeinput mark_1">in Ordnung</span>
<br><div class="fakeinput">
<pre class="mono">{I'm monotype by css. If I'm not empty the legend get my font}</pre></div>
</div>
</fieldset>
</div>
ImageCreate error: image type not recognised, and not supported by GD imagecreate
hi,
i am using mpdf in yii2. This is my controller code
public function actionPrint_death_certificate1()
{
$this->layout = 'certificate';
$html = $this->render('test');
require_once(Yii::$app->basePath . "/../vendor/mpdf/mpdf/mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
}
my view
<div class="container">
<div class="row">
<div class="col-md-6">
Heading1
</div>
<div class="col-md-6">
Heading2
</div>
</div>
</div>
now i get a pdf with heading1 and heading2 in two different lines. Bootstrap is not working. Am i missing something?
return $this->render('test');
when i tried this one it is working and heading1 and heading2 is coming in one line. In pdf it is not working
I can't find the method mPDF::SetProtection() in version 6.0... Any idea?
Hi there, i use 5.7.4 version of mpdf and my php version is 5.6.12.
I use this code
$pdf->setHTMLFooter('{DATE j-m-Y}');
end get that error:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in somefiles/_mpdf/mpdf.php on line 7333
Thanks.
currently you write into the following folders inside of the package:
would be pretty nice to be able to define either these 3 pathes individually or via a prefix path, which will resolve like this:
This way we can ensure, that we do not need to write into the folders of the package, which should be possible at all circumstances.
PDF for MathJax version 2.5 doesn't generated.
The latest version of MathJax, which successfully generated PDF - 2.4
For the file mpdf60/examples/MathJaxSample.htm
best regards
Warning: require_once(C:/www/index/config_cp.php): failed to open stream: No such file or directory in C:\www\index\mpdf.php on line 39
Fatal error: require_once(): Failed opening required 'C:/www/index/config_cp.php' (include_path='.;C:\program files\php\PEAR') in C:\www\index\mpdf.php on line 39
Via this http://mpdf1.com/manual/index.php?tid=106 link.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.