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 6060531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:50:12+00:00 2026-05-23T08:50:12+00:00

I’m trying to render Pdfs pages into png files using Ghostscript v9.02. For that

  • 0

I’m trying to render Pdfs pages into png files using Ghostscript v9.02. For that purpose I’m using the following command line:

gswin32c.exe -sDEVICE=png16m -o outputFile%d.png mypdf.pdf

This is working fine when the pdf crop box is the same as the media box, but if the crop box is smaller than the media box, only the media box is displayed and the border of the pdf page is lost.
I know usually pdf viewers only display the crop box but I need to be able to see the whole media page in my png file.

Ghostscript documentation says that per default the media box of a document is rendered, but this does not work in my case.
As anyone an idea how I could achieve rendering the whole media box using ghostscript?
Could it be that for png file device, only the crop box is rendered? Am I maybe forgetting a specific command?

For example, this pdf contains some registration marks outside of the crop box, which are not present in the output png file. Some more information about this pdf:

  • media box:
    • width: 667
    • height: 908 pts
  • crop box:
    • width: 640
    • height: 851
  • 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-05-23T08:50:13+00:00Added an answer on May 23, 2026 at 8:50 am

    OK, now that revers has re-stated his problem into that he is looking for “generic code”, let me try again.

    The problem with a “generic code” is that there are many “legal” formal representations of “CropBox” statements which could appear in a PDF. All of the following are possible and correct and set the same values for the page’s CropBox:

    • /CropBox[10 20 500 700]

    • /CropBox[ 10 20 500 700 ]

    • /CropBox[10 20 500 700 ]

    • /CropBox [10 20 500 700]

    • /CropBox [ 10 20 500 700 ]

    • /CropBox [ 10.00 20.0000 500.0 700 ]

    • /CropBox [    
                10    
                20    
                500    
                700    
               ] 

    The same is true for ArtBox, TrimBox, BleedBox, CropBox and MediaBox. Therefor you need to “normalize” the *Box representation inside the PDF source code if you want to edit it.

    First Step: “Normalize” the PDF source code

    Here is how you do that:

    1. Download qpdf for your OS platform.
    2. Run this command on your input PDF:
      qpdf --qdf input.pdf output.pdf

    The output.pdf now will have a kind of normalized structure (similar to the last example given above), and it will be easier to edit, even with a stream editor like sed.

    Second Step: Remove all superfluous *Box statements

    Next, you need to know that the only essential *Box is MediaBox. This one MUST be present, the others are optional (in a certain prioritized way). If the others are missing, they default to the same values as MediaBox. Therefor, in order to achieve your goal, we can simply delete all code that is related to them. We’ll do it with the help of sed.

    That tool is normally installed on all Linux systems — on Windows download and install it from gnuwin32.sf.net. (Don’t forget to install the named “dependencies” should you decide to use the .zip file instead of the Setup .exe).

    Now run this command:

    1. sed.exe -i.bak -e "/CropBox/,/]/s#.# #g" output.pdf

    Here is what this command is supposed to do:

    • -i.bak tells sed to edit the original file inline, but to also create a backup file with a.bak suffix (in case something goes wrong).
    • /CropBox/ states the first address line to be processed by sed.
    • /]/ states the last address line to be processed by sed.
    • s tells sed to do substitutions for all lines from first to last addressed line.
    • #.# #g tells sed which kind of substitution to do: replace each arbitrary character (‘.‘) in the address space by blanks (‘‘), globally (‘g‘).

    We substitute all characters by blanks (instead of by ‘nothing’, i.e. deleting them) because otherwise we’d get complaints about “PDF file corruption”, since the object reference counting and the stream lengths would have changed.

    Third step: run your Ghostscript command

    You know that already well enough:

    gswin32c.exe -sDEVICE=png16m -o outputImage_%03d.png output.pdf
    

    All the three steps from above can easily be scripted, which I’ll leave to you for your own pleasure.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put

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.