Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:11:18+00:00 2026-06-05T14:11:18+00:00

I need to optimize a number of big PDF documents for file size, so

  • 0

I need to optimize a number of big PDF documents for file size, so I tried using ghostscript, invoked like this:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -sOutputFile=output-my-doc.pdf input-my-doc.pdf

I can see this running for some pages, but then on particular pages it crashes.

I updated to gs version 9.02, and I experience the same. After bursting the document into separate pages, and running the command above on each page, I could confirm which pages are problematic ones; in fact, the error occurs even if I call just gs input-my-doc-pageX.pdf – this starts a viewer, and I could see text typeset until it came to an image, when it crashed.

So I could confirm that in my case, gs crashes on specific images – and finally I can also provide a minimal working (or rather, non-working) example, which demonstrates the problem (below). In particular, the problem seems to be 8-bit RGB images, specified in a certain way.

 

Now, I cannot tell if this is a bug, but since I need to get this done – I was thinking that maybe I could “cheat” ghostscript, by running the PDFs through an application, which would pretty much leave the PDFs untouched – except that it would re-encode the images to a single format (say, PNG); so that the gs optimizer could run over these files too without crashing.

What options do I have to re-encode only the images of a given PDF using the command line in Linux?

Many thanks in advance for any answers,
Cheers!

 

PS: The test case is basically the source-code PDF example in the post: Imagemagick: generate raw image data for PDF flate embedding?.

That PDF (hello2.pdf) opens just fine in, say, evince:

hello2.pdf-evince-OK

… but since it’s xref-table is corrupt, I repair it:

$ pdftk hello2.pdf output hello2O.pdf
$ qpdf --check hello2O.pdf 
checking hello2O.pdf
PDF Version: 1.4
File is not encrypted
File is not linearized
No errors found

The repaired file hello2O.pdf also opens fine in evince – however, when I try to run the above gs optimizing command on it, it fails:

$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -sOutputFile=optihello2O.pdf hello2O.pdf
GPL Ghostscript 9.02 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusSanL-Regu font from /usr/share/ghostscript/9.02/Resource/Font/NimbusSanL-Regu... 2756020 1410650 1869284 568021 3 done.
Error: /undefined in --run--
Operand stack:
   --dict:6/15(L)--   false   --dict:11/19(L)--   --dict:4/4(L)--   --nostringval--   FlateDecode   --dict:4/4(L)--   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1910   1   3   %oparray_pop   1909   1   3   %oparray_pop   1893   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   false   1   %stopped_push   --nostringval--   %loop_continue   --nostringval--   576   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1160/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:108/127(ro)(G)--   --dict:295/300(ro)(G)--   --dict:23/30(L)--   --dict:6/8(L)--   --dict:25/40(L)--   --dict:7/17(L)--
Current allocation mode is local
GPL Ghostscript 9.02: Unrecoverable error, exit code 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:11:20+00:00Added an answer on June 5, 2026 at 2:11 pm

    First, if you find a Ghostscript bug, please report it to us as http://bugs.ghostscript.com

    Secondly I suggest you update the current shipping version of 9.05 which probably has this bug fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in a need to optimize this really tiny, but pesky function. unsigned umod(int
I would like to get stack trace (file name and line number) information for
Given an array of size N I need to find the min number of
I need to optimize a feature which displays the number of alarms for the
I need to optimize our web service, but don't know where to begin. We're
I am have a lot of code that I need to optimize and make
I need to write the expression meaning optimize over the parameter set . I
I need to optimize a query for a ranking that is taking forever (the
I need to optimize some code where I multiply a vector of ints (32
I need to deal with a lot of big numbers much larger than a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.