简体   繁体   English

Python-创建多层PDF

[英]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.

相关问题 在python中,如何解析多层JSON? - In python, how to parse a multi-layered JSON? Python中的多处理多层图像合并 - Multiprocessing multi-layered image merging in Python 没有[href]的多层网站上的Python网络抓取 - Python web-scraping on a multi-layered website without [href] grep多层迭代匹配的字符串(Python) - Grep multi-layered iterable for strings that match (Python) 按多层元组的多层元素排序 - Python - Sort by elements in multiple layers of multi-layered tuple - Python 如何更新两层多层感知器中的学习率? - How to update the learning rate in a two layered multi-layered perceptron? 使用 Python pandas 将具有逗号值的字符串转换为多层索引的单独行 - Turning a string with comma values into individual rows of a multi-layered index with Python pandas 创建可访问每一层变量的多层Python类 - Creating multi-layered Python classes with access to variables within each layer 多层bidirectional_dynamic_rnn:与MultiRNNCell不兼容? - Multi-layered bidirectional_dynamic_rnn: incompatible with MultiRNNCell? 关于Tensorflow中的多层双向RNN的困惑 - Confused about multi-layered Bidirectional RNN in Tensorflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM