-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure when set cropbox with mediabox negative value #2736
Comments
There is a wrong check for rectangle containment - which will be corrected. You can already now use the low-level API as a circumvention and do this Please note that here you must use PDF geometry for the coordinates, which means point (x0, y0) specifies the lower-left and (x1, y1) the upper-right corner. Also observe that the desired value is contained in a string and must be provided exactly as shown. There also is no plausibility check, so this is on your own risk. After the fix, a session changing the CropBox (and friends) may look like this: import fitz
doc=fitz.open()
page=doc.new_page()
page.xref
4
# fake a MediaBox for demo purposes
doc.xref_set_key(4, "MediaBox", "[-30 -20 595 842]")
page.cropbox # default: MediaBox, but in MuPDF geometry!
Rect(-30.0, 0.0, 595.0, 862.0)
page.rect # equals th (shifted) CropBox : top-left = (0, 0)
Rect(0.0, 0.0, 625.0, 862.0)
# change the CropBox: shift by (10, 10) in both dimensions. Please note:
# To achieve this, 10 must be subtracted from 862! yo must never be negative!
page.set_cropbox(fitz.Rect(-20.0, 0.0, 595.0, 852.0))
# Confirm how page object looks like.
# Note the `-10` in the y0 coordinate.
print(doc.xref_object(4))
<<
/Type /Page
/MediaBox [ -30 -20 595 842 ]
/Rotate 0
/Resources 3 0 R
/Parent 2 0 R
/CropBox [ -20 -10 595 842 ]
>>
page.rect # and also look at the page rectangle
Rect(0.0, 0.0, 615.0, 852.0) |
Fixed in 1.23.7. |
Problem with setcropbox when mediabox have negative value
I want to set cropbox of a pdf file where mediabox is :
fitz page mediabox : Rect(-106.673, -362.691, 762.869, 1305.062)
Want To CropBox set To : -25.54 -294.47 415.66 971.34
I've got this error : ValueError: rect not in mediabox
I send you complete example python and pdf file
prblem_crop_pymupdf.zip
The text was updated successfully, but these errors were encountered: