KTUGFaq
KTUG FAQ
FrontPage › pyPDF
- ȨÆäÀÌÁö
- PDFÆÄÀÏÀ» ¹ÝÀ¸·Î ÀÚ¸£´Â ¹æ¹ý(without Acrobat)
- ¸ñÀû : Workshop/2008Spring¿¡¼ ÀÌÁÖÈ£´ÔÀÌ Acrobat Professional·Î º¸¿©ÁØ ¹æ¹ýÀ» ÃÖ´ëÇÑ ½±°Ô(?) ÇÁ·Î±×·¥À¸·Î ÇØ°áÇغ»´Ù.
- ÃÖÁ¾¼Ò½º document1.pdf¹®¼¸¦ document-output.pdf·Î ¸¸µé¾îÁÝ´Ï´Ù.
- ¸ðµç ÆäÀÌÁö¸¦ ¹ÝÀ¸·Î ÀÚ¸¨´Ï´Ù.
- ùÆäÀÌÁöÀÇ ¿À¸¥ÂÊ ¹Ý Áï 2page°¡ ½ÇÁ¦·Î´Â ¸¶Áö¸· ÆäÀÌÁö°¡ µÇ¾î¾ß ÇÕ´Ï´Ù.
- Acrobat ProfessionalÀº Crop Box¸¦ º¯°æÇÏÁö¸¸ ±×³É Media Boxº¯°æÇß½À´Ï´Ù.
- ¼Ò½º
#!/usr/bin/env python from pyPdf import PdfFileWriter, PdfFileReader output = PdfFileWriter() inputleft = PdfFileReader(file("document1.pdf", "rb")) inputright = PdfFileReader(file("document1.pdf", "rb")) def LeftHalfPage(p): p.mediaBox.upperRight = ( p.mediaBox.getUpperRight_x() / 2, p.mediaBox.getUpperRight_y() ) return p def RightHalfPage(p): p.mediaBox.lowerLeft = ( p.mediaBox.getUpperRight_x() / 2, p.mediaBox.getLowerLeft_y() ) return p ########################################################### output.addPage(LeftHalfPage(inputleft.getPage(0))) endPage = RightHalfPage(inputright.getPage(0)) for i in range(1, inputleft.getNumPages()): output.addPage(LeftHalfPage(inputleft.getPage(i))) output.addPage(RightHalfPage(inputright.getPage(i))) output.addPage(endPage) # print how many pages input1 has: print "document1.pdf has %s pages." % inputleft.getNumPages() # finally, write "output" to document-output.pdf outputStream = file("document-output.pdf", "wb") output.write(outputStream) outputStream.close()