Skip to main content
9 votes

Extract even-numbered and odd-numbered pages of a PDF into two separate PDFs

pdftk is not Open Source any longer, unfortunately. (That is a long story.) Plain gs engine can do it, though: gs -sDEVICE=pdfwrite \ -sPageList=odd \ -sOutputFile=odd.pdf \...
Maxim's user avatar
  • 301
8 votes

How can I fix the font problem of this pdf file?

I did some reading and some helpful posts on Stack Overflow (1, 2, 3) seem to suggest that the issue is with the specific fonts embedded in your PDF file. Your original file uses these fonts: $ ...
terdon's user avatar
  • 252k
7 votes

Overlay text in PDF via command line

For people that do not want to install a texlive distribution, you may prefer cpdf as explained here. However since cpdf has a strange license for commercial use, I tried to find an alternative. Here ...
tobiasBora's user avatar
  • 4,681
5 votes

How do I insert a blank page into a PDF with ghostscript or pdftk?

If using pdfjam is an option: pdfjam --outfile output.pdf input.pdf "-20,{},21-" In pdfjam, {} inside range specifications is interpreted as a blank page, so this command inserts a blank ...
quazgar's user avatar
  • 991
5 votes

How do I insert a blank page into a PDF with ghostscript or pdftk?

For anyone just looking to add a single blank page to the end of a PDF, I used the already linked question How do I create a blank PDF from the command line? to create a blank.pdf file and merge it ...
DeveloperACE's user avatar
4 votes

How to stop Ghostscript from adding "Producer" metadata to PDF files

It seems that it is a deliberate choice for Ghostscript to not allow you to set the DOCINFO /Producer key anymore. See this commit (here's on GitHub). The Producer of the output really is the ...
meuh's user avatar
  • 54.7k
3 votes
Accepted

"Place" Letter Sized PDF to Larger pdf at specific position

pdfjam, a tool that comes in TeX distributions like Texlive, will do the trick. The command will be pdfjam -o cover.pdf --papersize '{17.25in,11.25in}' --noautoscale true --nup 2x1 cover-page.pdf '{},...
L. Levrel's user avatar
  • 1,523
3 votes

ghostscript changes orientation of PDF

Add -dAutoRotatePages=/None to your gs command.
ZNN's user avatar
  • 31
3 votes

Extract even-numbered and odd-numbered pages of a PDF into two separate PDFs

You can use qpdf qpdf --empty --pages input.pdf 1-z:even -- even.pdf qpdf --empty --pages input.pdf 1-z:odd -- odd.pdf
lezambranof's user avatar
2 votes

How to convert a color pdf to black-white?

I get reliable results cleaning up scanned pdf's to good contrast with this script; #!/bin/bash # # $ sudo apt install poppler-utils img2pdf pdftk imagemagick # # Output is still greyscale, but lots ...
Bijou Smith's user avatar
2 votes

Can't print to PDF using cups-pdf; used to work, now "failed to set file mode" printing as non-root

Having Referred to the following post: https://ubuntuforums.org/showthread.php?t=1975881 After many research, in the end I found my problem was the permission of the folder /var/tmp/, it was 755 (...
Ingch's user avatar
  • 121
2 votes
Accepted

Convert pdf font colors to monochrome black

Option 1: convert -monochrome in.pdf out.pdf Option 2: You can still download Ghostscript 9.07 https://ghostscript.com/Ghostscript_9.07.html Compile it from source and make install the result. In ...
Ben's user avatar
  • 36
2 votes
Accepted

What is this GhostScript error? “/undefined in /BXlevel”

I'm noticing that you are using a very old GhostScript implementation. The error was reported to the GhostScript bug database in 2006 as bug #689876 (for releases 8.54 and 8.62) and should be fixed ...
Kusalananda's user avatar
  • 356k
1 vote

How can you compress images in a PDF (via a GUI, not batch or CLI util)?

Following are some GUI tools should be able to do what you want: PDF Tricks Qpdf Tools: Uses Ghostscript and QPDF. Avoid importing and exporting with tools that were not intended to work ...
xiota's user avatar
  • 540
1 vote

Cannot open X display `(null)'. **** Unable to open the initial device, quitting

Apparently either your Windows 10 system does not have an "X11 server" software that could receive and display graphics data from X11 GUI applications, or if you have one set up, your SSH ...
telcoM's user avatar
  • 114k
1 vote
Accepted

How to scale down PDF file (in pixels and in cm)?

It worked with gs -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dDEVICEWIDTHPOINTS=1280 -dPDFFitPage -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf which sets the size in cm to A4 ...
Photon's user avatar
  • 119
1 vote

methods of PDF compression

I assume that the size difference is related to ABBY using some commercial magic to be smart about image compression Don't assume, investigate. The PDF format is well-documented, read up on the ...
dirkt's user avatar
  • 33.4k
1 vote

How to convert only the first page of a PDF to a JPG with Ghostscript

The answer (provided by @Freddy) was available in the online documentation: -sPageList=1
Basil Bear's user avatar
1 vote

Close ghostscript without "-c quit" or -dBATCH

Your trap on EXIT is not specifically executed when you close the terminal window or press Ctrl+C, it is executed when then shell exits. Closing the terminal will kill the shell running in the ...
RalfFriedl's user avatar
  • 9,239
1 vote
Accepted

Using Ghostscript to extract every nth page from PDF

Does this help at all? #!/bin/bash function getChunk { #extract a page range gs -q -dNOPAUSE -sDEVICE=pdfwrite -sPageList=$1-$2 -o ${3%%.*}_$(printf %04d $4).pdf $3 } for file in *.pdf; do ...
bu5hman's user avatar
  • 4,851
1 vote

Error while trying to compress pdf using ghostscript recursively via loop

The Problem By default, find performs the -print action: -print True; print the full file name on the standard output, followed by a newline. The "full file name" means that you'll see the ...
JigglyNaga's user avatar
  • 8,106
1 vote
Accepted

Trouble installing GS from source

To have the compiler pick up math.h, I added -std=c99 to LCMS2_CFLAGS in the main Makefile once configure finished: LCMS2_CFLAGS=-DSHARE_LCMS=$(SHARE_LCMS) -std=c99
Leonid Isaev's user avatar
1 vote
Accepted

Finding the size (in points) of the descender of a font in Ghostscript / Postscript?

If you want to draw the line just under the descenders of a given string you can use pathbbox as in the link provided by ridgy in the comments to your question, but if you want a constant distance ...
meuh's user avatar
  • 54.7k
1 vote

How to tell libgs to use another freetype implementation?

One solution is to set LD_PRELOAD to original libfreetype.so. Another one is to recompile infinality with latest libfreetype (2.8.1).
p2rkw's user avatar
  • 111
1 vote

Splitting a PDF file with Ghostscript results in one extra blank page

I've encountered the same behavior. After digging into the documentation it appears that this is a known issue: Note, however that the one page per file feature may not supported by all devices. ...
JacobEvelyn's user avatar
1 vote

How can I convert a scanned PDF with OCRed text to one without OCRed text?

While gs -o output.pdf -sDEVICE=pdfwrite -dFILTERTEXT input.pdf is now a simple solution, there can be an issue with embedded jbig2 images that are recompiled by gs and increase in size. Below are ...
hife's user avatar
  • 132
1 vote

Can't print to PDF using cups-pdf; used to work, now "failed to set file mode" printing as non-root

My users' home directories are in /local/home, so I had to change the line @{HOMEDIRS}=/home/ /local/home/ in /etc/apparmor.d/tunables/home. Then restart apparmor with sudo service apparmor restart
Chelmite's user avatar
  • 135
1 vote

How to convert a color pdf to black-white?

There are many great answers above. I took one of the answers above and added some human interfacing to it. Maybe someone will find it useful. #!/bin/bash pdf2Gray() { if [ -z "$1" ]; then ...
abear2's user avatar
  • 11
1 vote

Install Ghostscript v 9.05 (or newer) on CentOS

In CentOS 8 there is an easier way to do this installation: dnf --enablerepo=PowerTools install ghostscript
Gilberto Moreira's user avatar
1 vote

How to convert a pdf to 4-up in landscape mode (ideally using ghostscript)?

Here is an approach with LaTeX. It puts 6 4"×6" postcards onto a 11"×17" sheet of paper including rotation to fit the two on the side. This could be improved by adding cut marks. \...
William Entriken's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible