6

I am working on API which gives me PDF(ver 1.7) in response and my project is using zend pdf library which doesn't support parsing of PDF version 1.7 .

So i have decided to convert PDF version to make compatible with Zend Pdf.

Is there any way to convert pdf version to older version using php?

Thanks

Gulshan Maurya
  • 1,010
  • 11
  • 22
  • Are you sure zend pdf supports 1.6? The major break was between 1.4 and 1.5, everything since then were details. – mkl Sep 03 '16 at 09:19
  • I am currently using "ghostscript server software" right now to convert to version 1.6. And that works as i need but that is not preferred way. – Gulshan Maurya Sep 03 '16 at 09:32
  • Are you sure that the 1.6 is important? Or might be relevant whether cross reference tables or cross reference streams and object streams are used? – mkl Sep 03 '16 at 12:10
  • cross reference is used in PDF which is causing problem to Zend_PDF. Not sure about 1.6 but 1.4 is working. – Gulshan Maurya Sep 03 '16 at 12:38
  • If the problem are the cross reference streams and object streams, they are allowed since 1.5 but are not required. Thus, you should probably ask for a tool transforming those streams to cross reference tables and normal objects. – mkl Sep 03 '16 at 20:06
  • so is there any php tool for this? – Gulshan Maurya Sep 05 '16 at 06:04
  • I don't know. I'm not into PHP, merely into PDF, so I argued along that knowledge. If I knew such a tool, I'd have answered accordingly. If on the other hand you could use a Java application, I could point you to one. – mkl Sep 05 '16 at 08:19
  • @mkl Thank you for your time. I have non php solution but purpose of posting this question here is to get some php tool or way to do this. – Gulshan Maurya Sep 05 '16 at 09:58

2 Answers2

1

You can do this in Ghostscript. I have been looking for a solution for the similar problem and after trying so many different scripts the most reliable one is ghost script.

  $command = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6  -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=pdf_out.pfg pdf_in.pdf";
  $p_result =  exec($command); 

these are the options for your out pdf;

-dPDFSETTINGS=/screen (screen-view-only quality, 72 dpi images)

-dPDFSETTINGS=/ebook (low quality, 150 dpi images)

-dPDFSETTINGS=/printer (high quality, 300 dpi images)

-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)

-dPDFSETTINGS=/default (almost identical to /screen)

The problem is this : You have got a steak and you want it to convert another type of steak, so the other scripts are taking your steak, turning in to minced meat and than making steak again. So the outcome will never be exactly same. For example if your pdf has got a text says "click here" and takes you to www.example.com , after converting the version of pdf, the "click here" link is being removed.

Display name
  • 420
  • 5
  • 20
  • Thanks for your answer but i am already using Ghostscript. I want PHP solution not third party software dependent solution. – Gulshan Maurya Sep 09 '16 at 05:24
  • hi gulshan, I have been doing PDF operations online for last 4 years, used every single piece of code and software and php is not enough to edit pdf. you will have to use a third party library. so your question was "Is there any way to convert pdf version to older version using php?" , so the answer is NO. – Display name Sep 09 '16 at 08:20
  • Ok, is there any library available to parse PDF 1.7 and perform operations like merge pdf pages? – Gulshan Maurya Sep 09 '16 at 09:51
  • yes there are few options, one is free and the other one is commercial (200 euros). So i assume you will go with the free option. it is called PDFtk. the script is on shell command example is "pdftk file1.pdf file2.pdf file3.pdf cat output newfile.pdf" – Display name Sep 09 '16 at 10:33
  • Is it PHP based? if it is PHP based i can use commercial. – Gulshan Maurya Sep 09 '16 at 10:55
  • it is a linux software where you run a shell script to run the commands. as i said earlier php it self is not enough for pdf documents. – Display name Sep 09 '16 at 11:00
  • my bad :( but i will be looking forward in future. Many thanks for your valuable time. I am giving you bounty as you have given much attention. – Gulshan Maurya Sep 09 '16 at 11:02
0

You shouldn't rely on ZendPdf. It is an abandoned and unmaintained project and the ZendPdf homepage suggests, that you should use TCPDF instead.

Anh Pham
  • 2,108
  • 9
  • 18
  • 29
PatrickF
  • 594
  • 2
  • 11