Make a browsable PostScript page list from a PDF
pdf2dsc turns a PDF into a small PostScript document that lists its pages for Ghostscript-based viewers. The result is useful when you want to browse PDF pages in a different order, or hand a DSC document to software that understands Adobe's Document Structuring Conventions. It does not convert the PDF into independent image or PostScript page files.
The route
Jump straight to the step you need, or tick off Done means at the end.
This guide uses the pdf2dsc supplied by Ghostscript 10.02.1 on this machine. Allow about five minutes for a single conversion. You need a readable PDF, the ghostscript package, and enough space for the new DSC file. None of the commands below needs sudo.
1. Check the installed command
Confirm that the command is available and record the Ghostscript package version. The package version is useful when comparing output with another host, because this tool is a Ghostscript wrapper rather than a separate PDF engine.
command -v pdf2dsc
dpkg-query -W -f='${Package} ${Version}\n' ghostscript
On this host the expected version is ghostscript 10.02.1~dfsg1-0ubuntu7.9. The command itself does not offer a version option in the installed script. Passing an unsupported option such as --help is treated as a PDF filename, so use the manpage or package query for help and version information.
Checkpoint
Continue when command -v prints a path and the package query prints a Ghostscript version.
2. Put the PDF in a deliberate location
Change the example path to the document you actually want to process. First check that it is a regular, readable file and that its name is the one you expect. This catches the common mistake of converting a missing download or a directory with a similar name.
pdf='/path/to/input.pdf'
test -f "$pdf" && test -r "$pdf" && ls -lh -- "$pdf"
If the check succeeds, ls shows the size and path. If it fails, fix the path or permissions before running pdf2dsc. Do not use sudo to hide a path error: the generated file should normally belong to the user running the conversion.
3. Generate the DSC file with the default name
Run pdf2dsc with the PDF as its only argument.
cd /path/to/the/output/directory
pdf2dsc /path/to/input.pdf
With no second argument, the command removes the input extension and appends .dsc. For example, /path/to/input.pdf produces /path/to/input.dsc, in the same directory as the PDF. The file contains DSC comments such as %%Pages and page entries that ask Ghostscript to display individual PDF pages.
Check the output without opening it in an editor. This confirms both that the file exists and that it looks like PostScript rather than an error report.
test -s /path/to/input.dsc
sed -n '1,12p' /path/to/input.dsc
A successful result starts with %!PS-Adobe-3.0 and normally includes a line like %%Pages: 19, with the number matching the input document. The exact page count and media dimensions depend on the PDF.
Checkpoint
Stop here if the output is missing, empty, or does not start with a PostScript header. The diagnostic from Ghostscript usually identifies a missing, unreadable, or invalid input file.
4. Choose a separate output name when needed
Pass a second argument when the default name is inconvenient, or when you want the generated file in a different directory.
pdf2dsc /path/to/input.pdf /path/to/output/input-page-list.dsc
test -s /path/to/output/input-page-list.dsc
head -n 4 /path/to/output/input-page-list.dsc
The parent directory must already exist, and you must have write permission there. Use a new filename while testing so that you do not accidentally replace a DSC file that another workflow still needs. If you deliberately replace a disposable generated file, keep the original PDF: it is the source from which the DSC file can be recreated.
5. Use the result with the right expectations
The DSC file is a page-list wrapper around the original PDF. When a PostScript viewer processes it, the original PDF must still be accessible at the path embedded in the DSC setup section. Moving the PDF afterwards can therefore break the DSC file even though the DSC file itself is intact. Keep the two files together, or regenerate the DSC file after moving the PDF.
The generated document uses Ghostscript-specific procedures. It is intended for Ghostscript-based viewers, such as Ghostview, rather than for every general-purpose PostScript interpreter. A viewer may be able to browse pages in any order, but pdf2dsc does not edit the PDF, extract pages, or create a portable standalone copy.
Common failures
/undefinedfilenameor a file error: check the exact input path, read permission, and current working directory. Quoting the path protects spaces and shell metacharacters, for examplepdf2dsc "$pdf".- The output is written somewhere unexpected: remember that the one-argument form puts the
.dscbeside the PDF, not beside your shell's current directory. Supply an explicit second path when that matters. - The viewer cannot open the pages: restore the PDF to the path referenced by the DSC file, or run
pdf2dscagain after moving it. The DSC file is not self-contained. - A non-Ghostscript viewer rejects it: this is a compatibility boundary described by the tool's caveat. Try a Ghostscript-based viewer or use a workflow that consumes PDF directly.
Done means
pdf2dscis installed and its Ghostscript version is known.- The DSC file exists, is non-empty, and starts with a PostScript header.
- The page count in
%%Pagesis plausible for the source PDF. - The original PDF remains at the path recorded by the DSC file.
- You have a Ghostscript-based viewer or another known consumer for the result.