A PDF produced from LaTeX often carries "active" content: clickable hyperlinks, internal cross-reference links, bookmarks, and sometimes form fields or embedded JavaScript. When you need a flat, static PDF for printing, archiving, or submitting to a system that rejects interactive elements, the simplest reliable tool is Ghostscript. This tutorial shows how to strip that active content by re-distilling the file through Ghostscript's pdfwrite device.
Step 1: Install Ghostscript
On macOS, install it with Homebrew:
brew install ghostscript
On Debian or Ubuntu use sudo apt install ghostscript; on most Linux distributions Ghostscript is packaged as ghostscript and provides the gs command.
Step 2: Re-distill the PDF
Run the source PDF back through Ghostscript's pdfwrite device. This rewrites the file from its drawing operations, and the interactive annotation layer (links, bookmarks, form fields) is not carried across, leaving a flat PDF that looks identical but is no longer active:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=NEW_FILE.pdf -dBATCH Trivedi_Devharsh_CV.pdf
Breaking down the options:
-dNOPAUSEprocesses every page without pausing between them.-sDEVICE=pdfwriteselects the PDF writer, which is what rebuilds the file.-sOUTPUTFILE=NEW_FILE.pdfis the flat output file.-dBATCHexits Ghostscript when the job is done instead of dropping into its prompt.Trivedi_Devharsh_CV.pdfis the input file (replace with your own).
Ghostscript prints its banner and processes each page:
GPL Ghostscript 10.02.1 (2023-11-01) Copyright (C) 2023 Artifex Software, Inc. All rights reserved. This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY: see the file COPYING for details. Processing pages 1 through 3. Page 1 Page 2 Page 3
The result, NEW_FILE.pdf, keeps the visible text and graphics but drops the clickable link layer.
Step 3: Verify
Open NEW_FILE.pdf and confirm the links no longer respond to clicks and the layout is unchanged. The text stays selectable and searchable because the page content itself is preserved; only the interactive annotations are gone.
If something interactive still survives
Re-distilling removes the annotation layer in the large majority of cases. If a particular file still carries something you need gone, the most thorough option is to rasterize each page to an image and wrap it back into a PDF, which guarantees nothing interactive remains:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfimage24 -r300 -sOUTPUTFILE=NEW_FILE.pdf input.pdf
This renders every page at 300 DPI. The trade-off is that the text is no longer selectable or searchable, so use it only when a fully static, image-only PDF is acceptable.
Avoiding active content at the source
If you control the LaTeX source and simply never want these links, the cleaner long-term fix is to not load hyperref, or to disable its links with \hypersetup{draft}, so the PDF is produced flat in the first place. Ghostscript remains the right tool when you only have the finished PDF.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.