PDF: Difference between revisions

From miki
Jump to navigation Jump to search
(New page: == PDF == * Use <tt>pdftops</tt> (package <tt>xpdf</tt>) to remove password from a protected PDF: <source lang="bash"> pdftops -upw <password> <encrypted>.pdf <decrypted>.ps ...)
 
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== PDF ==
== Links ==
* https://www.bitsgalore.org/2021/09/06/pdf-processing-and-analysis-with-open-source-tools
* Use <tt>pdftops</tt> (package <tt>xpdf</tt>) to remove password from a protected PDF:

== Remove PDF password ==
* See also [http://wiki.yobi.be/wiki/MiscCrypto#To_unlock_password-protected_pdfs on Yobi]
* PDF documents may have up to 2 passwords:
** '''User password''': protects read access to the document, and when no ''Owner password'' is specified, also protects permission settings.
** '''Owner password''': protects full access to the document, and protects permission settings (printing, copying...)

* Use <tt>pdftops</tt> (package <tt>xpdf</tt>) to remove password from a protected PDF. It works with either password, but when both passwords are set, it also works when only the ''user password'' is known (upon condition that permission <tt>allow Printing</tt> is set).


<source lang="bash">
<source lang="bash">
pdftops -upw <password> <encrypted>.pdf <decrypted>.ps # To generate a PostScript file (e.g. for further editing)
pdftops -upw <password> <encrypted>.pdf <decrypted>.ps # To generate a PostScript file (e.g. for further editing)
read; pdftops -upw "$REPLY" <encrypted>.pdf <decrypted>.ps # Same as above but don't store the password in command history
pdftops -upw <password> <encrypted>.pdf -|ps2pdf - <decrypted>.pdf # To generate a new PDF
pdftops -upw <password> <encrypted>.pdf -|ps2pdf - <decrypted>.pdf # To generate a new PDF
pdftops -opw <password> <encrypted>.pdf -|ps2pdf - <decrypted>.pdf # When the Owner Password is known...
</source>
</source>


* An other solution is to use ''PDF Toolkit'' <tt>pdftk</tt>:
* An other solution is to use ''PDF Toolkit'' <tt>pdftk</tt>. However unlike ''pdftops'' this method doesn't work when only ''user password'' is known but both passwords are set.
<source lang="bash">pdftk <encrypted>.pdf input_pw <password> output <decrypted>.pdf</source>


:'''!!! Update''': <tt>pdftk</tt> seems to have a bug that prevent it to remove password from recent PDFs.
* <tt>pdftk</tt> can also be used to generate protected documents, and specifying permissions (eg. ''Printing'' permission).
<source lang="bash">
pdftk <unprotected>.pdf output <protected>.pdf allow Printing owner_pw <ownerpwd> user_pw <userpwd> #Allow HQ printing
</source>


* <tt>[http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm ps2pdf]</tt> can also generate encrypted documents. But the generated document cannot be opened by ''Evince'', and also it is less convenient for specifying the right permission:
<source lang="bash">pdftk <encrypted>.pdf input_pw <password> output <decrypted>.pdf</source>
<source lang="bash">
ps2pdf -sOwnerPassword=STRING -sUserPassword=STRING -dPermissions=number <decrypted>.ps <reencrypted>.pdf
</source>

== Concatenate PDF ==

Easiest is to use <code>pdfunite</code> from Poppler package:
<source lang="bash">
pdfunite first.pdf second.pdf output.pdf
</source>

== Watermark / stamp PDF ==

=== Using pdftk ===
<source lang="bash">
# source: https://superuser.com/questions/280659/how-can-i-apply-a-watermark-on-every-page-of-a-pdf-file
pdftk in.pdf background watermark.pdf output out.pdf
pdftk in.pdf stamp watermark.pdf output out.pdf
qpdf --overlay watermark.pdf --repeat=1 -- in.pdf out.pdf
qpdf --underlay watermark.pdf --repeat=1 -- in.pdf out.pdf
</source>

=== Using PDFCreator (windows) ===
See [[Powerpoint]].

Latest revision as of 06:18, 10 October 2022

Links

Remove PDF password

  • See also on Yobi
  • PDF documents may have up to 2 passwords:
    • User password: protects read access to the document, and when no Owner password is specified, also protects permission settings.
    • Owner password: protects full access to the document, and protects permission settings (printing, copying...)
  • Use pdftops (package xpdf) to remove password from a protected PDF. It works with either password, but when both passwords are set, it also works when only the user password is known (upon condition that permission allow Printing is set).
pdftops -upw <password> <encrypted>.pdf <decrypted>.ps              # To generate a PostScript file (e.g. for further editing)
read; pdftops -upw "$REPLY" <encrypted>.pdf <decrypted>.ps          # Same as above but don't store the password in command history
pdftops -upw <password> <encrypted>.pdf -|ps2pdf - <decrypted>.pdf  # To generate a new PDF
pdftops -opw <password> <encrypted>.pdf -|ps2pdf - <decrypted>.pdf  # When the Owner Password is known...
  • An other solution is to use PDF Toolkit pdftk. However unlike pdftops this method doesn't work when only user password is known but both passwords are set.
pdftk <encrypted>.pdf input_pw <password> output <decrypted>.pdf
  • pdftk can also be used to generate protected documents, and specifying permissions (eg. Printing permission).
pdftk <unprotected>.pdf output <protected>.pdf allow Printing owner_pw <ownerpwd> user_pw <userpwd>    #Allow HQ printing
  • ps2pdf can also generate encrypted documents. But the generated document cannot be opened by Evince, and also it is less convenient for specifying the right permission:
ps2pdf -sOwnerPassword=STRING -sUserPassword=STRING -dPermissions=number <decrypted>.ps <reencrypted>.pdf

Concatenate PDF

Easiest is to use pdfunite from Poppler package:

pdfunite first.pdf second.pdf output.pdf

Watermark / stamp PDF

Using pdftk

# source: https://superuser.com/questions/280659/how-can-i-apply-a-watermark-on-every-page-of-a-pdf-file
pdftk in.pdf background watermark.pdf output out.pdf
pdftk in.pdf stamp      watermark.pdf output out.pdf
qpdf --overlay  watermark.pdf --repeat=1 -- in.pdf out.pdf
qpdf --underlay watermark.pdf --repeat=1 -- in.pdf out.pdf

Using PDFCreator (windows)

See Powerpoint.