- 1. Important document
- 2. Tips
- 3. PDF app in Linux
- 4. Installation of PDFtk/pdftk
- 5. Examples
- 6. pdftk usage
- 7. Best Free PDF Tools | Gizmo’s Freeware
Important document
./find_in_pdf.docx
./List_of_PDF_Editing_tools_for_Ubuntu.html
./pdftk_Learning.docx
Tips
Reduce the size of PDF doc
1 | i=large.pdf |
I had the same problem and found two different solutions (see this thread for more details). Both reduced the size of my uncompressed PDF dramatically.
- Pixelated (lossy):
1 | i=input.pdf |
- Unpixelated (lossless, but may display slightly differently):
1 | i=input.pdf |
Edit: I just discovered another option (for lossless compression), which avoids the nasty gs command. qpdf is a neat tool that converts PDFs (compression/decompression, encryption/decryption), and is much faster than the gs command:
Ref
- Ubuntu Tip:Howto reduce PDF file size from command line | Ubuntu Geek
- Linux: Compress PDF - Reduce PDF Size - ShellHacks
- How to Reduce the Size of PDFs on Ubuntu | Chron.com
- compression - How can I reduce the file size of a scanned PDF file? - Ask Ubuntu
- How to Shrink Huge pdf files via Terminal on Ubuntu | Anansewaa
1 | for Input in *.pdf; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.6 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${Input%.pdf}.PDF" "${Input}"; done |
Change the name of pdf documents
1 | for i in *.pdf; do mv ${i} `pdfinfo ${i} | grep "^Title\:\ " | sed "s/Title: //" | sed 's/\,/\_/g; s/\:/\_/g; s/\ /\_/g' | sed 's/\_\_/\_/g'`.pdf; done |
Conversion
1 | convert *.png target.pdf |
Convert BMP to pdf
遇到一个例子,无法直接使用下列命令将bmp文件直接转为pdf文件。这些命令涉及:
- img2pdf
- mogrify
- convert (from ImageMagick)
bmp文件如下:
1 | /media/ht/ht_5T/Work/References/Tech/DNA_Amplification/Isothermal_Amp/RCA_Ref/RCA_Ref_4/RCA产物的大小/AFM/Atomic_force_microscopy_analysis_of_RCA_of_plasmid_DNA/Templiphi-Time_course.bmp |
1 | convert 1.bmp 1.pdf |
1 | mogrify -format jpg 1.bmp # output, 1.jpg |
Convert JPEG/PNG to pdf
1 | ls -1 ./*.jpg | xargs -L1 -I {} img2pdf {} -o {}.pdf |
Convert TIFF to pdf
1 | tiff2pdf -j -o file_name.pdf file_name.tiff |
Converting DJVU to PDF
.djvu
1 | sudo apt install djview |
- Goto Synaptic Package Manager
- Install
1 | djvulibre-bin libdjvulibre21 okular-extra-backends evince libevdocument3 libevview3 |
- Goto terminal and write
1 | sudo apt-get install libtiff-tools |
- Goto the directory where the djvu file is present. Click the right mouse button. Goto “Open In Terminal” option. Click on it. A terminal will open.
- In that terminal write
Conversion
1 | ddjvu -format=pdf file_name.djvu file_name.pdf |
epub
- editing - Command line extraction of metadata (title. author) from epub file - Ebooks Stack Exchange
1 | exiftool *.epub | grep 'Package Metadata Title' | awk -F': ' '{print $2$3$4}' | sed 's/\*/\_/; s/\//\_/; s/\ /\_/g' | sed 's/\_\_/\_/g' > 1.list |
Powerpoint convert to PDF
1 | ############################################### |
Word convert to PDF
1 | # This will work for doc as well as docx files. |
Bookmarks
1 | # |
Convert PDF to Text
pdftotext[^pdftotext]
[^pdftotext]: How to Convert a PDF File to Editable Text Using the Command Line in Linux
1 | pdftotext 1.pdf 1.txt |
合并多个PDF文档
pdftk
1 | pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf |
PDF app in Linux
5 Easy & Effective Ways to Edit PDF Documents on Linux
- PDF Studio
- Master PDF Editor
- Calibre + LibreOffice
- Scribus
- GIMP
Installation of PDFtk/pdftk
How to install pdftk on Ubuntu 18.04 Bionic? - Ask Ubuntu
- gdebi (highly recommended over GNOME Software/Software Center), install it from the software center or $ sudo apt install gdebi
- a few dependencies from the artful repositories (.deb files):
libgcj-common (download: https://packages.ubuntu.com/artful/libgcj-common)
libgcj17 (download: https://packages.ubuntu.com/artful/libgcj17)
pdftk, also from artful repo (download: https://packages.ubuntu.com/artful/pdftk)
libgcj-common
libgcj17
pdftk
1 | sudo gdebi /media/ht/ht_5T/Stored_Softs/Linux_Softs/Not_Classified/libgcj-common_6.4-3ubuntu1_all.deb |
Basically the process is opening and installing the .deb files - preferably on gdebi - in the order below. It might be interesting to open pdftk first on gdebi just to see the “impossible dependency” warning. We’re basically installing the dependencies from an older repository, so it’ll run like it did in 17.10. The order is:
After that you might want to check the status of pdftk at the software center - it might say it is not installed; install there or maybe just let it be.
Go to the terminal and check pdftk:
1 | pdftk |
Examples
pdftk
1 | http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-defaults/libgcj-common_6.4-3ubuntu1_all.deb |
Collate scanned pages
1 | pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf |
or if odd.pdf is in reverse order:
1 | pdftk A=even.pdf B=odd.pdf shuffle A Bend-1 output collated.pdf |
Decrypt a PDF
1 | pdftk secured.pdf input_pw foopass output unsecured.pdf |
Encrypt a PDF using 128-bit strength (the default), withhold all permissions (the default)
1 | pdftk 1.pdf output 1.128.pdf owner_pw foopass |
Same as above, except password baz must also be used to open output PDF
1 | pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz |
Same as above, except printing is allowed (once the PDF is open)
1 | pdftk 1.pdf output 1.128.pdf owner_pw foo user_pw baz allow printing |
Join in1.pdf and in2.pdf into a new PDF, out1.pdf
1 | pdftk in1.pdf in2.pdf cat output out1.pdf |
or (using handles):
1 | pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf |
or (using wildcards):
1 | pdftk *.pdf cat output combined.pdf |
Remove page 13 from in1.pdf to create out1.pdf
1 | pdftk in.pdf cat 1-12 14-end output out1.pdf |
or:
1 | pdftk A=in1.pdf cat A1-12 A14-end output out1.pdf |
When using the Windows command-prompt, it helps to use drag-and-drop from the file manager: drag the input PDF file from the file manager onto the command-prompt, and its full pathname will appear at the prompt.
Apply 40-bit encryption to output, revoking all permissions (the default). Set the owner PW to foopass.
1 | pdftk 1.pdf 2.pdf cat output 3.pdf encrypt_40bit owner_pw foopass |
Join two files, one of which requires the password foopass. The output is not encrypted.
1 | pdftk A=secured.pdf 2.pdf input_pw A=foopass cat output 3.pdf |
Uncompress PDF page streams for editing the PDF in a text editor (e.g., vim, emacs)
1 | pdftk doc.pdf output doc.unc.pdf uncompress |
Repair a PDF’s corrupted XREF table and stream lengths, if possible
1 | pdftk broken.pdf output fixed.pdf |
Burst a single PDF document into pages and dump its data to doc_data.txt
1 | pdftk in.pdf burst |
Burst a single PDF document into encrypted pages. Allow low-quality printing
1 | pdftk in.pdf burst owner_pw foopass allow DegradedPrinting |
Write a report on PDF document metadata and bookmarks to report.txt
1 | pdftk in.pdf dump_data output report.txt |
Rotate the first PDF page to 90 degrees clockwise
1 | pdftk in.pdf cat 1east 2-end output out.pdf |
Rotate an entire PDF document to 180 degrees
1 | pdftk in.pdf cat 1-endsouth output out.pdf |
Article Author: Sid Steward
Notes
Pdftk is a command-line program, so you should use your computer terminal or command prompt when first testing these examples.
Ref
Article Tags
pdftk or related: how to make a bookmark for every inserted PDF?
linux - Merge PDF’s with PDFTK with Bookmarks? - Stack Overflow
pdftk
usage
- pdftk—-命令行下操作PDF的利器 - 第三方命令行 - 批处理之家 批处理_BAT_CMD_DOS_VBS_Perl_Python_PowerShell - Powered by Discuz!
1 | 合并PDF: |