Giter Site home page Giter Site logo

tcpdf's Introduction

TCPDF

PHP PDF Library

Donate via PayPal Please consider supporting this project by making a donation via PayPal

NOTE

A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode.

Description

PHP library for generating PDF documents on-the-fly.

Main Features:

  • no external libraries are required for the basic functions;
  • all standard page formats, custom page formats, custom margins and units of measure;
  • UTF-8 Unicode and Right-To-Left languages;
  • TrueTypeUnicode, OpenTypeUnicode v1, TrueType, OpenType v1, Type1 and CID-0 fonts;
  • font subsetting;
  • methods to publish some XHTML + CSS code, Javascript and Forms;
  • images, graphic (geometric figures) and transformation methods;
  • supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/script/formats.php)
  • 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  • JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  • automatic page header and footer management;
  • document encryption up to 256 bit and digital signature certifications;
  • transactions to UNDO commands;
  • PDF annotations, including links, text and file attachments;
  • text rendering modes (fill, stroke and clipping);
  • multiple columns mode;
  • no-write page regions;
  • bookmarks, named destinations and table of content;
  • text hyphenation;
  • text stretching and spacing (tracking);
  • automatic page break, line break and text alignments including justification;
  • automatic page numbering and page groups;
  • move and delete pages;
  • page compression (requires php-zlib extension);
  • XOBject Templates;
  • Layers and object visibility.
  • PDF/A-1b support.

Third party fonts:

This library may include third party font files released with different licenses.

All the PHP files on the fonts directory are subject to the general TCPDF license (GNU-LGPLv3), they do not contain any binary data but just a description of the general properties of a particular font. These files can be also generated on the fly using the font utilities and TCPDF methods.

All the original binary TTF font files have been renamed for compatibility with TCPDF and compressed using the gzcompress PHP function that uses the ZLIB data format (.z files).

The binary files (.z) that begins with the prefix "free" have been extracted from the GNU FreeFont collection (GNU-GPLv3). The binary files (.z) that begins with the prefix "pdfa" have been derived from the GNU FreeFont, so they are subject to the same license. For the details of Copyright, License and other information, please check the files inside the directory fonts/freefont-20120503 Link : http://www.gnu.org/software/freefont/

The binary files (.z) that begins with the prefix "dejavu" have been extracted from the DejaVu fonts 2.33 (Bitstream) collection. For the details of Copyright, License and other information, please check the files inside the directory fonts/dejavu-fonts-ttf-2.33 Link : http://dejavu-fonts.org

The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2). Link : http://projects.arabeyes.org/

ICC profile:

TCPDF includes the sRGB.icc profile from the icc-profiles-free Debian package: https://packages.debian.org/source/stable/icc-profiles-free

Developer(s) Contact

tcpdf's People

Contributors

baptistepillot avatar cedric-anne avatar daeroni avatar defrance avatar dilyanpalauzov avatar dominiqueferet avatar findus23 avatar gemal avatar jakuje avatar jausions avatar jonasnutz avatar leofeyer avatar mvorisek avatar nicolaasuni avatar nicolaasuni-vonage avatar niklasbr avatar paulholden avatar remicollet avatar rvanginneken avatar stchr avatar supervirus avatar tacovandenbroek avatar tanelt avatar thorsten avatar tofandel avatar vincentlanglet avatar wenzhengjiang avatar westhouseit avatar williamdes avatar woytam 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  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

tcpdf's Issues

Merge PDFs

Hi,
It would be awesome if we could merge PDF files (the same way it is possible with FPDI) directly using TCPDF. That would be a great feature.

Thanks.

TCPDF doesn't load http://www.mydomain.com image if domain is https

I've an tinymce editor on my PHP webapp to save "precompiled" content (text/images).

I've saved an old entry with some text and a image link. This is the HTML view of tinymce editor.

<p>This is an image</p>
<img src="http://mywebapp.com/files/image_1.jpg" />

Then a button named "Create PDF and SEND"...create the A4 pdf version of my tinymce content (using TCPDF) and send via email.

All ok when my app was on http. Now we migrated to https and when i generate PDF, image disappear from PDF....i need to manually change (in html view of tinymce editor textarea):

<img src="http://mywebapp.com/files/image_1.jpg" />

to:

<img src="https://mywebapp.com/files/image_1.jpg" />

adding s to src. there is a solution to fix this problem on TCPDF?

In form fields select box option text not wrapping

Hello,

I am using TCPDF for generating form field PDF dynamically. We have long text options (i.e. "Feed water introduced through openings or connection used for relief, water column or water level gauge glass on cast iron boiler") in database and its not wrapping in select box in PDF. Another issue is its adding white space at the end of options text. If you have option like "Option 1" (8 character) then its adding 8 white space.

I have tried same code from this example https://tcpdf.org/examples/example_054/ and just added more text to select box options and its not working too. Please find attached PDF and see "Select2" for what I am talking about.
example_054.pdf

Waiting for solution because due to this we are stuck.

Thanks in advance.

TCPDF full page table width

Hi,
is there anyway that i can fit the table to the page (A4), it's a dynamic table
the table picture
none of below worked

<table width="100%">
<table style="width:100%;">
<table class="w100">
<link rel="stylesheet" href="style.css" />

my code:

$content = '<table>
    <thead>
        <tr>
            <th class="bg-dark text-white" align="center">#</th>
            <th align="center" class="bg-dark text-white">Code</th>
            <th align="left" class="bg-dark text-white">Description</th>
            <th align="center" class="bg-dark text-white">Item Type</th>
        </tr>
    </thead>
    <tbody>
        <tr style="background-color: #f2f2f2;">
            <td align="center">1</td>
            <td align="center">1001</td>
            <td align="left">Pofak</td>
            <td align="center">Fixed Price</td>
        </tr>
        <tr>
            <td align="center">2</td>
            <td align="center">1002</td>
            <td align="left">Ice</td>
            <td align="center">Weight</td>
        </tr>
        <tr style="background-color: #f2f2f2;">
            <td align="center">3</td>
            <td align="center">1003</td>
            <td align="left">Minoo</td>
            <td align="center">Fixed Price</td>
        </tr>
    </tbody>
</table>';
$newContent = '
    <style type="text/css">
    table{width:100%;}
    table, table td, table th{
        border-collapse: collapse;
        border: solid 1px #ababab;
    }
    .text-dark, table td{
        color: #343a40;
    }
    .text-white{
        color: #ffffff;
    }
    table td,
    table th {
        font-size: 11px;
        padding: 3px;
        line-height: 1.2;
        font-family:arial;
    }

    .bg-dark {
        background-color: #343a40;
    }
    .bg-secondary {
        background-color: #6c757d;
    }
    .bg-white {
        background-color: #ffffff;
    }
    .text-left {
        text-align: left;
    }
    .text-right {
        text-align: right;
    }
    .text-center {
        text-align: center;
    }
    </style>
    ';
    $newContent .= '<page>'.$content.'</page>';

    try {
        $html2pdf = new Html2Pdf('P', 'A4', 'en', true, 'UTF-8', 5);
        $html2pdf->pdf->SetDisplayMode('real');
        $html2pdf->writeHTML($newContent);
        $PDFName = "ItemLists_".date('Y.m.d_H.i.s').".pdf";
        $html2pdf->output($PDFName, 'I');
    } catch (Html2PdfException $x) {
        $html2pdf->clean();

        $formatter = new ExceptionFormatter($x);
        echo $formatter->getHtmlMessage();
    }

Thanks :)

Width and X position of scaled MultiCells

I noticed an odd behavior of MultiCells in transformations (especially scaling). It doesn't occur in Cells, but I suppose it might occur as well in other elements that are modified to fit the page dimensions.
Within a down-scaled part of the document, positions such as (230, 50) are still visible on a standard A4 page, because the dimensions get scaled down according to the transformation. However, TCPDF seems to force elements into the 210mm width of an A4 page, without scaling this page dimension or the margins. I modified example_013 from the documentation to illustrate my case, the code can be seen here. The resulting PDF is
example_013.pdf

Tested with TCPDF 6.2.11, 6.2.26 and master branch at 9fde7bb (6.3.2).

Has anyone else encountered a similar behaviour with TCPDF and has an idea how to solve this? I have debugged this for some time now and suspect that it has something to do with the position and width calculations inside MultiCell, but I'm not sure how exactly this can be fixed.

Error temp clean up

Error not present in 6.2.22

Version: 6.3.5
msg:unlink(/tmp/__tcpdf_5187212244c54f1c07d644b6a8c2f794_imgmask_plain_d301f5c75467d1c6dbdd7862526a6f3f): No such file or directory |

error occurs -> tcpdf.php | ln:7791

image is called in header function:

public function Header() {
$image_file = '../assets/images/logos/logo.png';
$this->Image($image_file, 15, 8, '', 7, '', '', 'T', false, 300, 'L', false, false, 0, false, false, false);
}

Illegal string offset 'position'

Hi everybody!

I'm getting the following error:

Warning: Illegal string offset 'position' in /var/www/public/Packages/Libraries/tecnickcom/tcpdf/tcpdf.php line 15588

Using this code:

<div style="width:62mm; height:20mm; position:relative; overflow: hidden;">
         <barcode dimension="2D" type="DATAMATRIX" value="{article.number}" label="label" style="position: absolute; top: 7mm; left: 1mm; width:13mm; height:13mm; color: #000000; font-size: 4mm;"></barcode>
         <div style="position:absolute; left:1mm; top:1mm; width:40mm; height:18mm; font-size:5mm; font-weight:bold;">
             {article.number}
         </div>
         <div style="position:absolute; left:15mm; top:7mm; width:46mm; height:13mm; font-size:3mm;">
             {article.description}
         </div>
     </div>

$html2pdf = new Html2Pdf("L", [62, 21], "de", true, "UTF-8", [0, 0, 0, 0]);

Does anyone have any idea where this error can come from? Thank you very much!

How to set qr inside cell

i have a table, the rows table is dynamic, then i need set the qr code in a cell, but not work because the position paramters is absolute

TCPDF not showing same signature name which send in function.

I am using TCPDF for signature. I have issue relate signature name. I send sign1 name in addEmptySignatureAppearance() but the name display in pdf like: /T (รพรฟ s i g n 1 [ 0 0 2 ])

In code:

$pdf->addEmptySignatureAppearance(20, 27, 175, 70, 30, 'sign1');
$pdf->addEmptySignatureAppearance(20, 110, 175, 70, 30, 'sign2');

The pdf view as a text document:

/T (รพรฟ s i g n 1   [ 0 0 1 ])
/T (รพรฟ s i g n 2   [ 0 0 2 ])

but I want result like :

/T (sign1)
/T (sign2)

Dose any way to do it.

Not working in PHP7.3

We try to use TCPDF for HTML to PDF download from Here and check all examples in "examples" directory but got error as The each() function is deprecated TCPDF

unlink() No such file or directory warning on 6.3.2

hello after updating to tcpdf 6.3.2 i get warning on method tcpdf.php line 7801 with message " unlink(.......\temp/__tcpdf_393737b5201efd77eec80f86fca55b63_imgmask_alpha_af7077161af0ed4509f4b792149d0a9a)" No such file or directory

after commenting out that line, the issue gone....
i hope theres a better fix for this

border looping table not show on all page

hallo i have an issue in looping table with border not show on all page(use function writehtml) , if i have 6 page, 1 or 2 of them not show border correctly, can u explain why? thanks

Case of incorrect 1D barcode (CODE11)

I'm using a library to generate CODE11 barcodes. I have one case where the barcode is generated incorrectly. This case is a series of numbers: 218980415346
The generated barcode has the wrong last STOP character.
The barcode is generated:

$style = array(
		'position' => '',
		'align' => 'C',
		'stretch' => false,
		'fitwidth' => true,
		'cellfitalign' => 'C',
		'border' => true,
		'hpadding' => 'auto',
		'vpadding' => 'auto',
		'fgcolor' => array(0,0,0),
		'bgcolor' => false, //array(255,255,255),
		'text' => false,
		'font' => 'dejavusans',
		'fontsize' => 12,
		'stretchtext' => 4
	);

$pdf->write1DBarcode('218980415346', 'CODE11', '', '', '', 25, 0.6, $style, 'N');

Hindi Language Support Issue

TCPDF not supporting Hindi Language.i tried with different fonts like Devnagari, freesans, freeserif. Hindi language is rendering but there issue are coming like
เคธเฅเคตเคฟเคงเคพ is rendered as เคธเฅเคตเคงเคฟเคพ
lots of similar kind of issues are coming while rendering.
please suggest me if any solution or any fix

Transaction with writeHTML will not reset

$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 15, PDF_MARGIN_RIGHT, true);
    $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM + 5);
    // add a page
    $pdf->AddPage();

    $pdf->setAutoPageBreak(false);
    //$pdf->startTransaction(); // Moved

    $tbl = <<<EOD
    <div id="Container">
    <table border="1" cellpadding="2" cellspacing="2" align="center">
    <tr><td colspan="3">demo</td></tr>
     <tr nobr="true">
      <th colspan="3">NON-BREAKING ROWS</th>
     </tr>
     <tr nobr="true">
      <td>ROW 1<br />COLUMN 1</td>
      <td>ROW 1<br />COLUMN 2</td>
      <td>ROW 1<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 2<br />COLUMN 1</td>
      <td>ROW 2<br />COLUMN 2</td>
      <td>ROW 2<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 3<br />COLUMN 1</td>
      <td>ROW 3<br />COLUMN 2</td>
      <td>ROW 3<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 4<br />COLUMN 1</td>
      <td>ROW 4<br />COLUMN 2</td>
      <td>ROW 4<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 5<br />COLUMN 1</td>
      <td>ROW 5<br />COLUMN 2</td>
      <td>ROW 5<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 6<br />COLUMN 1</td>
      <td>ROW 6<br />COLUMN 2</td>
      <td>ROW 6<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 7<br />COLUMN 1</td>
      <td>ROW 7<br />COLUMN 2</td>
      <td>ROW 7<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 8<br />COLUMN 1</td>
      <td>ROW 8<br />COLUMN 2</td>
      <td>ROW 8<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 9<br />COLUMN 1</td>
      <td>ROW 9<br />COLUMN 2</td>
      <td>ROW 9<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 10<br />COLUMN 1</td>
      <td>ROW 10<br />COLUMN 2</td>
      <td>ROW 10<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 11<br />COLUMN 1</td>
      <td>ROW 11<br />COLUMN 2</td>
      <td>ROW 11<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 12<br />COLUMN 1</td>
      <td>ROW 12<br />COLUMN 2</td>
      <td>ROW 12<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 13<br />COLUMN 1</td>
      <td>ROW 13<br />COLUMN 2</td>
      <td>ROW 13<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 14<br />COLUMN 1</td>
      <td>ROW 14<br />COLUMN 2</td>
      <td>ROW 14<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 15<br />COLUMN 1</td>
      <td>ROW 15<br />COLUMN 2</td>
      <td>ROW 15<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 16<br />COLUMN 1</td>
      <td>ROW 16<br />COLUMN 2</td>
      <td>ROW 16<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 17<br />COLUMN 1</td>
      <td>ROW 17<br />COLUMN 2</td>
      <td>ROW 17<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 18<br />COLUMN 1</td>
      <td>ROW 18<br />COLUMN 2</td>
      <td>ROW 18<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 19<br />COLUMN 1</td>
      <td>ROW 19<br />COLUMN 2</td>
      <td>ROW 19<br />COLUMN 3</td>
     </tr>
     <tr nobr="true">
      <td>ROW 20<br />COLUMN 1</td>
      <td>ROW 20<br />COLUMN 2</td>
      <td>ROW 20<br />COLUMN 3</td>
     </tr>
    </table>
    </div>
    EOD;

    $html = new Document($tbl);
    $single = $html->find('#Container');
    $positionY = $pdf->GetY();
    $positionX = $pdf->GetX();
    //$response->getBody()->write("Container:" . var_export($single, true) . "\n\n");
    if ($single) {

        $table = $single[0]->find('table')[0];
        $rows = $table->find('tr');
        //$response->getBody()->write("rows:" . var_export($rows, true) . "\n\n");
        //$rows = $rows[0]->getElementsByTagName('tr');
        //$response->getBody()->write("rows2:" . var_export($rows, true) . "\n\n");

        if ($rows) {
            $positionY = $pdf->GetY();
            $positionX = $pdf->GetX();
            $pdf->startTransaction(); // Start transaction only because we may need it
            // Header for html, this starts the html and can optionally insert the header row as the first row on every new page.
            $html_header = '<tr nobr="true"><td>Spalte 1</td><td>Splate 2</td><td>Spalte 3</td></tr>';
            $html_buffer = '<table border="1" cellpadding="2" cellspacing="2" align="center">' . $html_header;
            for ($i = 0; $i < count($rows); $i++) {

                $pdf->writeHTML($html_buffer . $rows[$i]->html() . '</table>', true, false, false, false, '');

                if ($pdf->getY() < ($pdf->getPageHeight())) { // Note the less-than operator
                    // We might be able to add some more text, so undo that
                    $pdf->rollbackTransaction(true);
                    $pdf->SetY($positionY);
                    //$pdf->SetX($positionX + $i);
                    // And store the html
                    $html_buffer .= $rows[$i]->html();
                } else {
                    // $response->getBody()->write("AddLine:" . $pdf->getY() . "<" . ($pdf->getPageHeight() - ((PDF_MARGIN_BOTTOM + PDF_MARGIN_TOP) * 2)) . "\n\n");
                    // $response->getBody()->write($html_buffer . '</table>' . "\n\n");
                    // We exceeded our limit
                    $pdf->rollbackTransaction(true);
                    $pdf->SetY($positionY);
                    //$pdf->SetX($positionX + $i);
                    // Write last known good table
                    $pdf->writeHTML($html_buffer . '</table>', true, false, false, false, '');
                    // Add a new page
                    $pdf->AddPage();

                    // Reset html buffer
                    $html_buffer = '<table border="1" cellpadding="2" cellspacing="2" align="center">' . $html_header;
                    // Add line we couldn't fit on last page to html buffer
                    $html_buffer .= $rows[$i]->html();
                }
            }
            // There is still information in our buffer and it fits on a single page
            $pdf->writeHTML($html_buffer . '</table>', true, false, false, false, '');
            // Final commit
            $pdf->commitTransaction();
        }
    }

    $pdf->setAutoPageBreak(true, 30);

will allways write the table to the same position, what i expect. But the problem is that the document is not really reset the last transaction. The cell text is multiple times written.

No i get what i want, but with more added text as i would have.

The best view is to show the problem is to set the X position for each loop and see that the text comes multiple times and would end in an not clear font.

Ref:
https://stackoverflow.com/questions/11221174/tcpdf-split-html-table-on-multiple-pages
https://stackoverflow.com/questions/36306193/tcpdf-rollbacktransaction-on-a-writehtmlcell

Requires: composer require imangazaliev/didom

Footer Rendering after body

How can i call SetAutoPageBreak() in the Footer method?

The problem i have is that i can have a dynamic height to the footer and i can only obtain that height in the Footer() method. In this case i can't set the AutoPageBreak because the footer is called after the body method.

Is there any workaround this?
Thank you

"TCPDF_PARSER ERROR: Unable to find startxref"

The problem

I'm using https://pdfparser.org/ that is based in TCPDF. It works fine with several PDFs but when I try some PDFs it gives me this error. For example with this PDF: https://www.dropbox.com/s/953syp2n16m6gir/p6.pdf?dl=0

Error:

Fatal error: Uncaught Exception: TCPDF_PARSER ERROR: Unable to find startxref in /Applications/MAMP/htdocs/msci/pdfparser-master/vendor/tecnickcom/tcpdf/tcpdf_parser.php:807 Stack trace: #0 /Applications/MAMP/htdocs/msci/pdfparser-master/vendor/tecnickcom/tcpdf/tcpdf_parser.php(173): TCPDF_PARSER->Error('Unable to find ...') #1 /Applications/MAMP/htdocs/msci/pdfparser-master/vendor/tecnickcom/tcpdf/tcpdf_parser.php(117): TCPDF_PARSER->getXrefData() #2 /Applications/MAMP/htdocs/msci/pdfparser-master/src/Smalot/PdfParser/Parser.php(93): TCPDF_PARSER->__construct('%PDF-1.4\n%\xAA\xAB\xAC\xAD\n...') #3 /Applications/MAMP/htdocs/msci/pdfparser-master/src/Smalot/PdfParser/Parser.php(81): Smalot\PdfParser\Parser->parseContent('%PDF-1.4\n%\xAA\xAB\xAC\xAD\n...') #4 /Applications/MAMP/htdocs/msci/pdfparser-master/prueba.php(8): Smalot\PdfParser\Parser->parseFile('p6.pdf') #5 {main} thrown in /Applications/MAMP/htdocs/msci/pdfparser-master/vendor/tecnickcom/tcpdf/tcpdf_parser.php on line 807

Embed vector-based ImageEps vs Image

When using TCPDF to generate a PDF, the same image in the PDF file is used multiple times and only the same copy is copied. The size of the generated PDF file does not change much.And like SVG, AI, EPS, the same reference multiple times, the file size increases with each additional reference. Is this a bug or is it not fixed for other reasons?

for($i = 0; $i < 9; $i++){
$pdf->Image('images/image_demo.jpg', 15, 140, 75, 113, 'JPG', 'http://www.tcpdf.org', '', true, 150, '', false, false, 1, false, false, false);
}//101KB
Compared
for($i = 0; $i < 99; $i++){
$pdf->Image('images/image_demo.jpg', 15, 140, 75, 113, 'JPG', 'http://www.tcpdf.org', '', true, 150, '', false, false, 1, false, false, false);
}//124KB
The volume of the generated PDF file does not change much.
for($i = 0; $i < 9; $i++){
$pdf->ImageSVG($file='images/tux.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
}//258KB
Compared
for($i = 0; $i < 99; $i++){
$pdf->ImageSVG($file='images/tux.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
}//2599KB!!!

The volume of the generated PDF file has been increased several times.
@NiklasBr If SVG, EPS file is a little larger, the increase of PDF file is more obvious.

Rect goes to new page

Hi,
I use Rect function to create rectangles on page. I setup all margins to 0 and disabled Footer creation, but the last rectangle goes to new page instead remaining on same page.

Before adding a naw page I setup margins like this.

$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(false);
$tcpdf->SetMargins(0, 0, 0, true);
$tcpdf->setCellPaddings(0,0,0,0);
$tcpdf->setFooterMargin(0);
$tcpdf->setHeaderMargin(0);
$tcpdf->SetAutoPageBreak(false, 0);

$tcpdf->AddPage();

image

Notice: Trying to access array offset on value of type int

Running example 59 in php 7.4:

php example_059.php

gives me this:

PHP Notice:  Trying to access array offset on value of type int in /home/user/TCPDF/tcpdf.php on line 12385

it seems to happen here:

$pdf->addHTMLTOC(1, 'INDEX', $bookmark_templates, true, 'B', array(128,0,0));

Would be nice if there was a workaround or a fix..

Writehtml table with nobr header not showing on top of page

Hi all,

I am using TCPDF to generate a document with a lot of html tables on it.
Each table has the nobr tag because I want each table to 'stay together' on one page.
Each separate table is outputted using the WriteHTML command.

So roughly, the structure is (sorry for terrible layout, just wanted to keep it short):

Header column
Some cell
Some other cell

$pdf->writeHTML($html_table, true, false, true, false, '');

Header column
Some cell
Some other cell
$pdf->writeHTML($html_table, true, false, true, false, '');`
Header column
Some cell
Some other cell
$pdf->writeHTML($html_table, true, false, true, false, '');`

And so on....

But what is happening is that 'occasionally', not every time, the first table on a page does not have a header...it's just not there. I have done numerous tests, but was not able to understand exactly why this sometimes happens. I have a feeling that it has something to do with the "nobr" kicking in or not, but I have not been able to prove it.

Would any of you have an idea? It seems like a strange bug...

Thanks in advance for your support.

Regards,

Robbie

PHP7.3, A non-numeric value encountered

With latest clone today ...

Severity: Warning
Message: A non-numeric value encountered
Filename: tcpdf/tcpdf.php
Line Number: 5398

Seems $this->textstrokewidth is FALSE, fails in a multiplication.

Setting it to 0 in this case doesn't break anything for me.

GD and ICC profile

I have both GD and Imagick installed in my PHP. In my PDF, I use an image created with Imagick on which I add a CMYK profile for printing (CoatedFOGRA39.icc).

$img->setImageFormat('jpeg');
$img->getImageProfiles('*', null);
$icc_cmyk = file_get_contents('CoatedFOGRA39.icc');
$img->profileImage('icc', $icc_cmyk);
$img->transformImageColorspace(Imagick::COLORSPACE_CMYK);

$pdf->Image('@'.$img, $x, $y);

The resulting PDF generated with TCPDF has bad colors so the profile I give is not used and is replaced by something else or is simply removed.

I tracked this down to the Image() function. If GD is installed, it uses imagecreatetruecolor() and other functions that modify the original image and its data. If I comment out the block starting at if (($info === false) AND function_exists($gdfunction)) { then TCPDF correctly uses imagick and everything is fine because it finds the icc profile and keeps it.

So here are my suggestions to fix this:

  1. Change the order, call imagick before GD (imagick is better at everything so it should benefit everyone, but it is a potential BC break)
  2. Add a parameter to specify which image library to use. Most php image libraries do this these days. Keep this parameter empty by default. Example:
$pdf->setImageLibrary('imagick');

Any ideas?

Multicell() Draws border over previous cell

Copied from tecnickcom/tc-lib-pdf#37

I have this block that creates a set of TCPDF MultiCell()s in a multicolumn pdf.

$TColW0 = 29;
$DColW0 = 37;
$mbh = $pdf->getStringHeight($DColW0, $reqHeader['partPackingInfo'], false, true, '', 1);
$pdf->MultiCell($TColW0, $mbh, 'Packaging Details:', 1, 'R', '', 0, '', '', true, 0, false, false, '', 'M', false);
$pdf->MultiCell($DColW0, $mbh, $reqHeader['partPackingInfo'], 1, 'L', '', 1, '', '', true, 0, false, false, '', 'M', false);
  • The first line uses TCPDF's native function to get the height of the multi line string and sets the $mbh variable to later set both cells to the same height.
  • The $DColW0 and $TColW0 variables are predetermined and set column widths.

My problem is the result looks like this,

TCPDF Multiline Issue

I tried using the title column's width in the x value of the data cell, but that just shifts the content out of the column.

The content looks to be in the right place the border for the data cell is just drawn in the wrong spot. Is there a setting or something I'm missing when it comes to MultiCell() borders? Any help/suggestions much appreciated.


Updating the block to make use of SetX

$TColW0 = 29;
$DColW0 = 37;
$mbh = $pdf->getStringHeight($DColW0, $reqHeader['partPackingInfo'], false, true, '', 1);
$pdf->MultiCell($TColW0, $mbh, 'Packaging Details:', 1, 'R', '', 0, '', '', true, 0, false, false, '', 'M', false);
$pdf->SetX($TColW0);
$pdf->MultiCell($DColW0, $mbh, $reqHeader['partPackingInfo'], 1, 'L', '', 1, '', '', true, 0, false, false, '', 'M', false);

Shifts the content independent of where the border is drawn.
SETX Example


Using the x specification inside of MultiCell()

$TColW0 = 29;
$DColW0 = 37;
$mbh = $pdf->getStringHeight($DColW0, $reqHeader['partPackingInfo'], false, true, '', 1);
$pdf->MultiCell($TColW0, $mbh, 'Packaging Details:', 1, 'R', '', 0, '', '', true, 0, false, false, '', 'M', false);
$pdf->MultiCell($DColW0, $mbh, $reqHeader['partPackingInfo'], 1, 'L', '', 1, $TColW0, '', true, 0, false, false, '', 'M', false);

enter image description here

Again content shifts, border is drawn over previous cell.

MultiCell() Documentation.


Result with cell fill turned on.

$TColW0 = 29;
$DColW0 = 37;
$mbh = $pdf->getStringHeight($DColW0, $reqHeader['partPackingInfo'], false, true, '', 1);
$pdf->MultiCell($TColW0, $mbh, 'Packaging Details:', 1, 'R', 1, 0, '', '', true, 0, false, false, '', 'M', false);
$pdf->MultiCell($DColW0, $mbh, $reqHeader['partPackingInfo'], 1, 'L', 1, 1, '', '', true, 0, false, false, '', 'M', false);

FillExample

Turning fill on paints over all previously drawn borders for that row with the exception of the border for the last cell. The content of both cells is still in the expected position, the border is drawn to the expected size, but is drawn in the wrong position.

Footer breaks transformation

If we use transforms and a page is ending inside a transformed part, the transformation is applied to the footer, but seems to be stopped afterwards, so it doesn't continue on the next page.

Simplified code example:

// Start transform
$pdf->StartTransform();
$pdf->Rotate(15);

// Output some multi-line text that causes a page break.
$pdf->writeHTMLCell(0, 0, '', 260, $html, 0, 1, 0, true, '', true); // <-- Page break within here

// Stop transform
$pdf->StopTransform();

See the slightly changed version of example001.php here. This results in a PDF like
example_001.pdf. You see that there is a rotated text at the end of page 1. The footer is rotated along with the text (but shouldn't be, because it has no own rotation). The second part of the text on page 2 instead is not rotated at all (but should be, because it's inside the transformation).

Is there any way to save the whole transformation stack before printing the footer and restoring it afterwards?

Replace core PDF font

Hi,

I'm trying to replace the core font Times New Roman, some Polish glyphs are missing in the current version of the font.

Is it perhaps possible and if so, how ?

TCPDF ERROR: XObject "Template" doesn't exist

Hello there Nicola.

I've used your software for some months and I had no trouble at all.

However, I've tried installing a project on my friend's machine (PHP 5.5 on Windows) and I can't output PDF because I keep getting this error message:

XObject "Template" doesn't exist

I have the exact same code on a Linux machine (but running on PHP 5.4) and this problem does not occur.

Do have any idea as to what could be happening?

Oh yes I forgot to mention. I'm using version 6.0.057 on Linux (PHP 5.4 - no errors here). I've tried the same version on Windows (PHP 5.5) and I've also trie dthe latest version (6.0.091) and I've had errors in both versions.

Thank you for having written such a useful piece of code and thank you for helping out!

Absolute Image dont show anymore

after 6.2.23 the "Fix support for image URLs" i cant use image with full path
Because tcpdf try to fix adding webserver path

I think is better tcpdf dont do anything like that... please revert this "fix"

Updating to PHP 7.3 issues some Warnings

I just tried to update my site to PHP 7.3 using the latest TCPDF version (6.3.2).
When I try to create a PDF, I get a lot of Warnings (some of them more than once)

Warning: Invalid argument supplied for foreach() in /vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php on line 1842
Warning: array_map(): Expected parameter 2 to be an array, bool given in /vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php on line 2002
Warning: array_map(): Expected parameter 2 to be an array, null given in /vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php on line 1781
Warning: array_merge(): Expected parameter 1 to be an array, null given in /vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php on line 2010
Warning: array_merge(): Expected parameter 2 to be an array, null given in /vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php on line 2010
Warning: count(): Parameter must be an array or an object that implements Countable in /vendor/tecnickcom/tcpdf/tcpdf.php on line 6345
Warning: max(): Array must contain at least one element in /vendor/tecnickcom/tcpdf/tcpdf.php on line 6341

Is this something I am doing wrong or are there still some issues with PHP 7.3?
All errors occur when I call the method $tcpdf->GetStringWidth().

Also I noticed, when using a non-default font, TCPDF deletes all images that have been used in $tcpdf->Image().
I had this line in the PDF: $pdf->SetFont('freesans', '', 8);. After removing it, the images were not deleted anymore.

Thank you for your help!

Duplicated attachment

Duplicated attachment are created by invoking annotation function (see attached screenshot). One of the attachments is not really valid (i.e. cannot be opened by double click).

I've traced it into _putEmbeddedFiles but cannot see any duplicated operation. So probably the stream data is not completely compatible with PDF reference?

$this->tcpdf->annotation(0, 0, 0, 0, 'attachment', ['Subtype' => 'FileAttachment', 'FS' => $attachment]);

Screen Shot 2020-04-28 at 9 39 13 AM

TCPDF 6.2.22 and later breaks multi usage of the same image

As in subject. All versions prior to 6.2.21 are not affected.
From 6.2.22 when you use the same image many times in your pdf only first appearance is supported properly. All following links to the same image are not visible/broken.
In my opinion code from TCPDF::_destroy() should not always delete images stored in cache located at K_PATH_CACHE setting. If you need more info please let me know.

Related to Dolibarr/dolibarr#11651

image files are deleted after pdf has been rendered

hello,

we have a serious issue since the update to version 6.3.0. we have two static images that we include in the header. when the pdf is rendered they are deleted from the filesystem. so every new pdf does not have these files anymore. i tracked this down to this commit: b41a5ca

the images are added in this way:

$this->resourceDirectory = getcwd() . '/data/content/';
$this->Image($this->resourceDirectory . 'image.png', 371, 60, 164, 60, '', '', 'T');

and then in _destroy() they are deleted from the filesystem. how can we avoid the deletion of these files?

TCPDF error when modifying the font size with a transaction

Hello,
i'm getting

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\WEBSERVER???\inc\tcpdf\include\tcpdf_fonts.php on line 2010
TCPDF ERROR: Wrong page number on setPage() function:

When using this code:

	$textFontSize = 12;
	$cardWidth = 100;

	while(true) {
		$pdf->SetFont('helvetica', 'R', $textFontSize);
		
		// $pdf->SetFontSize($textFontSize);
		$pdf->startTransaction();
		// $pdf->SetFontSize($textFontSize);


		$pdf->SetTextColor(255, 0, 0);
		$pdf->MultiCell($cardWidth * 0.95, 0, "test", 0, 'L', false, 0);
		$pdf->Ln();

		$pdf->SetTextColor(255, 125, 0);
		$pdf->MultiCell($cardWidth * 0.95, 0, "test", 0, 'L', false, 0);
		$pdf->Ln();

		$pdf->SetTextColor(0, 125, 0);
		$pdf->MultiCell($cardWidth * 0.95, 0, "test", 0, 'L', false, 0);
		$pdf->Ln();

		$pdf->SetTextColor(0, 0, 0);
		$pdf->MultiCell($cardWidth * 0.95, 0, "test", 0, 'L', false, 0);
		$pdf->Ln();


		if($textFontSize >= 12) {
			$textFontSize-= .25;
			$pdf = $pdf->rollbackTransaction();
		} else {
			$pdf->commitTransaction();
			break;
		}
	}

I changed it a bit to make it a nice case to test.
Basically what I try to achieve is to decrease the font size while the text doesn't fit inside a box specified.
But I always get the error but only after a rollback.

Digital signature

Getting this error while trying to run Example 52

Warning: openssl_pkcs7_sign(): error getting private key in C:\xampp\htdocs\halil2\TCPDF\tcpdf.php on line 7616

Notice: Undefined offset: 1 in C:\xampp\htdocs\halil2\TCPDF\tcpdf.php on line 7626
TCPDF ERROR: Some data has already been output, can't send PDF file

$maxecl is undefined

Just noticed it while looking at the files (wanted to report it in case the breaks something for someone)

The variable $maxecl used in line 754 is only set a few lines afterwards:

protected function getErrorCorrectionLevel($ecl, $numcw) {
// check for automatic levels
if (($ecl < 0) OR ($ecl > 8)) {
if ($numcw < 41) {
$ecl = 2;
} elseif ($numcw < 161) {
$ecl = 3;
} elseif ($numcw < 321) {
$ecl = 4;
} elseif ($numcw < 864) {
$ecl = 5;
} else {
$ecl = $maxecl;
}
}
// get maximum correction level
$maxecl = 8; // starting error level
$maxerrsize = (928 - $numcw); // available codewords for error
while ($maxecl > 0) {

Bug in firefox

Bug in firefox
Image background not showing in mozilla firefox.
When using google chrome showing background perfectly

Problem when changing font size

Hello,

I tried to upgrade TCPDF from 5.9.179 to 6.0.091 and everything worked fine except in situations where the function SetFont is called.

In some cases, when changing only the font size and / or the style (bold or not), the text did not get displayed.

Short example

$font = 'courier';

$this->SetFont($font, '', 10, '', false);
$this->SetTextColorArray(array(0, 0, 0));
$this->MultiCell(120, 5, 'Test 1', 0, 'L', false, 1, null, null, false, 0, false, true, 5, 'M', true);

$this->SetFont($font, '', 10, '', false);
$this->SetTextColorArray(array(0, 0, 0));
$this->MultiCell(120, 5, 'Test 1', 0, 'L', false, 1, null, null, false, 0, false, true, 5, 'M', true);

The string is only displayed once.

Usage of rollbackTransaction() removes all files from cache including previously copied images

The usage of startTransaction()/rollbackTransaction() is a recommended way to figuring out the precise height of the element before actual rendering. But it has this side effect, that it removes all the data from cache directory, including the copied images. It is well visible with header images if they are resized while printing.

The issue can be reproduced with the following code (based on example 047):
https://gist.github.com/Jakuje/d88c837f6520416964926fac5187ccbf

The first image is visible, but the second one is not. This worked fine with some old version of TCPDF (before the image file caching was introduced?), but does not work now.

I spent some time figuring out where the issue lies and it turns out that it is a combination of several aspects:

  • the rollbackTransaction() needs to be called with self argument
  • the image needs to be resized
  • ...

What is going on here is that the image is copied to the tmp directory in the first object, which is cloned, the rollbackTransaction() calls _destroy(true, true) with correct arguments to preserve this information. But just few lines below, it is called again, this time as _destroy(true) from destructor, which leads to the erasing of the tmp directory.

This was bothering me for quite some time and I believe the correct fix will be to have a boolean property which should be set in _destroy() to prevent the other call to _destroy() in this case. More about the proposed solution will come soon in pull request.

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.