2009年12月24日 星期四 16:04
各位好: 本人是python新人,正在看的书是"python学习手册",没有做过什么实用的课题。 近日,有朋友需要把2个PDF文件的部分合并在一起。网上google了半天,也没有找到能看懂的例子。 希望各位行者大侠帮助。 小白努力中。。。。。。。。。。。 [?] 卫东 GEEK WEI 13910976071 E-mail:weidongdongs在gmail.com 技客电脑小组 www.geekcare.cn -------------- 下一部分 -------------- 一个HTML附件被移除... URL: <http://www.zeuux.org/pipermail/zeuux-python/attachments/20091224/03f2cfef/attachment.html> -------------- 下一部分 -------------- A non-text attachment was scrubbed... Name: 不可用 Type: image/gif Size: 103 bytes Desc: 不可用 URL: <http://www.zeuux.org/pipermail/zeuux-python/attachments/20091224/03f2cfef/attachment.gif>
2009年12月24日 星期四 17:04
给你一个函数,直接写你的输入文件输出文件路径吧
def mergePdf(frompaths,topath):
"""
@type frompaths: list or tuple
@param frompaths: 所有pdf存放的路径
@param topath: 目标pdf文件路径
@example:
>>> mergePdf(['/var/files/1.pdf,/var/files2.pdf'],'/tmp/12.pdf')
"""
from pyPdf import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
for pdfpath in frompaths:
input = PdfFileReader(file(pdfpath,"rb"))
# 跳过加密pdf
if input.isEncrypted == True
continue
# 获得源pdf文件中页面总数
pagecount=input.getNumPages()
# 分别将page添加到输出output中
for i in range(0,pagecount):
output.addPage(input.getPage(i))
outStream = file(topath,"wb")
output.write(outStream)
outStream.close()
2009/12/24 Dong Wei <weidongdongs在gmail.com>
>
> 各位好:
>
> 本人是python新人,正在看的书是"python学习手册",没有做过什么实用的课题。
> 近日,有朋友需要把2个PDF文件的部分合并在一起。网上google了半天,也没有找到能看懂的例子。
> 希望各位行者大侠帮助。
>
> 小白努力中。。。。。。。。。。。
>
> [?]
> 卫东 GEEK WEI
> 13910976071
> E-mail:weidongdongs在gmail.com
>
> 技客电脑小组
> www.geekcare.cn
>
>
>
>
> _______________________________________________
> zeuux-python mailing list
> zeuux-python在zeuux.org
> http://www.zeuux.org/mailman/listinfo/zeuux-python
>
>
--
News about me: http://www.feedmagnet.com/youngking/news/
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: <http://www.zeuux.org/pipermail/zeuux-python/attachments/20091224/f8383148/attachment.html>
-------------- 下一部分 --------------
A non-text attachment was scrubbed...
Name: 不可用
Type: image/gif
Size: 103 bytes
Desc: 不可用
URL: <http://www.zeuux.org/pipermail/zeuux-python/attachments/20091224/f8383148/attachment.gif>
Zeuux © 2025
京ICP备05028076号