How to PDF

From XPUB & Lens-Based wiki

How to PDF?

The "Portable Document Format" launched in 1992 by Adobe Inc™, owned by them until 2008, after which it was released and re-licensed as an ISO standard.

PDF has its roots in PostScript, a document format and programming language launched in 1982 with the aim to standardize the printing industry. With PostScript it became possible to print documents from any computer on any printer with PostScript support.

PDF writing workflows

Depending on how you write, what writing environment you use, and in what formats you can export your writing, you can generate a PDF and write a custom stylesheet.

writing toolexport file formatPDF engine → 🎉 PDF 🎉

Docx

$ pandoc --from docx --to pdf mytext.docx --stylesheet stylesheet.css --pdf-engine=weasyprint --output mytext.pdf

Instead of "weasyprint", you can also use other PDF engines: pdflatex, lualatex, xelatex, latexmk, tectonic, wkhtmltopdf, weasyprint, pagedjs-cli, prince, context, pdfroff (but you need to install that software first on your computer before you can use it). See more info on this page: https://pandoc.org/MANUAL.html#option--pdf-engine

More info: Pandoc

Markdown

$ pandoc --from markdown --to pdf mytext.md --stylesheet stylesheet.css --pdf-engine=weasyprint --output mytext.pdf

More info: Pandoc

Mediawiki

$ pandoc --from mediawiki --to pdf mytext.mediawiki --stylesheet stylesheet.css --pdf-engine=weasyprint --output mytext.pdf

More info: Pandoc

HTML

$ weasyprint mytext.html -s stylesheet.css mytext.pdf

More info: Weasyprint

PDF compression

Very probably a very real future scenario: you are applying for a fund and need to upload a portfolio document in PDF format. You work on it very hard, all day, your fingers feel stiff from all the typing, you have to make sure it is done before the deadline at midnight. Five minutes before the deadline you're done!! Whoohoo, you are relieved: "this is just in time"! "Let's upload this quickly!" ........ And then you look at the interface and you notice the small light grey letters that say: "max 10 MB"... WHAT TO DO?!?

🌟 Compress your PDF! 🌟

This is a bash script based on Ghostscript that can be used to compress/resize a PDF.

This is a version of a script called resample.sh written by OSP.

Script

#! /bin/bash

pdffile=$1;
dpi=$2 

gs \
  -o "${pdffile%.pdf}-resized.pdf" \
  -sDEVICE=pdfwrite \
  -dDownsampleColorImages=true \
  -dDownsampleGrayImages=true \
  -dDownsampleMonoImages=true \
  -dColorImageResolution=$dpi \
  -dGrayImageResolution=$dpi \
  -dMonoImageResolution=$dpi \
  -dColorImageDownsampleThreshold=1.0 \
  -dGrayImageDownsampleThreshold=1.0 \
  -dMonoImageDownsampleThreshold=1.0 \
   "${pdffile}"

How to use it?

Save the code above to a file called resize.sh.

The script requires two arguments:

$ ./resize.sh <file.pdf> <resolution in DPI>

For example:

$ ./resize.sh myfile.pdf 300

The output will be something like:

myfile-resized.pdf

PDF imposition

Your PDF is done, congratulations!! Now it's time to print it. But how? As a stapled A4 document? As a small A5 booklet? As a zine printed on A3 and folded to A6? How to do this??!

📚 Imposition your PDF! 📚

Imposition

PDF colorspace

RGB → CMYK

$ ./rgb2cmyk.sh input.pdf

rgb2cmyk.sh (using Ghostscript), part of OSP's pdfutils

You can check if it worked out with this color separations script:

coloseperation.sh (using Ghostscript), part of OSP's pdfutils

More info: http://osp.kitchen/tools/pdfutils/

Grayscale

$ ./color_convert.sh black input.pdf input-K.pdf

http://osp.kitchen/tools/pdfutils/tree/master/color_convert.sh#project-detail-files

More info: http://osp.kitchen/tools/pdfutils/

PDF backgrounds + stamping!

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

pdftk tools: background, multibackground, stamp, multistamp

PDF merging!

Merge multiple PDFs into one:

$ pdfunite file1.pdf file2.pdf output.pdf

Links