anwerjunaid anwerjunaid - 24 days ago 14
PHP Question

Merging Different PDF formats with PHP?

I am trying to merge few PDF files with Setasign FPDI. This packages is working fine for some PDF format but failing for others.

There are three different formats of PDF i could find.

Format 1:

%PDF-1.4
%´µ¶·
%
1 0 obj
<<
/Type /Catalog
/PageMode /UseNone
/ViewerPreferences 2 0 R
/Pages 3 0 R
/PageLayout /OneColumn
>>


Format 2:

--uuid:3c4caf6a-2a7e-4ca5-9e0a-63346610deae
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <1>

%PDF-1.4
%âãÏÓ
1 0 obj
<</ColorSpace/DeviceGray/Subtype/Image


Format 3:

2550 4446 2d31 2e34 0a25 aaab acad 0a34
2030 206f 626a 0a3c 3c0a 2f43 7265 6174
6f72 2028 4170 6163 6865 2046 4f50 2056
6572 7369 6f6e 2031 2e30 290a 2f50 726f
6475 6365 7220 2841 7061 6368 6520 464f
5020 5665 7273 696f 6e20 312e 3029 0a2f
4372 6561 7469 6f6e 4461 7465 2028 443a
3230 3136 3131 3130 3135 3437 3532 5a29
0a3e 3e0a 656e 646f 626a 0a35 2030 206f


FPDI works great with Format 1 but it is failing for format 2.

When i tried to merge two files from Format 2 from Another PDF Merging Website, i got combined pdf in Format 3.

My question is how can merge 2 Format 2 files in to any format in PHP.

And if anyone can explain these formats, that would be great too.

Answer

"Format 2" is a corrupted file, because it includes invalid header data which will corrupt the byte offset positions in the PDF (FPDI will not repair such files but requires valid PDFs).

"Format 3" is only a bunch of hex values not a PDF file.

Comments