Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6325771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:57:28+00:00 2026-05-24T16:57:28+00:00

Update: Thanks to stardt whose script works! The pdf is a page of another

  • 0

Update: Thanks to stardt whose script works! The pdf is a page of another one. I tried the script on the other one, and it also correctly spit each pdf page, but the order of page numbers is sometimes right and sometimes wrong. For example, in page 25-28 of the pdf file, the printed page numbers are 14, 15, 17, are 16. I was wondering why? The entire pdf can be downloaded from http://download304.mediafire.com/u6ewhjt77lzg/bgf8uzvxatckycn/3.pdf

Original: I have a scanned pdf, where two paper pages sit side by side in a pdf page. I would like to split the pdf page into two, with the original left half becoming the earlier of the two new pdf pages. The pdf looks like enter image description here.

Here is my Python script named un2up inspired by Gilles:

#!/usr/bin/env python
import copy, sys
from pyPdf import PdfFileWriter, PdfFileReader
input = PdfFileReader(sys.stdin)
output = PdfFileWriter()
for p in [input.getPage(i) for i in range(0,input.getNumPages())]:
    q = copy.copy(p)
    (w, h) = p.mediaBox.upperRight

    p.mediaBox.upperLeft = (0, h/2)
    p.mediaBox.upperRight = (w, h/2)
    p.mediaBox.lowerRight = (w, 0)
    p.mediaBox.lowerLeft = (0, 0)

    q.mediaBox.upperLeft = (0, h)
    q.mediaBox.upperRight = (w, h)
    q.mediaBox.lowerRight = (w, h/2)
    q.mediaBox.lowerLeft = (0, h/2)

    output.addPage(q)
    output.addPage(p)
output.write(sys.stdout)

I tried the script on a pdf in terminal with command being un2up < page.pdf > out.pdf, but the output out.pdf is not correctly split.

I also checked the values of variables w and h, the output of p.mediaBox.upperRight, and they are 514 and 1224 which don’t look right based on their actual ratio.

The file can be downloaded from http://download851.mediafire.com/bdr4sv7v5nzg/raci13ct5w4c86j/page.pdf.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:57:29+00:00Added an answer on May 24, 2026 at 4:57 pm

    Your code assumes that p.mediaBox.lowerLeft is (0,0) but it is actually (0, 497)

    This works for the file you provided:

    #!/usr/bin/env python
    import copy, sys
    from pyPdf import PdfFileWriter, PdfFileReader
    input = PdfFileReader(sys.stdin)
    output = PdfFileWriter()
    for i in range(input.getNumPages()):
        p = input.getPage(i)
        q = copy.copy(p)
    
        bl = p.mediaBox.lowerLeft
        ur = p.mediaBox.upperRight
    
        print >> sys.stderr, 'splitting page',i
        print >> sys.stderr, '\tlowerLeft:',p.mediaBox.lowerLeft
        print >> sys.stderr, '\tupperRight:',p.mediaBox.upperRight
    
        p.mediaBox.upperRight = (ur[0], (bl[1]+ur[1])/2)
        p.mediaBox.lowerLeft = bl
    
        q.mediaBox.upperRight = ur
        q.mediaBox.lowerLeft = (bl[0], (bl[1]+ur[1])/2)
        if i%2==0:
            output.addPage(q)
            output.addPage(p)
        else:
            output.addPage(p)
            output.addPage(q)
    
    output.write(sys.stdout)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update Thanks to Marc's help the AlphaPagedList class is now available on CodePlex if
Update: Thanks guys, I didn't realize it was very close to zero but not
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find
UPDATE: Thanks for all your help guys! I just need to take a litte
I am using DBIx::Class and I would like to only update one row in
I have a update panel with a gridview inside. The gridview works fine when
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
I have a table which PolygonMapping whose register contains a polygon id and other
Update: Is there a way to achieve what I'm trying to do in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.