Is there a way to make FPDF/FPDI or Zend_Pdf support the parsing of PDFs greater than 1.4?
Asked Answered
B

7

13

I am trying to add an existing PDF (created otherwise) to a PDF created with FPDF using FPDI. It seems to work find for most PDFs, but I get the following error:

FPDF error: Unable to find xref table.

After some testing, I figured out that if I use a PDF version of 1.4 or lower (Acrobat v5 or lower) it seems to work. Looking at the file it seems to be because of a different PDF format.

Is there a work around or solution to this? I have probably 10 000+ PDFs uploaded by users, some of the new working, some of them not. It's also annoying that FPDI just dies instead of causing some kind of error or even returning false

The only solution I can think of right now is to parse the first line of the PDF file to determine the version and only add the ones that over versions that will work.

Edit:

I also tried this in Zend_Pdf and it had the following result, using the demo file that comes with the Zend Framework:

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Cross-reference streams are not supported yet.' in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php:331
Stack trace:
#0 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php(455): Zend_Pdf_Parser->_loadXRefTable('116')
#1 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(297): Zend_Pdf_Parser->__construct('/Volumes/Docume...', Object(Zend_Pdf_ElementFactory_Proxy), true)
#2 /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf.php(250): Zend_Pdf->__construct('/Volumes/Docume...', NULL, true)
#3 /Volumes/Documents/temp/ZendFramework-1.7.7/demos/Zend/Pdf/demo.php(37): Zend_Pdf::load('/Volumes/Docume...')
#4 {main}
  thrown in /Volumes/Documents/temp/ZendFramework-1.7.7/library/Zend/Pdf/Parser.php on line 331

Is it impossible to parse PDFs greater than 1.4?

Bulk answered 18/3, 2009 at 22:59 Comment(0)
B
4

I found that using commerical version of FPDI PDF-Parser solved my problem. I've been using it for a year now and haven't had any PDFs it couln't parse (unless the PDF was corrupt or had something else weird going on).

Bulk answered 13/2, 2011 at 5:30 Comment(3)
Can you please share with us how you worked with this add-on? Because I have no clue as to how to use it. Ive installed the file, not sure how to use it. Im using the following PDFmerger github.com/myokyawhtun/PDFMerger/blob/master/PDFMerger.php#L78Sorbian
Why did you duplicate an answer instead of accepting it?Actor
@Actor Hmmmm, that is odd. I'm not sure why I would have done that. Seems like others have done the same thing.Bulk
F
20

You can use FPDI with TCPDF, it will generate and read (with FPDI) version 1.7 PDFs.

See TCPDF - PHP class for PDF.


EDIT

I have recently been challenged with the issue of using various versions and formats of PDF with FPDI and TCPDF, and I can confirm that PDF versions above 1.4 are hit and miss, the interesting thing is that I have a lot of working 1.7 PDFs, and works about 50/50 on 1.5 and 1.6.

I worked around the issue by converting all non-workable PDF files to v1.4 using GhostScript which you can exec from the command line. Use ps2pdf14 from the GhostScript lib folder.

Fuji answered 23/7, 2009 at 23:41 Comment(1)
I wouldn't have expected the command ps2pdf14 to work with PDF as input but it worked like a charm.Boyce
S
6

I've just released a pair of projects (TCPDI / tcpdi_parser, based on FPDI and tcpdf_parser, respectively) which work with TCPDF 6 (and FPDF_TPL) to import PDFs above v1.4 (tested up to 1.6 so far, but I'll make sure it works with 1.7 once I find a 1.7 PFD to test it with!) without requiring any commercial addons. Basic installation and usage instructions can be found in the TCPDI README; please feel free to try it out and report any issues via the Github tracker.

Stolzer answered 1/10, 2013 at 2:45 Comment(2)
I just tried it, trying to add text to a PDF v.1.5 and it doesn't work.Interglacial
@greg, if your PDF is not password-protected, please file an issue on the relevant project (TCPDI or tcpdi_parser) with full details of what you're trying to do and what happened (i.e. what error(s) you get). I'll try to investigate, but can't make any promises on time frame.Stolzer
S
5

Setasign is offering a PDF parser as a commercial addon to FPDI. We had no troubles parsing PDF files up to version 1.7 so far using the new parser.

Sunbreak answered 27/11, 2009 at 10:26 Comment(1)
Can you please share with us how you worked with this add-on? Because I have no clue as to how to use it. Ive installed the file, not sure how to use it. Im using the following PDFmerger github.com/myokyawhtun/PDFMerger/blob/master/PDFMerger.php#L‌​78Sorbian
B
4

I found that using commerical version of FPDI PDF-Parser solved my problem. I've been using it for a year now and haven't had any PDFs it couln't parse (unless the PDF was corrupt or had something else weird going on).

Bulk answered 13/2, 2011 at 5:30 Comment(3)
Can you please share with us how you worked with this add-on? Because I have no clue as to how to use it. Ive installed the file, not sure how to use it. Im using the following PDFmerger github.com/myokyawhtun/PDFMerger/blob/master/PDFMerger.php#L78Sorbian
Why did you duplicate an answer instead of accepting it?Actor
@Actor Hmmmm, that is odd. I'm not sure why I would have done that. Seems like others have done the same thing.Bulk
C
2

for symfony, I used this lib to convert >1.4 https://packagist.org/packages/xthiago/pdf-version-converter

Cinderellacindi answered 19/2, 2016 at 10:39 Comment(2)
You know...I think I actually implemented something like this at one point to deal with this an other issues. I just call ghostscript directly in my case, but this might make life a bit easier.Bulk
I'm the author of xthiago/pdf-version-converter. The library can be used in any PHP project - it no requires the use of Symfony Framework (Full Stack). The library internally uses two components of Symfony (process and filesystem), but composer takes care about it. I recommend you the use of the library because it has unit tests (PHPUnit) and is open-source - you can benefit of bug fixes and enhancements made by community.Mixologist
J
0

If you have Acrobat PDF writer, you can manipulate the job settings to make the PDF you are printing/savingAs to be compatible to PDF 1.4. For the tiny reason I need this product, it doesn't seem worth the 100 euros to get the commercial version that is compatible to versions greater than 1.4.

Jumpy answered 23/1, 2014 at 0:52 Comment(0)
G
-2

my team had removed some part of the code. we stopped the code from adding watermark to the pdf. this solved the problem for us. PDF >= 1.5

Gereld answered 5/4, 2012 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.