Skip to content

Documents and PDFs ​

A PDF can be 3 KB or 30 MB for the same single page. After this lesson you can tell which kind you have, why, and how to make the big kind smaller without making it unreadable.

What a PDF is ​

PDF (Portable Document Format) describes pages that look the same on every device and printer. Each page can hold three kinds of content:

ContentStored asSize
TextCharacters, plus the font to draw them withTiny
Vector graphicsLines, shapes and fills, like SVGSmall
ImagesRaster pictures, usually compressed as JPEG or losslesslyOften almost all of the file

Around the pages a PDF can also carry metadata (title, author, the program that made it), links, form fields, bookmarks, attached files, and sometimes a password.

Look inside one ​

A PDF is partly readable text. This is the start of a one-page PDF holding about fifty lines of typed text, made with Ghostscript:

text
%PDF-1.7
…
4 0 obj
<</Type/Page/MediaBox [0 0 612 792]
/Rotate 0/Parent 3 0 R
/Resources<</ProcSet[/PDF /Text]
/Font 9 0 R
/Contents 5 0 R
…

%PDF-1.7 is the version. The page object says the page is 612 × 792 points (a point is 1/72 inch, so this is 8.5 × 11 inches, US Letter), that it uses text and a font, and where its contents are. The whole file is 3,071 bytes. The text is stored as characters, which is about as compact as a document gets. (A font embedded in the file would add some kilobytes; this one uses a font every PDF reader already has.)

Why scanned PDFs are big ​

A scanner or a phone "scan" app does not record letters. It takes a photo of each page, and the PDF holds one image per page.

Pixel sizes for an A4 page (8.27 × 11.69 inches) at common scan resolutions:

Scan resolutionPage in pixelsRaw pixels (colour)
72 DPI595 × 8421.5 MB
150 DPI1240 × 17546.5 MB
300 DPI2480 × 350826.1 MB

Even compressed as JPEG, a colour page scanned at 300 DPI came out at 2.4 MB in our test, against 3 KB for the typed page. At that rate a 20-page scan comes to around 50 MB, more than most email services accept.

Scans have two more problems:

  • The text is not text. You cannot search it, select it or copy it, and screen readers used by blind people cannot read it, unless the scanner ran OCR (optical character recognition), which adds a hidden text layer.
  • Colour wastes space. A black-and-white letter scanned in colour stores three channels for what is really two shades.

Compressing a PDF: downsampling ​

A PDF compressor mostly works on the images, because that is where the bytes are. Its main tool is downsampling: lowering the resolution of each image to what the purpose needs, then re-compressing it.

PurposeResolution that is enough
Reading on screen72 to 150 DPI
Printing on an office printer150 to 300 DPI
Professional printing300 DPI

We took the 2.4 MB scanned page and ran it through Ghostscript, the free PDF engine, with two of its standard settings. ebook downsamples images to 150 DPI, screen to 72 DPI:

bash
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook \
   -sOutputFile=scan-ebook.pdf scan-300.pdf
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/screen \
   -sOutputFile=scan-screen.pdf scan-300.pdf
ls -l *.pdf
text
-rw-rw-r-- 1 user user 2404151 … scan-300.pdf
-rw-rw-r-- 1 user user  402851 … scan-ebook.pdf
-rw-rw-r-- 1 user user  126772 … scan-screen.pdf

From 2.4 MB to 400 KB is fine for reading on screen. 127 KB is small, but small print may become hard to read. Always open the result and zoom in on the smallest text before you send it.

A PDF that is mostly typed text shrinks only a little, because there is little to downsample.

PDF compression in the Dhiva Labs apps ​

The three apps compress PDFs in quite different ways:

AppHow it compressesGood forWatch out
CompressXGhostscript, at four levels: Low (best quality), Medium, High (default) and Maximum (smallest)Scans and photo-heavy PDFsNeeds Ghostscript; Linux and Windows only
Creator ToolkitRebuilds the PDF with stronger compression of its internal dataText PDFs with bloated internalsLeaves images as they are, so scans shrink little
Dhiva ToolsTurns every page into an image, at Maximum compression, Recommended or High qualityScansText can no longer be selected, searched or copied, and links stop working

CompressX's four levels correspond to Ghostscript's prepress, printer, ebook and screen settings, so High is the ebook run above.

WARNING

Compression that turns pages into images, or downsamples them, cannot be undone. Keep the original PDF, especially for contracts, forms and anything with text you may need to copy later.

Merging and splitting ​

Merging joins several PDFs into one, in order. Splitting pulls pages out into separate files. Neither changes the content of the pages, so neither loses quality.

text
 Merge
 ┌─────────┐   ┌──────────┐
 │ cv.pdf  │ + │ cert.pdf │  →  cv_merged.pdf (3 pages)
 │ 2 pages │   │ 1 page   │
 └─────────┘   └──────────┘

 Split, "Every page"
 ┌────────────┐
 │ report.pdf │  →  report_pages/
 │ 3 pages    │       report_page_01.pdf
 └────────────┘       report_page_02.pdf
                      report_page_03.pdf
  • Merge: CompressX's Compress & Merge tab (uses qpdf or Ghostscript; Linux and Windows) and Creator Toolkit's Merge tab. Both join files in the order you add them and name the result after the first file with _merged added.
  • Split: Creator Toolkit's Split tab, with Every page or a Page range such as 2 to 5. See Work with PDFs.

Typical uses: put a CV and its certificates into one file for an application, or send only the signed page of a long contract.

Password-protected PDFs cannot be opened by Creator Toolkit or Dhiva Tools; remove the password in a PDF reader first, if it is your document.

PDFs from images, and images from PDFs ​

Phone photos of receipts or a handwritten form often need to become one PDF.

  • CompressX Images → PDF makes one page per image, each page the size of its image, with the images stored as JPG at the Default quality from Settings. It works on Android too. See Turn images into a PDF.
  • Dhiva Tools JPG to PDF lets you choose the Page size (A4 portrait, A4 landscape, US Letter or Fit to image) and a Margin. See JPG to PDF.

The size of the result follows the images. Twelve 4 MB phone photos make a PDF of tens of megabytes. Shrink the photos first (Lesson 2: a long side of about 1600 to 2000 pixels is plenty for a page you read on screen), then build the PDF.

Going the other way, Dhiva Tools PDF to JPG renders pages as JPG images at 72 DPI — screen / web, 150 DPI — recommended or 300 DPI — print quality, using the same DPI idea as scanning.

Stay safe ​

  • Keep originals of anything you compress. Lossy PDF compression is one-way.
  • Check the metadata before sending. A PDF's properties can include the author's name, the company, and the program used. Most PDF readers show them under File → Properties or Document properties.
  • Black boxes do not always hide text. Drawing a black rectangle over text in an editor often leaves the text underneath, where anyone can select and copy it. Use a real redaction tool, or print and re-scan, then check by trying to select the hidden words.
  • Scans of ID cards, bank statements and signed forms are prime material for identity theft. Send them only where they are needed, and prefer tools that process the file on your device, as all the apps in this track do.
  • Be careful with PDFs from strangers. PDFs can contain links and scripts. Open unexpected attachments in an up-to-date reader or browser, and do not follow links inside them that ask you to sign in.

Check yourself ​

QuizDocuments and PDFs

Question 1 of 6

A one-page typed letter is 40 KB as a PDF. The same letter, scanned, is 2.5 MB. Why?

Score: 0

What you learned ​

  • A PDF page holds text, vector graphics and images; images usually make up most of the size.
  • A scanned PDF is one photo per page, so it is large and its text is not searchable without OCR.
  • PDF compression mostly downsamples images, to about 150 DPI for screen reading or 72 DPI for the smallest files.
  • Merging and splitting do not change page content and lose no quality.
  • To build a small PDF from photos, shrink the photos first.

Next steps ​