1

I have a pdf in landscape orientation and is a "Page Spread".

  1. I need to split the page in half vertically in the middle.

    I used this setting to cut the pdf in half: this one gets the left part of the page

    "C:\Program Files (x86)\gs\gs9.10\bin\gswin32c.exe" -o output.pdf 
    -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dSubsetFonts=true -dEmbedAllFonts=true -g 750x1085 -c  
    "<</BeginPage{0.95 0.96 scale 20 22 translate}>> setpagedevice" "<</PageOffset [0 0]>> setpagedevice"  -f input.pdf
    
  2. The above command works fine. My problem now is I need to set the Mediabox, Cropbox, Bleedbox, Trimbox, and artbox similar to the size of the splitted page. In the instance above; it should be 750x1085.

    What should be the correct command/settings to run on GS so that the Mediabox, Cropbox, Bleedbox, Trimbox and artbox has the same sizes?

UPDATE
This is a sample of the PDF file I'm trying to cut in half: PDF FILE TO SPLIT

I am now using /PAGE pdfmark and this is the command I'm trying to use:

     "C:\Program Files (x86)\gs\gs9.10\bin\gswin32c.exe" -o output.pdf -sDEVICE=pdfwrite -dNOPAUSE -dBATCH 
    -dSAFER -dUseCropbox -dSubsetFonts=true -dEmbedAllFonts=true -g7500x10850 
    -c "[/CropBox [0 0 750 1085] /PAGES pdfmark" 
    "[/MediaBox [0 0 750 1085] /PAGES pdfmark" 
    "[/TrimBox [0 0 750 1085] /PAGES pdfmark" 
    "[/BleedBox [0 0 750 1085] /PAGES pdfmark"
    "[/ArtBox [0 0 750 1085] /PAGES pdfmark" 
    "<</BeginPage{0.95 0.96 scale 20 22 translate}>> setpagedevice" 
    "<</PageOffset [0 0]>> setpagedevice" 
    -f input.pdf

I still can't achieve setting the Cropbox, MediaBox, TrimBox, BleedBox, ArtBox with the same size.

What should be the correct settings for the command?

SandoMarco
  • 11
  • 3
  • The MediaBox at least should already be the size of the specified media, and the other boxes are usually not set. If you want to set them you will need to use the /PAGE pdfmark. – KenS Jan 03 '14 at 08:10
  • @KenS I'm confused. but for example in my code above? Where do I insert the "/PAGE pdfmark"? – SandoMarco Jan 06 '14 at 06:00
  • You put it on the command line surrounded by -c and -f switches, since its PostScript. – KenS Jan 06 '14 at 08:04
  • Hi @KenS. Thanks for the response. Much appreciated. But I'm kind of lost on applying the /PAGE pdfmark on the command. I tried adding it between the -c and -f but there's an error: " /unmatchedmark in --pdfmark--". I've just jumped into using ghostscript and I'm lost on the different settings on the commands. Perhaps can you help me with the settings I should add on the command I've given above? I'm also trying to research on the internet on how to use the pdfmark but no luck. I'm still lost. Thanks a lot! – SandoMarco Jan 06 '14 at 08:34
  • What parameters did you supply with the pdfmark ? Its a PostScript operator, so you need to add all the parameters before you call it. Somewhat analagous to the setpagedevice you are already using. You can pick up a copy of the pdfmark reference here : http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdfmark_reference.pdf – KenS Jan 06 '14 at 13:02
  • @KenS Thanks for the reference. Really helped me a lot in somehow understanding the pdfmark. I've updated my question above. I've added the settings for pdfmark and still no luck configuring the BOXES. Is there something wrong with my command? Is it correct? – SandoMarco Jan 07 '14 at 00:32

1 Answers1

0

Moving to an answer here, comments are too small.

Your basic problem is that the original PDF file already contains all of the Box parameters you are trying to modify. The Ghostscript PDF interpreter will, for certain classes of output device, preserve those boxes by writing its own version of a pdfmark to the device. Because this happens after your pdfmark, it replaces yours.

There is, unfortunately, no mechanism in place to disable this. Additionally, since you are using Windows, you have the resources built into the ROM file system, so you can't readily modify them.

So at this point there isn't really anything you can do about this. If you are comfortable downloading the source and meddling with some PostScript let me know and I think I can give you a solution (you don't need to rebuild GS, but the PostScript resources aren't available separately).

EDIT to include some suggested work-arounds

In pdf_main.ps:

% Test whether the current output device handles pdfmark.
/.writepdfmarkdict 1 dict dup /pdfmark //null put readonly def
/.writepdfmarks {   % - .writepdfmarks <bool>
  currentdevice //.writepdfmarkdict .getdeviceparams
  mark eq { //false } { pop pop //true } ifelse
  systemdict /DOPDFMARKS known or
} bind def

You could alter /.writepdmarks to be:

/.writepdfmarks {   % - .writepdfmarks <bool>
    false
} bind def

But note that a number of other things will stop being emitted in the output PDF file.

Instead you could look at the code in pdf_showpage_finish:

/pdfshowpage_finish {   % <pagedict> pdfshowpage_finish -
   save /PDFSave exch store
...
...
  .writepdfmarks {

        % Copy the boxes.
    { /CropBox /BleedBox /TrimBox /ArtBox } {
      2 copy pget {
        % .pdfshowpage_Install transforms the user space do same here with the boxes
        oforce_elems
        2 { Page pdf_cached_PDF2PS_matrix transform 4 2 roll } repeat
        normrect_elems 4 index 5 1 roll fix_empty_rect_elems 4 array astore
        mark 3 1 roll {/PAGE pdfmark} stopped {cleartomark} if
      } {
        pop
      } ifelse
    } forall

You can modify the line '{ /CropBox /BleedBox /TrimBox /ArtBox }', any Boxes you don't want to preserve you can remove from that line.

If you want to prevent any of them overriding your specifications, then remove the lines from '% Copy the boxes' up to '% Copy annotations and links'

Please note this only works on a system where the resources are not built into a ROM file system, or where the resources are at least available on disk, and the path to the Resource files is specified using the -I switch.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Hi @KenS. Does that mean when I try to modify the Box parameters it just reverts it back and replace my settings? Actually I'm going to use LINUX for running this command and I use PHP to call the command. Can you help me with a solution to this? The thing is I'm going to need PHP to call the command for splitting the file. I'm really open for suggestions and solutions. Thanks. – SandoMarco Jan 07 '14 at 08:38
  • Yes, the Box parameters in the PDF files override the ones from your pdfmark operations. If you look in gs/Resources/Init you'll find a file called pdf_main.ps. There are several places you can modify this depending what you want to do. Rather than try and put this in comments I've edited my answer..... – KenS Jan 07 '14 at 15:16