[英]Python - create a multi-layered PDF
Is there a way to use Python to create a multiple layers PDF. 有没有一种方法可以使用Python创建多层PDF。 But not merge.
但不能合并。
I think the multiple layers PDF means there is more than one layers in a page and I can select which layer to show in Acrobat. 我认为多层PDF意味着页面中不止一层,我可以选择在Acrobat中显示哪一层。
Here is a document I find about layered PDF: http://www.open.ac.uk/opencetl/files/opencetl/file/ecms/web-content/Multi-pdf-how-to-%20file.pdf 这是我发现的有关分层PDF的文档: http : //www.open.ac.uk/opencetl/files/opencetl/file/ecms/web-content/Multi-pdf-how-to-%20file.pdf
And an example of layered PDF: http://www.talkgraphics.com/attachment.php?s=1901864ddbe7b63f672440daffc3907e&attachmentid=76844&d=1285324919 还有一个分层PDF的示例: http ://www.talkgraphics.com/attachment.php?s = 1901864ddbe7b63f672440daffc3907e&attachmentid = 76844&d= 1285324919
You can use PyPDF2 to overlay pages from different PDF files, producing another PDF file that is not flattened. 您可以使用PyPDF2覆盖来自不同PDF文件的页面,从而生成另一个不会展平的PDF文件。
You can find a good example adding a watermark here . 您可以在此处找到添加水印的好示例。 Take a look at the example and explanation in the "Overlaying Pages" section.
查看“覆盖页面”部分中的示例和说明。
From what I can tell, neither Reportlab nor Pypdf have mechanisms to create the blocks of marked content necessary to implement layers (or Optional Content Groups). 据我所知,Reportlab和Pypdf都没有机制来创建实现层(或可选内容组)所必需的标记内容块。
I have created such using IronPython and Datalogics .Net interface to APDFL. 我已经使用IronPDF和Datalogics .Net界面创建了APDFL。 There is also a Java interface, so you could do the same with Jython.
还有一个Java接口,因此您可以使用Jython进行相同的操作。
The technique is basically that you create an OptionalContentGroup for your layer, you then add the content that you want in your layer to a container, and you set the Container's OptionalContentMembershipDict to an OptionalContentMemberDict that connects the two. 该技术基本上是为图层创建一个OptionalContentGroup,然后将图层中所需的内容添加到容器中,然后将Container的OptionalContentMembershipDict设置为连接两者的OptionalContentMemberDict。
ocg = PDFL.OptionalContentGroup(doc,"Labels")
doc.DefaultOptionalContentConfig.Order.Insert(0,PDFL.OptionalContentOrderLeaf(ocg))
labelContainer.OptionalContentMembershipDict = PDFL.OptionalContentMembershipDict(doc,[ocg,],PDFL.VisibilityPolicy.AnyOn)
Where labelContainer is a Container Element I had added to the Content of my page. 其中labelContainer是我添加到页面内容中的容器元素。
Disclosure: I work for Datalogics. 披露:我为Datalogics工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.