FPDI free parser that supports PDF version higher than 1.4
Asked Answered
E

4

12

Is there a free/open-source PDF parser out there that can do the job? The free parser that comes with FPDI only supports PDF version up to 1.4. I tried TCPDF but it didn't work.

I know I can change the PDF version of a PDF file thru Acrobat but I had experienced bug on doing this.

I am using FPDI to watermark PDFs we're selling on our company. I noticed one of the PDF I downgraded to 1.4 from 1.7 thru Acrobat looks pretty much the same but after my watermark function is done, the PDF will have white spaces on the right and bottom part of my cover page which has a black background. In short, the PDF looked bad to sell after the whole process.

Exteriorize answered 14/6, 2013 at 5:35 Comment(0)
O
8

I hit this same limitation in a project I'm currently working on, and ended up creating my own parser based on TCPDF's parser which works with a modified verision of FPDI called TCPDI and an unmodified copy of FPDF_TPL. It works with TCPDF 6, and supports up to at least PDF 1.6 (I haven't got a 1.7 PDF handy to try, but I'll be hunting one down shortly to make sure it works).

If you're still wanting to do this, please feel free to try out TCPDI / tcpdi_parser - if you encounter any issues, please report them via Github and I'll look into them. Basic installation and usage instructions can be found in the TCPDI README.

Ozone answered 1/10, 2013 at 2:35 Comment(2)
Nice work ! Can it work only using FPDF ? I created all my PDF with FDPF and I don't want to revisite all my functions to fit to TCPDF. Thanks.Folly
Does your parser (or tcpdi) handle protecting PDF files with a password and only allowing certain permissions? I didn't see that in your code, so I wasn't sure.Gearldinegearshift
G
7

I've worked around this limitation by using pdftk to uncompress a PDF before loading it into FPDI, then re-compressing it with pdftk afterwards.

I did look into a paid license for FPDI but struggled immensly trying to compile and get the evaluation version running and lost hope/confidence. TCPDI lacked any real installation path other than forking or cloning and they all seemed patchy at best on PHP 7.4.

The solution looks a little like this once you've installed pdftk on your machine:

$PDF = new Fpdi();
try {
    $PDF->setSourceFile('./pdf.pdf');
} catch (\Exception $exception) {
    if (aBoolFunctionToDetectThisParticularException($exception)) {
        exec('pdftk ./pdf.pdf output ./pdf_expanded.pdf uncompress');
        $PDF->setSourceFile('./pdf_expanded.pdf');
    } else {
        throw $exception;
    }
}

If you've gone down this route, it's a good idea to recompress as the difference in filesize is dramatic.

exec('pdftk ./pdf_expanded.pdf output ./pdf_compressed.pdf compress');
Gregor answered 12/8, 2020 at 9:47 Comment(2)
The same works with github.com/qpdf/qpdf exec('qpdf --stream-data=uncompress '.$originalPath.' '.$compressedPath); and later exec('qpdf --stream-data=compress '.$compressedPath . ' ' . $originalPath);Mosenthal
I forgot to mention in QPDF you need to use also this flag --force-version=1.4Mosenthal
B
3

FPDI allows processing PDF files up to version 1.4. You can use GHOSTSCRIPT to convert any PDF file to version 1.4 before processing it with FPDI.

Example Code is available on my official website blog this link.

UPDATE -

Please follow this link now. The domain name has been changed from webnius.com to infoconic.com

Bushed answered 23/6, 2018 at 15:41 Comment(2)
That link's website is gone, so here's the wayback machine archive of it: web.archive.org/web/20190415124533/http://www.webnius.com/blog/…Cellist
thanks for the full practical example in the link, it would be great if you produce a generic solution and add to this answer here.Waly
S
-4

Because of the high google result when you search on FPDI. The paid version can do above 1.4:

https://www.setasign.com/products/fpdi-pdf-parser/details/

When you love the software buy it, it ain't allot and you help the developer. :)

Sowers answered 15/1, 2020 at 7:24 Comment(1)
For me $ 100 is something.Larocca

© 2022 - 2024 — McMap. All rights reserved.