python: Two items in loop [closed]Reading a controll character in a loop in PythonPython: Combing two...
Not using 's' for he/she/it
Is there any references on the tensor product of presentable (1-)categories?
How do you make your own symbol when Detexify fails?
Biological Blimps: Propulsion
Is aluminum electrical wire used on aircraft?
Open a doc from terminal, but not by its name
On a tidally locked planet, would time be quantized?
Melting point of aspirin, contradicting sources
Terse Method to Swap Lowest for Highest?
Is there a RAID 0 Equivalent for RAM?
Find the Primitive Roots Mod 31
If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Why a symmetric relation is defined: ∀x∀y( xRy⟹yRx) and not ∀x∀y (xRy⟺yRx)?
Travelling outside the UK without a passport
How could a planet have erratic days?
Why should universal income be universal?
Explaining alternative travel routes when going to the USA
Is Witten's Proof of the Positive Mass Theorem Rigorous?
Non-trope happy ending?
The probability of Bus A arriving before Bus B
Does the Location of Line-Dash-Wedge Notations Matter?
How can I block email signup overlays or javascript popups in Safari?
A social experiment. What is the worst that can happen?
python: Two items in loop [closed]
Reading a controll character in a loop in PythonPython: Combing two programs that analyze stringsStreamlined for-loop for comparing two listsMatch two dictionary keys efficiently in PythonExponentiation using while loop in PythonPython list dictionary items round robin mixingProject Euler #4 Python while loop efficiencyAutomatic image cropping in Python 3Determine added, removed and kept items between two listsPython 3 two-sum performance
$begingroup$
I have a script that takes PDF pages (from booklets), copies each one twice and then them in half by cropping the right side and then the left side.
However, I'm only getting one half on both sets
#!/usr/bin/python
# coding=utf-8
import sys
import os
from Quartz import PDFDocument, kPDFDisplayBoxMediaBox, kPDFDisplayBoxTrimBox, CGRectEqualToRect, CGRectMake
from CoreFoundation import NSURL
mediabox = kPDFDisplayBoxMediaBox
trimbox = kPDFDisplayBoxTrimBox
def debooklet(filename):
filename = filename.decode('utf-8')
shortName = os.path.splitext(filename)[0]
outFilename = shortName + " paged.pdf"
pdfURL = NSURL.fileURLWithPath_(filename)
pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
newPDF = PDFDocument.alloc().init()
if pdfDoc:
pages = pdfDoc.pageCount()
for p in range(0, pages):
outPageCount = newPDF.pageCount()
print outPageCount
page = pdfDoc.pageAtIndex_(p)
mediaBoxSize = page.boundsForBox_(mediabox)
halfway = (mediaBoxSize.size.width/2)
pageHeight = mediaBoxSize.size.height
leftHandCrop = CGRectMake(0,0,halfway,pageHeight)
rightHandCrop = CGRectMake(halfway, 0, halfway, pageHeight)
newPDF.insertPage_atIndex_(page, outPageCount)
newPDF.insertPage_atIndex_(page, outPageCount+1)
leftPage = newPDF.pageAtIndex_(outPageCount)
leftPage.setBounds_forBox_(leftHandCrop, mediabox)
rightPage = newPDF.pageAtIndex_(outPageCount+1)
rightPage.setBounds_forBox_(rightHandCrop, mediabox)
newPDF.writeToFile_(outFilename)
if __name__ == '__main__':
for filename in sys.argv[1:]:
debooklet(filename)
So for each page of the source PDF, I create two pages in the new one. Then crop one to the left and one to the right. But I'm only getting one side. Even when I comment out one of the cropping lines, I still get all pages cropped.
python
$endgroup$
closed as off-topic by Ludisposed, Austin Hastings, Jamal♦ Mar 16 at 2:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Ludisposed, Austin Hastings, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have a script that takes PDF pages (from booklets), copies each one twice and then them in half by cropping the right side and then the left side.
However, I'm only getting one half on both sets
#!/usr/bin/python
# coding=utf-8
import sys
import os
from Quartz import PDFDocument, kPDFDisplayBoxMediaBox, kPDFDisplayBoxTrimBox, CGRectEqualToRect, CGRectMake
from CoreFoundation import NSURL
mediabox = kPDFDisplayBoxMediaBox
trimbox = kPDFDisplayBoxTrimBox
def debooklet(filename):
filename = filename.decode('utf-8')
shortName = os.path.splitext(filename)[0]
outFilename = shortName + " paged.pdf"
pdfURL = NSURL.fileURLWithPath_(filename)
pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
newPDF = PDFDocument.alloc().init()
if pdfDoc:
pages = pdfDoc.pageCount()
for p in range(0, pages):
outPageCount = newPDF.pageCount()
print outPageCount
page = pdfDoc.pageAtIndex_(p)
mediaBoxSize = page.boundsForBox_(mediabox)
halfway = (mediaBoxSize.size.width/2)
pageHeight = mediaBoxSize.size.height
leftHandCrop = CGRectMake(0,0,halfway,pageHeight)
rightHandCrop = CGRectMake(halfway, 0, halfway, pageHeight)
newPDF.insertPage_atIndex_(page, outPageCount)
newPDF.insertPage_atIndex_(page, outPageCount+1)
leftPage = newPDF.pageAtIndex_(outPageCount)
leftPage.setBounds_forBox_(leftHandCrop, mediabox)
rightPage = newPDF.pageAtIndex_(outPageCount+1)
rightPage.setBounds_forBox_(rightHandCrop, mediabox)
newPDF.writeToFile_(outFilename)
if __name__ == '__main__':
for filename in sys.argv[1:]:
debooklet(filename)
So for each page of the source PDF, I create two pages in the new one. Then crop one to the left and one to the right. But I'm only getting one side. Even when I comment out one of the cropping lines, I still get all pages cropped.
python
$endgroup$
closed as off-topic by Ludisposed, Austin Hastings, Jamal♦ Mar 16 at 2:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Ludisposed, Austin Hastings, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36
add a comment |
$begingroup$
I have a script that takes PDF pages (from booklets), copies each one twice and then them in half by cropping the right side and then the left side.
However, I'm only getting one half on both sets
#!/usr/bin/python
# coding=utf-8
import sys
import os
from Quartz import PDFDocument, kPDFDisplayBoxMediaBox, kPDFDisplayBoxTrimBox, CGRectEqualToRect, CGRectMake
from CoreFoundation import NSURL
mediabox = kPDFDisplayBoxMediaBox
trimbox = kPDFDisplayBoxTrimBox
def debooklet(filename):
filename = filename.decode('utf-8')
shortName = os.path.splitext(filename)[0]
outFilename = shortName + " paged.pdf"
pdfURL = NSURL.fileURLWithPath_(filename)
pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
newPDF = PDFDocument.alloc().init()
if pdfDoc:
pages = pdfDoc.pageCount()
for p in range(0, pages):
outPageCount = newPDF.pageCount()
print outPageCount
page = pdfDoc.pageAtIndex_(p)
mediaBoxSize = page.boundsForBox_(mediabox)
halfway = (mediaBoxSize.size.width/2)
pageHeight = mediaBoxSize.size.height
leftHandCrop = CGRectMake(0,0,halfway,pageHeight)
rightHandCrop = CGRectMake(halfway, 0, halfway, pageHeight)
newPDF.insertPage_atIndex_(page, outPageCount)
newPDF.insertPage_atIndex_(page, outPageCount+1)
leftPage = newPDF.pageAtIndex_(outPageCount)
leftPage.setBounds_forBox_(leftHandCrop, mediabox)
rightPage = newPDF.pageAtIndex_(outPageCount+1)
rightPage.setBounds_forBox_(rightHandCrop, mediabox)
newPDF.writeToFile_(outFilename)
if __name__ == '__main__':
for filename in sys.argv[1:]:
debooklet(filename)
So for each page of the source PDF, I create two pages in the new one. Then crop one to the left and one to the right. But I'm only getting one side. Even when I comment out one of the cropping lines, I still get all pages cropped.
python
$endgroup$
I have a script that takes PDF pages (from booklets), copies each one twice and then them in half by cropping the right side and then the left side.
However, I'm only getting one half on both sets
#!/usr/bin/python
# coding=utf-8
import sys
import os
from Quartz import PDFDocument, kPDFDisplayBoxMediaBox, kPDFDisplayBoxTrimBox, CGRectEqualToRect, CGRectMake
from CoreFoundation import NSURL
mediabox = kPDFDisplayBoxMediaBox
trimbox = kPDFDisplayBoxTrimBox
def debooklet(filename):
filename = filename.decode('utf-8')
shortName = os.path.splitext(filename)[0]
outFilename = shortName + " paged.pdf"
pdfURL = NSURL.fileURLWithPath_(filename)
pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
newPDF = PDFDocument.alloc().init()
if pdfDoc:
pages = pdfDoc.pageCount()
for p in range(0, pages):
outPageCount = newPDF.pageCount()
print outPageCount
page = pdfDoc.pageAtIndex_(p)
mediaBoxSize = page.boundsForBox_(mediabox)
halfway = (mediaBoxSize.size.width/2)
pageHeight = mediaBoxSize.size.height
leftHandCrop = CGRectMake(0,0,halfway,pageHeight)
rightHandCrop = CGRectMake(halfway, 0, halfway, pageHeight)
newPDF.insertPage_atIndex_(page, outPageCount)
newPDF.insertPage_atIndex_(page, outPageCount+1)
leftPage = newPDF.pageAtIndex_(outPageCount)
leftPage.setBounds_forBox_(leftHandCrop, mediabox)
rightPage = newPDF.pageAtIndex_(outPageCount+1)
rightPage.setBounds_forBox_(rightHandCrop, mediabox)
newPDF.writeToFile_(outFilename)
if __name__ == '__main__':
for filename in sys.argv[1:]:
debooklet(filename)
So for each page of the source PDF, I create two pages in the new one. Then crop one to the left and one to the right. But I'm only getting one side. Even when I comment out one of the cropping lines, I still get all pages cropped.
python
python
asked Mar 15 at 20:39
benwiggybenwiggy
1084
1084
closed as off-topic by Ludisposed, Austin Hastings, Jamal♦ Mar 16 at 2:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Ludisposed, Austin Hastings, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Ludisposed, Austin Hastings, Jamal♦ Mar 16 at 2:09
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Ludisposed, Austin Hastings, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36
add a comment |
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Code Review is for reviews of working code. If you're having trouble getting things to work correctly, consider posting your code on Stack Overflow.
$endgroup$
– Austin Hastings
Mar 15 at 23:36