hanneskod / libmergepdf Goto Github PK
View Code? Open in Web Editor NEWPHP library for merging multiple PDFs
PHP library for merging multiple PDFs
When I try to merge PDFs with the following code I get the error Notice: Uninitialized string offset: 548
$merger = new Merger(new TcpdiDriver());
$merger->addIterator([new File('354025a5-original.pdf', true), new File('another.pdf', true)]);
$mergedPdf = $merger->merge();
This happens when trying to merge the attached PDF File
354025a5-original.pdf
More stack:
Notice: Uninitialized string offset: 548
--
in tcpdi_parser.php line 711
at tcpdi_parser->getRawObject(548, '/NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>')in tcpdi_parser.php line 916
at tcpdi_parser->getDictValue(559, '/InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>')in tcpdi_parser.php line 798
at tcpdi_parser->getRawObject(9, '/InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>')in tcpdi_parser.php line 916
at tcpdi_parser->getDictValue(848, '/BleedBox[ 0 0 841.89 595.276]/Resources<</ColorSpace<</CS0 8 0 R >>/XObject<</Im0 10 0 R >>/ExtGState<</GS0 9 0 R >>/ProcSet[/PDF/ImageC/ImageI]>>/MediaBox[ 0 0 841.89 595.276]/TrimBox[ 0 0 841.89 595.276]/Type/Page/Parent 3 0 R /Contents 7 0 R /CropBox[ 0 0 841.89 595.276]/PieceInfo<</InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>>>')in tcpdi_parser.php line 798
at tcpdi_parser->getRawObject(285, '/BleedBox[ 0 0 841.89 595.276]/Resources<</ColorSpace<</CS0 8 0 R >>/XObject<</Im0 10 0 R >>/ExtGState<</GS0 9 0 R >>/ProcSet[/PDF/ImageC/ImageI]>>/MediaBox[ 0 0 841.89 595.276]/TrimBox[ 0 0 841.89 595.276]/Type/Page/Parent 3 0 R /Contents 7 0 R /CropBox[ 0 0 841.89 595.276]/PieceInfo<</InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>>>')in tcpdi_parser.php line 916
...
Even more stack available if necessary.
How can I challenge this problem? Is that tcpdi_parser
even maintained by you?
Hello,
When I updated the package to version 4.0 the composer send this message
"Warning: Ambiguous class resolution, "FPDF" was found in both "....vendor/rafikhaceb/tcpdi/tcpdi.php" and ".....vendor/setasign/fpdf/fpdf.php", the first will be used."
The dependencies have two class with the same name FPDF.
Is it normal?
To be prepared for the december release of PHP 8.0, this repository has some additional TODOs to be tested against the new major version.
Instead of calling a PDF file directly, I am loading it with a PHP script. If I navigate with browser directly to script "pdf_fetch.php" the PDF downloads correctly. But when I try:
$merger->addFile('pdf_fetch.php');
I get "TCPDI_PARSER ERROR Unable to find startxref". I'm not sure if I need to adjust the headers in some way. Currently I have:
header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename='file.pdf'");
Hi,
I'm using version 3.0.0 with composer autoloader and facing some problems related with FPDI classes.
Using the following code:
use iio\libmergepdf\Merger;
$file = "file1.pdf";
$file2 = "file2.pdf";
$pdf = new Merger;
$pdf->addFromFile($file);
$pdf->addFromFile($file2);
header("Content-Type: application/pdf");
echo $pdf->merge();
Throws the expection: FPDI: 'include(fpdi_pdf_parser.php): failed to open stream: No such file or directory'.
The above expection seems to be solved if I change the line 120 of file setasign\fpdi\fpdi.php from
if (!class_exists('fpdi_pdf_parser')) {
to if (!class_exists('fpdi_pdf_parser', false)) {
But then it throws another exception: FPDI: 'include(pdf_parser.php): failed to open stream: No such file or directory'.
Please feel free to ask more details if needed,
Thanks.
My question is: Is this project alive ?
It was last updated on 7 Dec 2020
I am moving out of https://github.com/DALTCORE/lara-pdf-merger and need to know if this project is alive to be sure I will have PHP 8.1 compat if I contribute to it
What should be fixed ?
I made the last PHP 8.1 fixes in tcpdf 6.4.4
libmergepdf/src/Driver/Fpdi2Driver.php
Line 26 in 6613b97
I am trying to delete my pdf files after the merge. But it won't let me do it because the system is using the files. The reset function does not release those added files. How can I release those files?
They use v1.5 pdfs:
We use code like this to add the documents:
$merger = new Merger(new TcpdiDriver());
foreach ($booking->getManuallyCreatedDocuments() as $manuallyCreatedDocument) {
$merger->addRaw(
stream_get_contents($manuallyCreatedDocument->getOriginalResource()->getStream())
);
}
What i get is: 'TCPDI_PARSER ERROR [tcpdi-5d5182b965944]: Pagenumber is wrong! (Requested 0, max )'
If i enable full exception handling i get the following error message:
500 Internal Server Error.pdf.pdf
Would be nice to get an idea how to fix that - current workaround is to skip all documents, where the pagenumber can not be read from.
I would sponsor a fix, if you contact me and we negotiate the conditions.
$pdfMerger->addFile("archivo1.pdf");
$pdfMerger->addFile("archivo2.pdf");
$archivo = $pdfMerger->merge();
$pdfMerger->addFile($archivo);
I'm using this package in combination with our own browsershot package. This package is simply a wrapper around puppeteer, and allows to convert a HTML page to PDF.
Within the same request, I generate a PDF with browsershot, merge it with several other PDFs using this library, and send it to the user.
Chrome gives me the following error:
If I download the PDF file, both Preview and Acrobat Reader say the PDF is broken. For reference, this is the corrupt file:
However, if I go into the filesystem where the PDF has been generated, and open it there, all is fine. This is the same file, but accessed directly from the server:
Some more observations:
Based on these observations, I'm thinking about some kind of race condition, maybe? I wanted to open this issue to see if anyone also encountered similar problems?
After merging 2 PDF, all metadata is gone (title, subject, keywords etc). That's to be expected. I fixed that by adding metadata on the FPDI object:
$fpdi = new FPDI;
$merger = new Merger($fpdi);
$fpdi->SetTitle('Title Ś ś Ŝ ŝ Ş ş Ć ć Ĉ ĉ Ċ ċ Č č');
$merger->addRaw($raw);
etc. That works, but it doesn't seem to accept unicode. Is there a special way to add unicode metadata?
Proofs:
$merger = new Merger;
$merger->addFile('foo.pdf');
$merger->addFile('bar.pdf', new Pages('1-10'));
$createdPdf = $merger->merge();
after merge , then how to download or save to local storage?
Hi, I'm coming across this intermittent error:
iio\libmergepdf\Exception: FPDI: 'Unable to find object (4, 0) at expected location.' in '/home/forge/site/storage/app/files/7d567217-308c-49c5-870d-19222dfa059d.pdf'
The file is 100% there at that location, and it's only with certain files others (using the same methods to retrieve the file location) work without any issues. The file itself is fine and opens with no issues when viewing on a computer. I'm not certain this is an issue with libmergepdf but I'm wondering if you have come across this issue before? It's using the Laravel framework for what it is worth.
Great library by the way been super helpful!
Thanks
I get this error Fatal error: Uncaught Error: Class 'iio\libmergepdf\Merger' not found in...
while the class is actually there. What could be the problem?
Steps to reproduce:
When merging with PDF 1.7 version it is not working
"'Array to string conversion' in 'raw-content'" - I get this when using TcpdiDriver
and of course:
"'This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)' in 'raw-content'" - this for FPDI
Hi, see below..
NOTICE: PHP message: PHP Deprecated: assert(): Calling assert() with a string argument is deprecated in /app/vendor/iio/libmergepdf/src/Pages.php on line 69
I always get the same error. The PDFs are 1.7 and individually I can get them without problems.
`$pdfMerge = new Merger();
$curl = $this->createCurlObject();
foreach ($pdfs as $pdf){
try {
$file = tempnam(sys_get_temp_dir(), 'DOC');
$curl->download($pdf->url, $file);
$pdfMerge->addFile($file);
.....
`
when I make the merge and try to return, the error comes
return $pdfMerge->merge() ==> Unable to find PDF file header
PHP 7.0.33-1~dotdeb+8.1 with libmergepdf version 3.1.1
We have a problem with the merging tool. The first two pdfs are generated with dompdf, and they work well.
aaa0.75641900 1472727705.pdf
aaa0.77990100 1472727705.pdf
After merging them, the links are not clickable anymore.
afinal.pdf
PHPUnit 7.5.18 by Sebastian Bergmann and contributors.
..EEEE................... 25 / 25 (100%)
Time: 158 ms, Memory: 72.00 MB
There were 4 errors:
1) iio\libmergepdf\Driver\Fpdi2DriverTest::testExceptionOnFailure
Array and string offset access syntax with curly braces is deprecated
/home/hannes/repos/libmergepdf/vendor/tecnickcom/tcpdf/tcpdf.php:16900
/home/hannes/repos/libmergepdf/vendor/setasign/fpdi/src/Tcpdf/Fpdi.php:25
/home/hannes/repos/libmergepdf/tests/Driver/Fpdi2DriverTest.php:23
2) iio\libmergepdf\Driver\Fpdi2DriverTest::testMerge
Use of undefined constant K_CELL_HEIGHT_RATIO - assumed 'K_CELL_HEIGHT_RATIO' (this will throw an Error in a future version of PHP)
/home/hannes/repos/libmergepdf/tests/Driver/Fpdi2DriverTest.php:40
3) iio\libmergepdf\Driver\TcpdiDriverTest::testExceptionOnFailure
Array and string offset access syntax with curly braces is deprecated
/home/hannes/repos/libmergepdf/vendor/rafikhaceb/tcpdi/tcpdi.php:248
/home/hannes/repos/libmergepdf/tests/Driver/TcpdiDriverTest.php:15
4) iio\libmergepdf\Driver\TcpdiDriverTest::testMerge
Array and string offset access syntax with curly braces is deprecated
/home/hannes/repos/libmergepdf/vendor/rafikhaceb/tcpdi/tcpdi.php:248
/home/hannes/repos/libmergepdf/tests/Driver/TcpdiDriverTest.php:30
ERRORS!
Tests: 25, Assertions: 22, Errors: 4.```
Hi,
I'm using your package as part of a laravel application and it works OK on our staging server which is php 5.6, unbuntu 14.04.
Have now moved it to a different server which runs php 7.1, unbuntu 16.04 and the app falls over as soon as I hit this line : $m = new \iio\libmergepdf\Merger(); It causes an nginx 502 error, so I can't see any debug information. If I comment that line out everything works fine.
Any help you can give me working out what's going wrong would be much appreciated.
Thanks. Leon
Thanks !
I'm havig this another issue in some cases of merge.
I removed the try/catch statement to see where it came from.
Trying to access array offset on value of type int {"userId":1,"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type int at .../vendor/iio/libmergepdf/tcpdi/tcpdi.php:564)
Right now, the $merger->merge()
call always returns the raw PDF.
It would be great if I could specify an output path directly to save memory and possibly time (https://github.com/clegginabox/pdf-merger seems to take half as much time when writing to a file).
Is there a way to compress the .pdf file?
Is it possible to change the version of fpdi from 1.4 to the actual 1.5? Or should I create a Pull-request?
I need to use TCPDF aswell -> https://github.com/hanneskod/fpdi#support-for-tcpdf
Hello,
Due to the restrictions of the free version of FPDI, I have to switch to the commercial license.
Do you know how can I easily integrate this to the libmergepdf library ?
Thanks you.
Describe the bug
When installing this package, composer reports a warning:
Package setasign/fpdi-fpdf is abandoned, you should avoid using it. No replacement was suggested.
Not sure how to solve this best. Find an alternative. Adopt fpdi-fpdf? Inline the important parts?
To Reproduce
run composer install
in this project, or in a project using libmergepdf
Include files
--
Screenshots
--
Please complete the following information:
Additional context
--
Declaration of setasign\Fpdi\FpdfTplTrait::AddPage($orientation = '', $size = '', $rotation = 0) should be compatible with TCPDF::AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
I want to use the commercial FPDI PDF parser from setasign. In order to do this, I have to use Fpdi2Driver
and pass in an instance of Fpdi
from setasign/fpdi
:
$merger = new Merger(new Fpdi2Driver(new Fpdi()));
Fpdi
extends FpdfTpl
(both from setasign/fpdi
)
FpdfTpl
extends \FPDF
This library provides an alias of \FPDF
which extends from TCPDF
(tecnickcom/tcpdf
).
Fpdi
and TCPDF
have incompatible method signatures on these methods:
Declaration of setasign\Fpdi\FpdfTplTrait::setPageFormat($size, $orientation) should be compatible with TCPDF::setPageFormat($format, $orientation = 'P')
Declaration of setasign\Fpdi\FpdfTplTrait::AddPage($orientation = '', $size = '', $rotation = 0) should be compatible with TCPDF::AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
Declaration of setasign\Fpdi\FpdfTplTrait::Link($x, $y, $w, $h, $link) should be compatible with TCPDF::Link($x, $y, $w, $h, $link, $spaces = 0)
Declaration of setasign\Fpdi\FpdfTplTrait::SetDrawColor($r, $g = NULL, $b = NULL) should be compatible with TCPDF::SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
Probably others, I lost interest in manually fixing them just to get a different error message.
This generates a warning in PHP 7.4 and fatal errors in PHP 8.
Hi,
I am using PDF version 1.5. Unable to merge them, and got the below error.
Fatal error: Uncaught Exception: TCPDF_PARSER ERROR: decodeFilterFlateDecode: invalid code in /libmergepdf/vendor/tecnickcom/tcpdf/include/tcpdf_filters.php:474 Stack trace:
#0 /libmergepdf/vendor/tecnickcom/tcpdf/include/tcpdf_filters.php(359): TCPDF_FILTERS::Error('decodeFilterFla...')
#1 /libmergepdf/vendor/tecnickcom/tcpdf/include/tcpdf_filters.php(94): TCPDF_FILTERS::decodeFilterFlateDecode('b\x8F\\xBEW)ccQ\x0F\x06E\x83!j...')
#2 /libmergepdf/vendor/rafikhaceb/tcpdi/tcpdi_parser.php(1158): TCPDF_FILTERS::decodeFilter('FlateDecode', 'b\x8F\\xBEW)ccQ\x0F\x06E\x83!j...')
#3 /libmergepdf/vendor/rafikhaceb/tcpdi/tcpdi_parser.php(1046): tcpdi_parser->decodeStream(Array, 'b\x8F\\xBEW)ccQ\x0F\x06E\x83!j...')
#4 /libmergepdf/vendor/rafikhaceb/tcpdi/tcpdi_parser.php(1082 in /libmergepdf/src/Driver/TcpdiDriver.php on line 52
The final PDF contents haven't any link while we merge several PDFs in which some of the PDF content having links. Please have a look.
Thanks
Rajendra
refactoring https://github.com/hanneskod/libmergepdf/blob/master/src/Merger.php#L152 would make it possible to extend your class more easily, and add custom post processing (e.g. add watermark images, etc.)
So I suggest moving the actual page add operation to a seperated function, which is easier to extend.
This would also raise the readability of the code in the merge function due to less complexity.
\vendor\itbz\fpdi\src\fpdi\fpdi\bridge.php is erroring out.
It is missing a backslash on line 42:
fpdi_bridge extends TCPDF //this is what it looks like
It should say:
fpdi_bridge extends \TCPDF
Hello,
I have a fillable PDF, when I save it with some fields filled, TCPDI Driver can't display they fields.
You can simply reproduce this with the following PDF:
example.pdf
firstname
and lastname
is filled (Toto / Rico). But if you pass it through TCPDI Driver (or FPDI), these data is not displayed.
Do you know how can I use TCPDI Driver with fillable PDF?
Thanks you.
Just wondering if this library support the use of using addPdf with a base64 string as the file property?
Please fix Page.php file to support PHP 7.2+ (assert functions).
Using the underlying FPDI library, merging files is not possible if one of them was created in PDF 1.5 or newer. Do you have any idea about how to solve this, eg. using another PDF library?
Error: This document (xxx.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI.
> $ git clone git://github.com/hanneskod/libmergepdf.git
Cloning into 'libmergepdf'...
remote: Counting objects: 320, done.
remote: Total 320 (delta 0), reused 0 (delta 0), pack-reused 320
Receiving objects: 100% (320/320), 68.94 KiB | 0 bytes/s, done.
Resolving deltas: 100% (134/134), done.
fatal: did not receive expected object a5231ceb78c135e9230936e0469d712dbb7a7a3c
fatal: index-pack failed
I am getting this error on my local machine, as well as Codeship (via composer).
- Installing iio/libmergepdf (dev-master 0701d00)
Cloning 0701d006f6f611dcb552589a8d7d678059501d54
Failed to download iio/libmergepdf from source: Failed to clone [email protected]:hanneskod/libmergepdf.git via git, https, ssh protocols, aborting.
- git://github.com/hanneskod/libmergepdf.git
Cloning into '/home/rof/src/github.com/Fire-Recovery-USA/frusa-recovery-hub/web/vendor/iio/libmergepdf'...
fatal: object of unexpected type
fatal: index-pack failed
- https://github.com/hanneskod/libmergepdf.git
Cloning into '/home/rof/src/github.com/Fire-Recovery-USA/frusa-recovery-hub/web/vendor/iio/libmergepdf'...
fatal: object of unexpected type
fatal: index-pack failed
- [email protected]:hanneskod/libmergepdf.git
Cloning into '/home/rof/src/github.com/Fire-Recovery-USA/frusa-recovery-hub/web/vendor/iio/libmergepdf'...
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
fatal: object of unexpected type
fatal: index-pack failed
Now trying to download from dist
- Installing iio/libmergepdf (dev-master 0701d00)
[UnexpectedValueException]
RecursiveDirectoryIterator::__construct(*redacted*/vendor/iio/libmergepdf): failed to open dir:
No such file or directory
Could this be an issue with the repo? With Github?
If I merge two PDF files using the latest v4.0 beta, all pages have a line drawn at their top. See the attached files for details.
What I've tried:
Is there any way to stream out the merged file instead of saving it?
It would be nice to use the function addFinder($finder) with an option for Pages().
Example:
$m->addFinder($finder, new Pages('1'));
This would merge the first page of all found pdfs.
Hi!
I use libmergepdf in a symfony2 project. Works like a charm!
But trhere ist a problem with shared hosting environments in
Merger.php Line 187:
return tempnam(sys_get_temp_dir(), "libmergepdf");
sys_get_temp_dir will return "/tmp". But must hosters restrict access for phpcgi/fpm to a users tmpfolder. Then you will get the following exception in Symfony2:
Warning: tempnam(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/srv/www/whereever) in /srv/www/whereever/vendor/iio/libmergepdf/src/Merger.php line 187
Maybe as default you can use the above call but also implement a setter to set the temppath ?
Best regards,
Kai.
PSR-4
License year
Gemnasium/update dependencies
Update build index.html link
Change namespace to libmergepdf/ ?? (bc-break)
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.