Skip to content

cropbox + fit-to-page + flip gives square output #52

@openendings

Description

@openendings

Version: 2.6.3
OS: Termux, 6.1.99-android14-11-gd7dac4b14270-ab12946699

A combination of --no-fit-to-page -r A4 -c A4 and landscape input (or -f f) results in a square 595×595pt output (instead of 842×595).
Notably, the Ghostscript call contains

  • -dDEVICEWIDTHPOINTS=842 -dDEVICEHEIGHTPOINTS=595 and
  • -c "<</EndPage {0 eq {[/CropBox [0 0 595 842] /PAGE pdfmark true}{false}ifelse}>> setpagedevice"

Steps:

  1. Begin with some landscape, smaller-than-A4 PDF. (I used a 708.661 x 538.583 pts sewing pattern.)
  2. Convert to A4 with options --no-fit-to-page -r A4 -c A4
    (The same seems to happen if -f f is added.)

Expected:

  • output PDF is 842×595, unscaled

Actual:

  • output PDF is 595×595, unscaled

Example

[The $DIRs are substituted to hide some personal info.]

+ /data/data/com.termux/files/home/dev/pdfScale/pdfScale.sh -v --gs-call --no-fit-to-page -r A4 -c A4 $DIR/document.pdf $DIR/tmp.pdf
pdfScale.sh v2.6.3 - Verbose Execution
   Single Task: Resize PDF Paper
       Dry-Run: FALSE
    Input File: $DIR/document.pdf
   Output File: $DIR/tmp.pdf
   Explode PDF: Disabled
 Get Page Size: Adaptive Enabled
        Method: Grep
                Failed, trying next method
        Method: PDFInfo
    Page Range: None (all pages)
  Source Width: 709 postscript-points
 Source Height: 539 postscript-points
    Print Mode: Print ( auto/empty )
  Scale Factor: Disabled (resize only)
   Fit To Page: Disabled (manual)
   Auto Rotate: PageByPage
   Flip Detect: Wrong orientation detected!
                Inverting Width <-> Height
  Run Resizing: A4 ( 842 x 595 ) pts
 Cropbox Reset: A4 ( 595 x 842 ) pts
  Final Status: Succeeded with Warnings
-------------------------------------------------
Ghostscript Debug Info:
GPL Ghostscript 10.02.0: PDFDocEncoding e is undefined
[GS RESIZE CALL STARTS]
"/data/data/com.termux/files/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=842 -dDEVICEHEIGHTPOINTS=595 -dAutoRotatePages=/PageByPage -dFIXEDMEDIA     -sOutputFile="$DIR/tmp.pdf" -c "<</EndPage {0 eq {[/CropBox [0 0 595 842] /PAGE pdfmark true}{false}ifelse}>> setpagedevice" -f "$DIR/document.pdf"
[GS RESIZE CALL ENDS]

Input dimensions

+ pdfinfo $DIR/document.pdf       

Title:           [REDACTED]
Creator:         Adobe Illustrator 29.5 (Macintosh)
Producer:        Adobe PDF library 17.00
CreationDate:    Sun Jun 15 16:50:07 2025 AEST
ModDate:         Sun Jun 15 16:50:07 2025 AEST
Custom Metadata: no
Metadata Stream: yes
Tagged:          no
UserProperties:  no
Suspects:        no
Form:            none
JavaScript:      no
Pages:           21
Encrypted:       yes (print:yes copy:yes change:yes addNotes:yes algorithm:AES)
Page size:       708.661 x 538.583 pts
Page rot:        0
File size:       966776 bytes
Optimized:       no
PDF version:     1.6

Output:

+ pdfinfo $DIR/tmp.pdf

Title:           [REDACTED]
Creator:         Adobe Illustrator 29.5 (Macintosh)&Â<™<�ãœY±\—o`·6_‘BLÀ,Ä%l˛WA‡‚
Producer:        GPL Ghostscript 10.02.0
CreationDate:    Thu Jul  3 11:05:16 2025 AEST
ModDate:         Thu Jul  3 11:05:16 2025 AEST
Custom Metadata: no
Metadata Stream: no
Tagged:          no
UserProperties:  no
Suspects:        no
Form:            none
JavaScript:      no
Pages:           21
Encrypted:       no
Page size:       595 x 595 pts
Page rot:        0
File size:       181399 bytes
Optimized:       no
PDF version:     1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions