tecnickcom / tcpdf Goto Github PK
View Code? Open in Web Editor NEWOfficial clone of PHP library to generate PDF documents and barcodes
Home Page: https://tcpdf.org
License: Other
Official clone of PHP library to generate PDF documents and barcodes
Home Page: https://tcpdf.org
License: Other
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!
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
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.
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.
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?
line 12387
if ((string)$page && (((string)$page)[0] == '*')) {
$page = intval(substr($page, 1));
// this page number will not be changed when moving/add/deleting pages
$fixed = true;
}
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
I noticed an odd behavior of MultiCell
s in transformations (especially scaling). It doesn't occur in Cell
s, 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.
Bug in firefox
Image background not showing in mozilla firefox.
When using google chrome showing background perfectly
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.
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?
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();
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..
nothing in dev docs
website full of crap : https://tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/
is there an online clean documentation ?
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?
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!
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:
rollbackTransaction()
needs to be called with self
argumentWhat 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.
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:
TCPDF/include/barcodes/pdf417.php
Lines 742 to 760 in 05731a1
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]);
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
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
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);
}
Hello tcpdf,
is there any plan to add LTV support in TCPDP signs ?
refs:
Thanks,
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.
I'm use PHP 7.2.5 and after update TCPDF to 6.3.4, not rendering images with base64
images with filepath render OK.
on v6.2.13 rendering OK.
HTML example in text that not rendering base64
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 |
Header column |
---|
Some cell |
Some other cell |
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
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
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.
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!
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 ?
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:
$pdf->setImageLibrary('imagick');
Any ideas?
$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
Document is corrupted when viewing and downloading the file.
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.
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
Hi
We are using ->setDestination() to create named links, then adding bookmarks to the relevant pages. This has been working for years but broke in version 6.3. Verified by downgrading to 6.2.26 which works.
The changelog at https://github.com/tecnickcom/TCPDF/blob/master/CHANGELOG.TXT only goes up to 6.2.25 so I can't really see what has changed.
Please advise, many thanks.
after i switch to 7.3 i have this warning.
couple minutes before posting here i updated TCPDF but error still showing
custom script implemented in wordpress
this warning don't break anything and pdf is created without error
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.
When I run my tests with PHP 7.4 I get the following error:
https://travis-ci.org/foodcoopshop/foodcoopshop/jobs/632751893
Line 1574
Warning (2): chr() expects parameter 1 to be int, string given in [/home/travis/build/foodcoopshop/foodcoopshop/vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php, line 1671]
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
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
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');
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 :)
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);
$mbh
variable to later set both cells to the same height.$DColW0
and $TColW0
variables are predetermined and set column widths.My problem is the result looks like this,
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.
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);
Again content shifts, border is drawn over previous cell.
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);
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.
If $border_style uses index 'all' but the value is empty this gives a Notice: Trying to access array offset on value of type int.
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
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"
I wan't to use Vietnamese in the header, Please support me.
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.