Search code examples
pdf-generationghostscript

How to add TrimBox and BleedBox without fonts being rasterized


I want Ghostscript to prepare PDFs for print production. The input PDF (Version 1.3) is in RGB, uses transparency and has crop marks.

  1. Convert colors to CMYK by applying an ICC profile
  2. Add a TrimBox and a BleedBox

I managed to achieve the steps above using the following command:

gs -o output.pdf -sDEVICE=pdfwrite -dPDFX  -r100 -dOverrideICC=true -sOutputICCProfile=ISOcoated_v2_300_eci.icc -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dRenderIntent=3 input.pdf -c "[ /PAGES pdfmark << /PDFXSetBleedBoxToMediaBox false /PDFXTrimBoxToMediaBoxOffset [29 29 29 29] /PDFXBleedBoxToTrimBoxOffset [8 8 8 8] >> setdistillerparams" -f 

But unfortunately the fonts are getting rasterized. I found out that -dPDFX causes that. But it seems like -dPDFX is needed to add the TrimBox and BleedBox. Without -dPDFX the fonts remain unchanged but the boxes won't be added.

I'm on OSX, the PDF contains two Type 3 fonts.
Any help is very appreciated.


Solution

  • OK, a few points:

    Ghostscript (and more particularly the pdfwrite device) doesn't add anything to PDF files. It makes brand new PDF files from the supplied input, which may or may not be a PDF file.

    The process is described here and I'd suggest you read it. Essentially you cannot assume that the content of the produced PDF file bears any relationship at all to the content of the input, if it's a PDF file.

    Your usage of ICC profiles is not causing the conversion to CMYK, that's done by setting ColorConversionStrategy. Your setting of OverrideICC and OutputICCProfile aren't doing anything and you should remove those switches. In addition you should not set ProcessColorModel if you are setting ColorConversionStrategy. Similarly setting RenderIntent does nothing at all with the pdfwrite device, drop that too.

    Don't set the resolution. All that does is set the resolution of any content which must be rendered (eg creating a PDF file < version 1.4 from an input file containing transparency). So drop the -r100.

    -dPDFX doesn't cause fonts to be rasterised.

    If that's happening then it's almost certainly nothing to do with selecting PDFX, without seeing your input file I can't comment further.

    -dPDFX is not necessary to create a PDF file with TrimBox or BleedBox.

    Of course, what your PostScript actually does is create PDFX Bleed and Trim Offsets, and yes, if you want those then you need to set PDFX, clearly. On the other hand, if you actually want to set normal regular Bleed or Trim boxes then that is also documented in the pdfmark reference (see page 37 of the 1.7 pdfmark reference):

    The syntax for specifying a non-default page cropping for a particular page in a document is as follows: [ /CropBox [xll yll xur yur] /PAGE pdfmark The syntax for specifying the default page cropping for a document is as follows: [ /CropBox [xll yll xur yur] /PAGES pdfmark

    Obviously you would Substitute Bleed or Trim for CropBox.

    Update

    This command line:

    gs -sDEVICE=pdfwrite -sOutputFile=new.pdf  /temp/input.pdf -c "[/CropBox [100 100 7568 3784] /PAGES pdfmark" -f
    

    for me produces a PDF file (new.pdf) which has a CropBox in the Pages tree root node. Entries in the Pages tree are inherited by all pages below the node where they are defined and when I open the file with Acrobatm I can see that the crop marks are no longer visible.

    So for me, it all works fine, and without using PDFX. Adding -sColorConversionStrategy=CMYK should be enough to get a CMYK file out. And since it isn't using PDF/X, it will maintain the transparency instead of rendering it. Note that since your file is all in DeviceGray, the colour is retained unchanged anyway.

    I forgot to say that using /TrimBox instead of /CropBox works perfectly well for me as well, in exactly the same manner.