tavinus / pdfScale

Bash Script to Scale and Resize PDFs using Ghostscript
MIT License
242 stars 36 forks source link

pdfscale custom resize appears to generate different flavor of pdf that interferes with gs PDFX (?) #47

Open DXXS opened 7 months ago

DXXS commented 7 months ago

For some reason, I've encountered an issue where pdf's scaled using 'custom' page size don't seem to allow post-application of PDFX items, while when I use a standard 11x17 size, it does!?":

$ pdfscale -v -r 11x17 pspread-booklet.pdf

$ gs -sDEVICE=pdfwrite -dPDFX-r1200 -g20400x13200 -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -sOutputFile=gs-converted-pdfT.pdf pspread-booklet.11X17.pdf -c "[/PAGES pdfmark << /PDFXSetBleedBoxToMediaBox false /PDFXTrimBoxToMediaBoxOffset [171 63 171 63] /PDFXBleedBoxToTrimBoxOffset [9 9 9 9] >> setdistillerparams"

^^ inspection of such version ^^ with pdfinfo -f 1 -l 1 -box gs-converted-pdfT.pdf shows boxes have been updated

$ pdfscale -v -r 'custom in 15 10' pspread-booklet.pdf

$ gs -sDEVICE=pdfwrite -dPDFX -r1200 -g18000x12000 -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -sOutputFile=gs-converted-pdfM.pdf pspread-booklet.CUSTOM.pdf -c "[/PAGES pdfmark << /PDFXSetBleedBoxToMediaBox false /PDFXTrimBoxToMediaBoxOffset [27 27 99 99] /PDFXBleedBoxToTrimBoxOffset [9 9 9 9] >> setdistillerparams

^^ inspection of such version ^^ with pdfinfo -f 1 -l 1 -box gs-converted-pdfM.pdf shows boxes are all still equal to MediaBox

tavinus commented 2 months ago

That is interesting. The GS calls look pretty much identical. Weird.

EDIT: I though you had the pdfScale GS calls there, but now I am not sure.
Are those GS calls from pdfScale?
If not, can you run both calls with -v --print-gs-call for us to compare both calls and the verbose info?

I made some tests here and the GS calls seems identical, just with Width X Height changed.

Paper std 11x17

$ ./pdfScale.sh --print-gs-call -v -r 11x17 mint.pdf
pdfScale.sh v2.6.1 - Verbose Execution
   Single Task: Resize PDF Paper
       Dry-Run: FALSE
    Input File: mint.pdf
   Output File: mint.11X17.pdf
 Get Page Size: Adaptive Enabled
        Method: Grep
  Source Width: 596 postscript-points
 Source Height: 843 postscript-points
    Print Mode: Print ( auto/empty )
  Scale Factor: Disabled (resize only)
   Fit To Page: Enabled (default)
   Auto Rotate: PageByPage
   Flip Detect: No change needed
  Run Resizing: 11X17 ( 792 x 1224 ) pts
  Final Status: File created successfully
[GS RESIZE CALL STARTS]
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=792 -dDEVICEHEIGHTPOINTS=1224 -dAutoRotatePages=/PageByPage -dFIXEDMEDIA -dPDFFitPage   -sOutputFile="mint.11X17.pdf" -c "" -f "mint.pdf"
[GS RESIZE CALL ENDS]

Paper custom in 15 10

$ ./pdfScale.sh --print-gs-call -v -r 'custom in 15 10' mint.pdf
pdfScale.sh v2.6.1 - Verbose Execution
   Single Task: Resize PDF Paper
       Dry-Run: FALSE
    Input File: mint.pdf
   Output File: mint.CUSTOM.pdf
 Get Page Size: Adaptive Enabled
        Method: Grep
  Source Width: 596 postscript-points
 Source Height: 843 postscript-points
    Print Mode: Print ( auto/empty )
  Scale Factor: Disabled (resize only)
   Fit To Page: Enabled (default)
   Auto Rotate: PageByPage
   Flip Detect: Wrong orientation detected!
                Inverting Width <-> Height
  Run Resizing: CUSTOM ( 720 x 1080 ) pts
  Final Status: File created successfully
[GS RESIZE CALL STARTS]
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=720 -dDEVICEHEIGHTPOINTS=1080 -dAutoRotatePages=/PageByPage -dFIXEDMEDIA -dPDFFitPage   -sOutputFile="mint.CUSTOM.pdf" -c "" -f "mint.pdf"

Comparing

"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=792 -dDEVICEHEIGHTPOINTS=1224 -dAutoRotatePages=/PageByPage -dFIXEDMEDIA -dPDFFitPage   -sOutputFile="mint.11X17.pdf" -c "" -f "mint.pdf"
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=720 -dDEVICEHEIGHTPOINTS=1080 -dAutoRotatePages=/PageByPage -dFIXEDMEDIA -dPDFFitPage   -sOutputFile="mint.CUSTOM.pdf" -c "" -f "mint.pdf"

So, identical calls, just with different sizes in points.

While looking at the verbose info, I noticed that the custom call actually inverted the orientation and caused the script to invert the Width X Height. Not sure if that is relevant, but it is a difference.

   Auto Rotate: PageByPage
   Flip Detect: Wrong orientation detected!
                Inverting Width <-> Height

You can disable flip-detection with -f d. But this only inverts the values of Width and Height and nothing else.

You can also mess with the auto-rotation options to see if it helps.