如何使用pyPdf合并两个横向pdf页面 [英] How to merge two landscape pdf pages using pyPdf

查看:362
本文介绍了如何使用pyPdf合并两个横向pdf页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将两个PDF文件与pyPdf合并.当我运行以下代码时,水印(page1)看起来不错,但是page2已顺时针旋转了90度.

I'm having trouble merging two PDF files with pyPdf. When I run the following code the the watermark (page1) looks fine, but the page2 has been rotated 90 degrees clockwise.

有什么想法吗?

from pyPdf import PdfFileWriter, PdfFileReader

# PDF1: A4 Landscape page created in photoshop using PdfCreator, 
input1 = PdfFileReader(file("base.pdf", "rb"))
page1 = input1.getPage(0)

# PDF2: A4 Landscape page, text only, created using Pisa (www.xhtml2pdf.com)
input2 = PdfFileReader(file("text.pdf", "rb"))
page2 = input2.getPage(0)

# Merge
page1.mergePage(page2)

# Output
output = PdfFileWriter()
output.addPage(page1)
outputStream = file("output.pdf", "wb")
output.write(outputStream)
outputStream.close()

推荐答案

我找到了解决方案.我的代码很好-我只需要更改生成原始PDF文件的方式即可.

I found a solution. My code was fine - I just had to change how I generated the original PDF files.

不是使用PdfCreator& amp;创建PDF. Photoshop,我将我的photoshop图像复制并粘贴到MS Word 2007中,然后使用其导出功能为page1创建PDF文件.现在效果很好!

Instead of creating the PDF using PdfCreator & Photoshop, I copy and pasted my photoshop image into MS Word 2007, and then used it's export feature to create the PDF file for page1. It now works great!

因此,PdfCreator必须生成与pyPdf不兼容的PDF文件.

So, PdfCreator must producing PDF files that are not compatible with pyPdf.

这篇关于如何使用pyPdf合并两个横向pdf页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆