Skip to content

Some areas are not visible after I converted to standard A4 size, how to solve it? I want to get a full A4 pdf with correct page orientation and fully fill the A4 page without white margins. #4083

Closed Answered by JorjMcKie
nissansz asked this question in Q&A
Discussion options

You must be logged in to vote

The following 10-line script does the job:

import sys, pymupdf

src = pymupdf.open(sys.argv[1])  # file to be reformatted to A4
out = pymupdf.open()  # result file
for spage in src:  # walk through input pages
    spage.remove_rotation()  # remove rotation - keeping visual appearance
    page = out.new_page()  # make A4 output page
    # insert source page content, appropriately scaled to full A4
    page.show_pdf_page(page.rect, src, spage.number)
out.ez_save(src.name + "-reformatted.pdf")

Because your example file pages have an aspect ratio different from sqrt(2):1, white borders result left and right. Specify keep_proportion=False to stretch.

Replies: 5 comments 13 replies

Comment options

You must be logged in to vote
1 reply
@nissansz
Comment options

Answer selected by JorjMcKie
Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Comment options

You must be logged in to vote
2 replies
@nissansz
Comment options

@JorjMcKie
Comment options

Comment options

You must be logged in to vote
8 replies
@JorjMcKie
Comment options

@nissansz
Comment options

@JorjMcKie
Comment options

@nissansz
Comment options

@nissansz
Comment options

Comment options

You must be logged in to vote
1 reply
@nissansz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants