Skip to content

Commit

Permalink
Merge pull request #113 from mansoorkhan96/master
Browse files Browse the repository at this point in the history
Upgrade Fpdf to v1.84
  • Loading branch information
codedge authored Sep 14, 2021
2 parents d733f2f + 66ec9bc commit 413b570
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 73 deletions.
15 changes: 7 additions & 8 deletions src/Fpdf/FAQ.htm
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ <h1>FAQ</h1>
<p><b>2.</b> <span class='question'>I get the following error when I try to generate a PDF: Some data has already been output, can't send PDF file</span></p>
You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return. A common
case is having extra blank at the end of an included script file.<br>
If you can't figure out where the problem comes from, this other message appearing just before can help you:<br>
If you can't figure out where the problem comes from, this other message appearing just before will help you:<br>
<br>
<b>Warning:</b> Cannot modify header information - headers already sent by (output started at script.php:X)<br>
<br>
It means that script.php outputs something at line X. Go to this line and fix it.
In case the message doesn't show, first check that you didn't disable warnings, then add this at the very
beginning of your script:
It means that script.php outputs something at line X. Go to that line and fix it.
In case the message doesn't show, check if PHP warnings are enabled. If they are not, enable them. If they are,
try adding this at the very beginning of your script:
<div class="doc-source">
<pre><code>ob_end_clean();</code></pre>
</div>
If you still don't see it, disable zlib.output_compression in your php.ini and it should appear.
</li>

<li id='q3'>
Expand Down Expand Up @@ -213,7 +212,7 @@ <h1>FAQ</h1>

<li id='q15'>
<p><b>15.</b> <span class='question'>How can I send the PDF by email?</span></p>
As for any other file, but an easy way is to use <a href="http://phpmailer.codeworxtech.com" target="_blank">PHPMailer</a> and
As for any other file, but an easy way is to use <a href="https://github.com/PHPMailer/PHPMailer" target="_blank">PHPMailer</a> and
its in-memory attachment:
<div class="doc-source">
<pre><code>$mail = new PHPMailer();
Expand Down Expand Up @@ -251,12 +250,12 @@ <h1>FAQ</h1>
<li id='q18'>
<p><b>18.</b> <span class='question'>I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?</span></p>
No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from a PDF.
It's provided with the <a href="http://www.foolabs.com/xpdf/" target="_blank">Xpdf</a> package.
It's provided with the <a href="https://www.xpdfreader.com" target="_blank">Xpdf</a> package.
</li>

<li id='q19'>
<p><b>19.</b> <span class='question'>Can I convert an HTML page to PDF with FPDF?</span></p>
Not real-world pages. But a GPL C utility does exist, <a href="https://www.msweet.org/projects.php?Z1" target="_blank">HTMLDOC</a>,
Not real-world pages. But a GPL C utility does exist, <a href="https://www.msweet.org/htmldoc/" target="_blank">HTMLDOC</a>,
which allows to do it and gives good results.
</li>

Expand Down
73 changes: 44 additions & 29 deletions src/Fpdf/Fpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/*******************************************************************************
* FPDF *
* *
* Version: 1.82 *
* Date: 2019-12-07 *
* Version: 1.84 *
* Date: 2021-08-28 *
* Author: Olivier PLATHEY *
*******************************************************************************/

define('FPDF_VERSION','1.82');
define('FPDF_VERSION','1.84');

class Fpdf
{
Expand Down Expand Up @@ -1090,6 +1090,7 @@ protected function _beginpage($orientation, $size, $rotation)
{
$this->page++;
$this->pages[$this->page] = '';
$this->PageLinks[$this->page] = array();
$this->state = 2;
$this->x = $this->lMargin;
$this->y = $this->tMargin;
Expand Down Expand Up @@ -1507,27 +1508,13 @@ protected function _putpage($n)
if(isset($this->PageInfo[$n]['rotation']))
$this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
$this->_put('/Resources 2 0 R');
if(isset($this->PageLinks[$n]))
if(!empty($this->PageLinks[$n]))
{
// Links
$annots = '/Annots [';
$s = '/Annots [';
foreach($this->PageLinks[$n] as $pl)
{
$rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
$annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
if(is_string($pl[4]))
$annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
else
{
$l = $this->links[$pl[4]];
if(isset($this->PageInfo[$l[0]]['size']))
$h = $this->PageInfo[$l[0]]['size'][1];
else
$h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k;
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
}
}
$this->_put($annots.']');
$s .= $pl[5].' 0 R ';
$s .= ']';
$this->_put($s);
}
if($this->WithAlpha)
$this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
Expand All @@ -1537,22 +1524,50 @@ protected function _putpage($n)
if(!empty($this->AliasNbPages))
$this->pages[$n] = str_replace($this->AliasNbPages,$this->page,$this->pages[$n]);
$this->_putstreamobject($this->pages[$n]);
// Annotations
foreach($this->PageLinks[$n] as $pl)
{
$this->_newobj();
$rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
$s = '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
if(is_string($pl[4]))
$s .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
else
{
$l = $this->links[$pl[4]];
if(isset($this->PageInfo[$l[0]]['size']))
$h = $this->PageInfo[$l[0]]['size'][1];
else
$h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k;
$s .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
}
$this->_put($s);
$this->_put('endobj');
}
}

protected function _putpages()
{
$nb = $this->page;
for($n=1;$n<=$nb;$n++)
$this->PageInfo[$n]['n'] = $this->n+1+2*($n-1);
for($n=1;$n<=$nb;$n++)
$this->_putpage($n);
$n = $this->n;
for($i=1;$i<=$nb;$i++)
{
$this->PageInfo[$i]['n'] = ++$n;
$n++;
foreach($this->PageLinks[$i] as &$pl)
$pl[5] = ++$n;
unset($pl);
}
for($i=1;$i<=$nb;$i++)
$this->_putpage($i);
// Pages root
$this->_newobj(1);
$this->_put('<</Type /Pages');
$kids = '/Kids [';
for($n=1;$n<=$nb;$n++)
$kids .= $this->PageInfo[$n]['n'].' 0 R ';
$this->_put($kids.']');
for($i=1;$i<=$nb;$i++)
$kids .= $this->PageInfo[$i]['n'].' 0 R ';
$kids .= ']';
$this->_put($kids);
$this->_put('/Count '.$nb);
if($this->DefOrientation=='P')
{
Expand Down
12 changes: 12 additions & 0 deletions src/Fpdf/changelog.htm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
<body>
<h1>Changelog</h1>
<dl>
<dt><strong>v1.84</strong> (2021-08-28)</dt>
<dd>
- Fixed an issue related to annotations.<br>
</dd>
<dt><strong>v1.83</strong> (2021-04-18)</dt>
<dd>
- Fixed an issue related to annotations.<br>
</dd>
<dt><strong>v1.82</strong> (2019-12-07)</dt>
<dd>
- Removed a deprecation notice under PHP 7.4.<br>
</dd>
<dt><strong>v1.81</strong> (2015-12-20)</dt>
<dd>
- Added GetPageWidth() and GetPageHeight().<br>
Expand Down
10 changes: 3 additions & 7 deletions src/Fpdf/makefont/makefont.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/*******************************************************************************
* Utility to generate font definition files *
* *
* Version: 1.3 *
* Date: 2015-11-29 *
* Version: 1.31 *
* Date: 2019-12-07 *
* Author: Olivier PLATHEY *
*******************************************************************************/

Expand Down Expand Up @@ -67,7 +67,7 @@ function GetInfoFromTrueType($file, $embed, $subset, $map)
$ttf = new TTFParser($file);
$ttf->Parse();
}
catch(\Exception $e)
catch(Exception $e)
{
Error($e->getMessage());
}
Expand Down Expand Up @@ -384,10 +384,6 @@ function MakeDefinitionFile($file, $type, $enc, $embed, $subset, $map, $info)
function MakeFont($fontfile, $enc='cp1252', $embed=true, $subset=true)
{
// Generate a font definition file
if(get_magic_quotes_runtime())
@set_magic_quotes_runtime(false);
ini_set('auto_detect_line_endings', '1');

if(!file_exists($fontfile))
Error('Font file not found: '.$fontfile);
$ext = strtolower(substr($fontfile,-3));
Expand Down
19 changes: 5 additions & 14 deletions src/Fpdf/makefont/ttfparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/*******************************************************************************
* Class to parse and subset TrueType fonts *
* *
* Version: 1.1 *
* Date: 2015-11-29 *
* Version: 1.11 *
* Date: 2021-04-18 *
* Author: Olivier PLATHEY *
*******************************************************************************/

Expand Down Expand Up @@ -75,10 +75,10 @@ function ParseOffsetTable()
$tag = $this->Read(4);
$checkSum = $this->Read(4);
$offset = $this->ReadULong();
$length = $this->ReadULong(4);
$length = $this->ReadULong();
$this->tables[$tag] = array('offset'=>$offset, 'length'=>$length, 'checkSum'=>$checkSum);
}
}
}

function ParseHead()
{
Expand Down Expand Up @@ -354,15 +354,7 @@ function ParsePost()

function Subset($chars)
{
/* $chars = array_keys($this->chars);
$this->subsettedChars = $chars;
$this->subsettedGlyphs = array();
for($i=0;$i<$this->numGlyphs;$i++)
{
$this->subsettedGlyphs[] = $i;
$this->glyphs[$i]['ssid'] = $i;
}*/

$this->AddGlyph(0);
$this->subsettedChars = array();
foreach($chars as $char)
Expand Down Expand Up @@ -607,7 +599,6 @@ function BuildFont()
$this->tables[$tag]['offset'] = $offset;
$offset += strlen($this->tables[$tag]['data']);
}
// $this->tables['head']['data'] = substr_replace($this->tables['head']['data'], "\x00\x00\x00\x00", 8, 4);

// Build offset table
$entrySelector = 0;
Expand Down Expand Up @@ -717,7 +708,7 @@ function CheckSum($s)

function Error($msg)
{
throw new \Exception($msg);
throw new Exception($msg);
}
}
?>
94 changes: 94 additions & 0 deletions src/Fpdf/tutorial/CevicheOne-Regular-Licence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Copyright (c) 2011 by LatinoType Limitada ([email protected]),
with Reserved Font Names "Cecivhe" and "Ceviche One"

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
25 changes: 25 additions & 0 deletions src/Fpdf/tutorial/CevicheOne-Regular.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$type = 'TrueType';
$name = 'CevicheOne-Regular';
$desc = array('Ascent'=>806,'Descent'=>-237,'CapHeight'=>425,'Flags'=>32,'FontBBox'=>'[-42 -237 1427 806]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>294);
$up = -75;
$ut = 50;
$cw = array(
chr(0)=>294,chr(1)=>294,chr(2)=>294,chr(3)=>294,chr(4)=>294,chr(5)=>294,chr(6)=>294,chr(7)=>294,chr(8)=>294,chr(9)=>294,chr(10)=>294,chr(11)=>294,chr(12)=>294,chr(13)=>294,chr(14)=>294,chr(15)=>294,chr(16)=>294,chr(17)=>294,chr(18)=>294,chr(19)=>294,chr(20)=>294,chr(21)=>294,
chr(22)=>294,chr(23)=>294,chr(24)=>294,chr(25)=>294,chr(26)=>294,chr(27)=>294,chr(28)=>294,chr(29)=>294,chr(30)=>294,chr(31)=>294,' '=>130,'!'=>254,'"'=>334,'#'=>496,'$'=>469,'%'=>765,'&'=>761,'\''=>148,'('=>268,')'=>269,'*'=>435,'+'=>442,
','=>235,'-'=>339,'.'=>233,'/'=>301,'0'=>512,'1'=>252,'2'=>501,'3'=>471,'4'=>537,'5'=>471,'6'=>501,'7'=>424,'8'=>506,'9'=>502,':'=>292,';'=>299,'<'=>463,'='=>483,'>'=>459,'?'=>453,'@'=>672,'A'=>511,
'B'=>573,'C'=>480,'D'=>541,'E'=>507,'F'=>490,'G'=>515,'H'=>517,'I'=>250,'J'=>270,'K'=>570,'L'=>368,'M'=>620,'N'=>548,'O'=>507,'P'=>540,'Q'=>532,'R'=>552,'S'=>490,'T'=>434,'U'=>527,'V'=>514,'W'=>670,
'X'=>541,'Y'=>497,'Z'=>499,'['=>288,'\\'=>472,']'=>288,'^'=>448,'_'=>350,'`'=>449,'a'=>446,'b'=>454,'c'=>394,'d'=>462,'e'=>404,'f'=>332,'g'=>458,'h'=>446,'i'=>234,'j'=>232,'k'=>457,'l'=>231,'m'=>659,
'n'=>450,'o'=>412,'p'=>436,'q'=>468,'r'=>389,'s'=>394,'t'=>318,'u'=>458,'v'=>421,'w'=>612,'x'=>450,'y'=>429,'z'=>423,'{'=>312,'|'=>231,'}'=>312,'~'=>504,chr(127)=>294,chr(128)=>586,chr(129)=>294,chr(130)=>176,chr(131)=>377,
chr(132)=>361,chr(133)=>761,chr(134)=>422,chr(135)=>425,chr(136)=>448,chr(137)=>1050,chr(138)=>490,chr(139)=>377,chr(140)=>787,chr(141)=>294,chr(142)=>499,chr(143)=>294,chr(144)=>294,chr(145)=>171,chr(146)=>148,chr(147)=>357,chr(148)=>334,chr(149)=>266,chr(150)=>444,chr(151)=>554,chr(152)=>416,chr(153)=>608,
chr(154)=>394,chr(155)=>378,chr(156)=>674,chr(157)=>294,chr(158)=>423,chr(159)=>497,chr(160)=>130,chr(161)=>253,chr(162)=>424,chr(163)=>510,chr(164)=>665,chr(165)=>551,chr(166)=>252,chr(167)=>413,chr(168)=>505,chr(169)=>675,chr(170)=>361,chr(171)=>668,chr(172)=>548,chr(173)=>440,chr(174)=>676,chr(175)=>413,
chr(176)=>278,chr(177)=>438,chr(178)=>328,chr(179)=>318,chr(180)=>449,chr(181)=>463,chr(182)=>535,chr(183)=>234,chr(184)=>535,chr(185)=>176,chr(186)=>322,chr(187)=>669,chr(188)=>761,chr(189)=>710,chr(190)=>904,chr(191)=>452,chr(192)=>511,chr(193)=>511,chr(194)=>514,chr(195)=>511,chr(196)=>511,chr(197)=>511,
chr(198)=>787,chr(199)=>480,chr(200)=>507,chr(201)=>507,chr(202)=>507,chr(203)=>507,chr(204)=>250,chr(205)=>250,chr(206)=>271,chr(207)=>272,chr(208)=>542,chr(209)=>548,chr(210)=>507,chr(211)=>507,chr(212)=>507,chr(213)=>507,chr(214)=>507,chr(215)=>496,chr(216)=>507,chr(217)=>527,chr(218)=>527,chr(219)=>526,
chr(220)=>527,chr(221)=>497,chr(222)=>522,chr(223)=>457,chr(224)=>446,chr(225)=>446,chr(226)=>446,chr(227)=>446,chr(228)=>446,chr(229)=>446,chr(230)=>635,chr(231)=>394,chr(232)=>404,chr(233)=>404,chr(234)=>412,chr(235)=>401,chr(236)=>235,chr(237)=>235,chr(238)=>256,chr(239)=>249,chr(240)=>475,chr(241)=>450,
chr(242)=>412,chr(243)=>412,chr(244)=>412,chr(245)=>413,chr(246)=>412,chr(247)=>444,chr(248)=>412,chr(249)=>458,chr(250)=>458,chr(251)=>458,chr(252)=>458,chr(253)=>429,chr(254)=>452,chr(255)=>429);
$enc = 'cp1252';
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
$file = 'CevicheOne-Regular.z';
$originalsize = 25916;
$subsetted = true;
?>
Binary file added src/Fpdf/tutorial/CevicheOne-Regular.ttf
Binary file not shown.
Binary file added src/Fpdf/tutorial/CevicheOne-Regular.z
Binary file not shown.
Loading

0 comments on commit 413b570

Please sign in to comment.