0

I'm trying to remove a protection layer of a PDF using PHP and following the method suggested in here.

But for some reasons, the output PDF file becomes a blank page. I'm not sure what I'm missing here.

This is the code:

$cmd = "gs -q -dNOPAUSE -dBATCH 
       -sDEVICE=pdfwrite 
       -sOutputFile='".$filepath."' 
       -c .setpdfwrite 
       -f '".$filepath."'";
$result = exec($cmd);

UPDATE

[Deleted wrong file]

UPDATE 2

Sorry, I think I uploaded the wrong file. This one should be the one with password protection (or anything of sorts that is not readable).

I'm on Linux and the GS version is Ghostscript 8.70

Community
  • 1
  • 1
nogias
  • 563
  • 2
  • 6
  • 23
  • You are mentioning a *protection layer*. Do you mean standard password protection? Or is some other mechanism used? If you are not sure, please supply the PDF in question for analysis. – mkl Jan 14 '16 at 07:16
  • Yes it is password-protected that I meant, file shared above – nogias Jan 15 '16 at 06:23
  • The file `SCAN_20160108_022033_568f554290eb6_scan_20160108_021616_568f543c301d8_tmp_20160108_091443_568f39651db6b_remittance-117149-2016-01-08.pdf` you shared is not password-protected. – mkl Jan 15 '16 at 07:09
  • I agree, this file is not encrypted. Also, running ot through Ghostscript to the pdfwrite device does not result in a PDF which has a blank page. – KenS Jan 15 '16 at 08:14
  • You don't say what OS you are using (I'm assuming some flavour of Linux) and you don't say what version of GS you are using. You should also try from the command line in case your PHP environment differs in some way (the environment may mean it is using a different version of GS for example) – KenS Jan 15 '16 at 08:16
  • Sorry everyone - I clearly uploaded the wrong file. I've updated the question with the right file :) – nogias Jan 20 '16 at 04:29
  • The new upload [protected.pdf](https://www.dropbox.com/s/ls1ybnyc9versxo/protected.pdf?dl=0) is not a PDF but some container format (IPM.Microsoft Mail.Note) containing a PDF. And the contained PDF is completely unprotected. – mkl Feb 02 '16 at 07:53
  • The container format actually is a Microsoft TNEF container... the dreaded `winmail.dat` attachment one sometimes receives from Outlook users. – mkl Feb 02 '16 at 08:01

2 Answers2

0

You are almost certainly going to have to share the PDF file. Also, unless you own the copyright to the file, 'removing protection' is illegal under the DMCA.

If you do own the copyright, why not simply remake the PDF file without protection.

Why are you using PHP instead of running the from the command sahell ?

KenS
  • 30,202
  • 3
  • 34
  • 51
  • 1
    I've shared the PDF file above. My app receives PDF files through an email inbox that our suppliers send invoices to. Some of them generate invoices using an automated software and for some reasons their invoices get password-protected while others don't. – nogias Jan 15 '16 at 06:24
0

Try with qpdf

qpdf --password=YOURPASSWORD-HERE --decrypt input.pdf output.pdf

Reference: http://www.cyberciti.biz/faq/removing-password-from-pdf-on-linux/

gn1
  • 526
  • 2
  • 5