hildogjr
hildogjr

Reputation: 876

Extract text from PDF file with password protection

I am trying to extract text from specific pages of PDF files protect with password.

I am try to use pdf2txt %my_file.pdf% but I could not make the command understand the password input or page as argument.

By the example in https://bugs.ghostscript.com/show_bug.cgi?id=691125, I am trying pdf2txt -sPDFPassword="a" h.pdf.

Upvotes: 0

Views: 587

Answers (2)

K J
K J

Reputation: 11739

Not clear which of hundreds of pdf2txt or pdftotext apps your using so check if it passes a GS password like that (most would not)

as you link the command would be dependant on GS itself getting
gs -sPDFPassword=password ...... other options h.pdf

so my version is windowsX32 thus path and .exe different but the result would be similar in x64 etc. gswin32c -sPDFPassword="a" h.pdf

enter image description here

for your commented use on windows it could be like :-

>gswin32c -q -dSAFER -sDEVICE=txtwrite -dTextFormat=3 -o - -sPDFPassword=a -f h.pdf

          Hello world!

much simpler would be use the alternative poppler/xpf pdftotext commands typically
pdftotext -layout -opw a h.pdf out.txt & type out.txt

                Hello world!

or for console

>pdftotext -nopgbrk -fixed 10 -opw a h.pdf -
               Hello world!

>

Upvotes: 1

hildogjr
hildogjr

Reputation: 876

gs -sDEVICE=txtwrite -sOutputFile=- -q -dNOPAUSE -dBATCH to-be-processed.pdf accept the parameter -sPDFPassword="a" before the file name.

Upvotes: 0

Related Questions