uroesch / pdftools

A collection of PDF command line tools and wrappers for Linux
MIT License
88 stars 4 forks source link
pdf pdf-converter pdf-document-processor pdf-generation

= {Title} :title: pdftools :author: Urs Roesch :firstname: Urs :lastname: Roesch :email: github@bun.ch :revnumber: 0.7.1 :keywords: PDF, CLI, Command Line, tools, documents, pdftk, ghostscript, + poppler utils, tesseract, OCR :!toc: :icons: font :git-user: uroesch :repo-name: pdftools ifdef::env-gitlab[] :base-url: https://gitlab.com/{git-user}/{repo-name} :email: gitlab@bun.ch endif::env-gitlab[] ifdef::env-github[] :base-url: https://github.com/{git-user}/{repo-name} :email: github@bun.ch :tip-caption: :bulb: :note-caption: :information_source: :important-caption: :heavy_exclamation_mark: :caution-caption: :fire: :warning-caption: :warning: endif::env-github[]

image:{base-url}/workflows/bash-compatibility/badge.svg[ title="bash-compatilibity", link="{base-url}/actions?query=workflow:bash-compatilbility" ] image:{base-url}/workflows/test-pdftools/badge.svg[ title="os-compatibility", link="{base-url}/actions?query=workflow:os-compatiblilty" ] image:{base-url}/workflows/create-docs/badge.svg[ title="create-docs", link="{base-url}/actions?query=workflow:create-docs" ]

ifndef::env-github,env-gitlab[] image:icons/gitlab-avatar.png[float="left"] endif::env-github,env-gitlab[]

ifdef::env-github,env-gitlab[] +++

+++ endif::env-github,env-gitlab[]

A collection of PDF command line tools and wrappers for Linux written in Bash Shell script. These are generally speaking convenience tools so one does not have to remember very long and cryptic options and switches.

The heavy lifting is done by backend tools such as pdftk, ghostscript and the poppler utils are used.

[[installation]] == Installation instructions

The scripts are meant to be installed in a users' home directory. To do this quickly the Makefile in the root of the repository has a target called user_install.

[source,console]

$ make user_install Install pdftools under /home//bin -> Installing bin/img2pdf to /home//bin/img2pdf -> Installing bin/ocrpdf to /home//bin/ocrpdf -> Installing bin/pdf2pdfa to /home//bin/pdf2pdfa -> Installing bin/pdfcat to /home//bin/pdfcat -> Installing bin/pdfmeta to /home//bin/pdfmeta -> Installing bin/pdfresize to /home//bin/pdfresize -> Installing bin/scan2jpg to /home//bin/scan2jpg -> Installing bin/scan2pdf to /home//bin/scan2pdf -> Installing bin/scan2png to /home//bin/scan2png

To uninstall everything the target user_uninstall can be used.

[[img2pdf]] == img2pdf

A script to convert PNGs, TIFFs or JPEGs to PDF files.

License:: MIT Requires:: bash, pdfcat, ImageMagick, pdftk

[[img2pdf-examples]] === Examples

.Create single page PDFs from images

img2pdf first.png second.jpg

.Create single page PDFs from images and then delete the original images.

img2pdf --delete first.png second.jpg

.Rotate image 180 degrees prior to creating the PDF.

img2pdf --rotate 180 myimage.png

.Rotate images by 180 degrees and concatenate everything into file output.pdf

img2pdf --output output.pdf --rotate 180 page1.png page2.jpg

[[img2pdf-usage]] === Usage


Usage: img2pdf [ ... ]

Options: -h | --help This message -d | --delete Delete the images after creating the PDF file. -o | --output Write the output to specified file . -r | --rotate Rotate the image by Where value can be a positive or negative integer between 0 and 360. -V | --version Display version and exit


<<<

[[ocrpdf]] == ocrpdf

Runs PDFs through OCR and saves the output as a text searchable PDF with the same name.

[NOTE]

Only works with PDFs comprised of a single JPEG, LZW or ZIP compressed image per page. LZW compressed images are being converted to ZIP compressed one during the OCR process.

License:: MIT Requires:: bash, pdfcat, pdfimages (poppler-utils), pdftk, tesseract

[[ocrpdf-examples]] === Examples

.Run OCR with all installed languages on a couple of PDFs

ocrpdf first.pdf second.pdf

.Run OCR with German dictionary on a single PDF

ocrpdf --lang deu german.pdf

.Run OCR with German, French and English dictionaries on multiple PDFs

ocrpdf --lang deu+fra+eng scanned_*.pdf

[[ocrpdf-usage]] === Usage


Usage: ocrpdf [options] [ [,,]]

Options: -h | --help This message -q | --quiet Don't send display processed file names -V | --version Print version information and exit -l | --lang Set the OCR languages to use. For multiple languages concatenate with a '+' E.g eng+deu for English and German Default: deu+eng+fra+ita+jpn+osd

Description: Runs PDFs through OCR and saves the output as a text searchable PDF with the same name.

Disclaimer: Only works with PDFs comprised of a single JPEG, LZW or ZIP compressed image per page. LZW compressed images will be converted to ZIP compressed ones during the OCR process.

<<<

[[pdfcat]] == pdfcat

A quick hack to replace pdfunite as it destroys too much of the original's meta data.

License:: MIT Requires:: bash, pdftk >= 2.0

[[pdfcat-examples]] === Examples

.Merging two PDFs into a new one

pdfcat first.pdf second.pdf > merged.pdf

.Merging sequentially ordered PDFs into a single document

pdfcat myscan*.pdf > merged.pdf

[[pdfcat-usage]] === Usage


Usage: pdfcat [] [..]

Options: -h | --help This message. -V | --version Print version and exit.

<<<

[[pdfmeta]] == pdfmeta

A wrapper script around pdftk to manipulate a PDFs meta data

License:: MIT Requires:: bash >= 4.0, pdftk >= 2.0

[[pdfmeta-examples]] === Examples

.Modify keywords

pdfmeta --keywords "rainbow, magical, unicorn" unicorn.pdf rainbow.pdf

.Modify creation date

pdfmeta --creation-date "2017-01-01 22:30:45" unicorn.pdf

[[pdfmeta-usage]] === Usage


Usage: pdfmeta [[] ..]

Options:
  -h | --help               This message
  -k | --keywords           Comma separated list of keywords
  -s | --subject            Define the PDFs subject
  -t | --title              Define the PDFs title
  -c | --creator            Define the PDFs creator program or library
  -p | --producer           Define the PDFs producing program
  -C | --creation-date      Set the creation date of the PDF
  -M | --modification-date  Set the modification date of the PDF
  -V | --version            Display version and exit

[NOTE]

On Ubuntu 18.04 (bionic) pdfmeta works only with the https://snapcraft.io/pdftk[snap] or with version 3.2.x of https://gitlab.com/pdftk-java/pdftk[`pdftk-java]. With every other version of pdftkCreationDateandModDatewill not work when running the unit tests. The changed PDF has no problem butpdfinfofrom thepoppler-utils` package can't handle the changed entries and reports them as empty.

<<<

[[pdfresize]] == pdfresize

A wrapper around ghostscript to reduce the size of a scanned document

[NOTE]

pdfresize is very likely not working with PDF documents containing https://en.wikipedia.org/wiki/JBIG2[JBIG2] images.

License:: MIT Requires:: bash, ghostscript

[[pdfresize-examples]] === Examples

.Resize to default resolution

pdresize --input input.pdf --output output.pdf

.Resize to screen resolution

pdfresize --quality screen --input input.pdf --output output.pdf

[[pdfresize-usage]] === Usage


Usage: pdfresize [-q pdfsettings] -i -o

Options: -h | --help This message -i | --input A PDF file preferably of high resolution -o | --output Name of the PDF file to save the result to -q | --quality Quality settings for output PDF. See quality keywords for acceptable input. -V | --version Print version and exit.

Quality keywords: screen - low-resolution; comparable to "Screen Optimized" in Acrobat Distiller ebook - medium-resolution; comparable to "eBook" in Acrobat Distiller printer - comparable to "Print Optimized" in Acrobat Distiller prepress - comparable to "Prepress Optimized" in Acrobat Distiller default - intended to be useful across a wide variety of uses

<<<

[[pdf2pdfa]] == pdf2pdfa

Small script to convert a PDF to PDF/A type.

[NOTE]

This is early beta and all the meta data in the PDF will be lost!

[[pdf2pdfa-examples]] === Examples

.Convert pdf file sample.pdf to a PDF/A-2 named sample_a.pdf

pdf2pdfa sample.pdf

.Convert pdf file sample.pdf to a PDF/A-2 named sample_pdfa.pdf

pdf2pdfa --suffix _pdfa sample.pdf

.Convert pdf file sample.pdf to a PDF/A-1 named sample_a.pdf

pdf2pdfa --level 1 sample.pdf

.Convert pdf file sample.pdf to a PDF/A-3 exiting on errors.

pdf2pdfa --level 3 --strict sample.pdf

.Convert pdf file sample.pdf to a PDF/A-2 with color model CMYK.

pdf2pdfa --color-model CMYK sample.pdf

[[pdf2pdfa-usage]] == Usage


Usage: pdf2pdfa [] [ [..]]

Options: -c | --color-model Color model to use for the conversion. Valid input is RGB or CMYK. Default: RGB -h | --help This message -l | --level PDF-A specification level to use. Valid input is 1 (A-1), 2 (A-2) and 3 (A-3). Default: 2 -S | --strict Exit if errors are encountered during conversion. -s | --suffix Append to filename Default '_a' -V | --version Display version and exit.

<<<

[[scan2pdf]] == scan2pdf

Is frontend for scanimage but has only been tested against the Canon LiDE 210 scanner.

Some but not all notable features are:

[[scan2pdf-examples]] === Examples

.Simple single page document produces file scan_YYYY-MM-DD_hh-mm-ss.pdf [source,console]

scan2pdf

.Simple single page document wth OCR produces file + scan_YYYY-MM-DD_hh-mm-ss.pdf [source,console]

scan2pdf --ocr

.Multi page interactive mode wth OCR. [source,console]

scan2pdf --interactive --ocr Enter filename [scan_2022-01-26_23-15-30]: <.> 1) Scan document <.> 2) Finish scan <.> 3) Wrap up and quit <.> Choose action > 1 <.> Choose action > 1 <.> Choose action > 3 <.>

<.> Provide file name or press enter to accept the default name. <.> Menu option 1 scans a page then returns to the prompt. <.> Menu option 2 writes all pages to a PDF file and prompts for a new name. <.> Menu option 3 writes all pages to a PDF file and exists. <.> Scan one page. <.> Scan another page. <.> Write PDF and exit.

.Scan and save as JPEG with filename scan_YYYY-MM-DD_hh-mm-ss.jpg [source,console]

scan2jpg

[[scan2pdf-usage]] === Usage

[source,console]

Usage: scan2pdf

--interactive  -I  Interactive mode
--type         -t  Document Type
                   Possible values are:
                     d[ocument]      for a text document
                     i[llustration]  for a drawing
                     ph[otograph]    for a photographic pictue
                     pr[int]         for a scan from a print e.g. newspaper
                     r[aw]           for not applying any post-processing
                     Default: document
--resolution   -r  Resolution of scan
                     Possible values are 75, 150, 300, 600, 1200
                     Default: 300
--page         -p  Page Size
                     Possible values are A4, A5, A6, Letter, CreditCard, CD-Cover
                     Default: A4
--depth        -d  Color depth of scan
                     1 for LineArt (Black & White)
                     8 for Grayscale and Color
                     16 for Color
                     Default: 8
--format       -f  PDF image compression
                     Possible values are jpeg, zip, lzw
                     Default: jpeg
--quality      -q  Recommended for jpeg, zip, png
                     Values for jpeg from 0 to 100
                     Values for png and zip from 0 to 9
                     Default: 90
 --mode        -m  Color mode of scan
                     Possible values are Lineart, Gray, Color
                     Default: Color
 --ocr         -R  Run the scan through character recognition
                     Default: false
 --ocr-lang    -L  Set the language for the character recognition
                     Every language 'tesseract' supports
                     Default: deu+eng+fra+ita+jpn+osd
 --output      -o  Filename of PDF file
                     Default: scan_2022-01-26_23-10-20
 --orientation -O  Document orientation
                     Possible options p[ortrait], l[andscape]
                     Default: portrait
 --scanner     -s  Set the scanner to be used
                     E.g: gensys:libusb:001:005
 --help        -h  This message

// vim: set colorcolumn=80 textwidth=80 spell spelllang=en_us :