| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
13年前发布

PDF文件生成Python工具包 pyPdf

     <p><em>PyPDF</em>这是一个用于构建PDF的纯Python工具包 。它能够实现:</p>    <ul>     <li>抽取文档信息(标题,作者等),</li>     <li>逐页页分割文档</li>     <li>逐页合并文档</li>     <li>裁剪页面,</li>     <li>合并多页成单页,</li>     <li>加密和解密PDF文件</li>    </ul>    <p>下面是一段使用的代码:</p>    <pre class="brush:python; toolbar: true; auto-links: false;">from pyPdf import PdfFileWriter, PdfFileReader  output = PdfFileWriter() input1 = PdfFileReader(file("document1.pdf", "rb"))  # print the title of document1.pdf print "title = %s" % (input1.getDocumentInfo().title)  # add page 1 from input1 to output document, unchanged output.addPage(input1.getPage(0))  # add page 2 from input1, but rotated clockwise 90 degrees output.addPage(input1.getPage(1).rotateClockwise(90))  # add page 3 from input1, rotated the other way: output.addPage(input1.getPage(2).rotateCounterClockwise(90)) # alt: output.addPage(input1.getPage(2).rotateClockwise(270))  # add page 4 from input1, but first add a watermark from another pdf: page4 = input1.getPage(3) watermark = PdfFileReader(file("watermark.pdf", "rb")) page4.mergePage(watermark.getPage(0))  # add page 5 from input1, but crop it to half size: page5 = input1.getPage(4) page5.mediaBox.upperRight = (     page5.mediaBox.getUpperRight_x() / 2,     page5.mediaBox.getUpperRight_y() / 2 ) output.addPage(page5)  # print how many pages input1 has: print "document1.pdf has %s pages." % input1.getNumPages()  # finally, write "output" to document-output.pdf outputStream = file("document-output.pdf", "wb") output.write(outputStream) outputStream.close()</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326706123515" target="_blank">http://www.open-open.com/lib/view/home/1326706123515</a></p>    <p></p>     
 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1326706123515.html
PHP PDF工具包