iText 7 - Merge PDF layers (OCG) with the base PDF

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

Is it possible to merge layers of a PDF (OCG) with the base PDF to result in a PDF without layers?

I saw that it's possible to accomplish this using an application as Adobe Acrobat DC using a "Flatten Layers" option but I need this programmed in my Java application using iText7.

EDIT:

@joelgeraci has a useful and good answer that solves the previous question, but I have initially some hidden layers that will be displayed anyway when removing the OCProperties from the catalog.

回答1:

You don't actually need to "merge" the layers. All of the layer content is already part of the page content. Layers, or more properly Optional Content Groups, are sets of instructions that the viewer can either draw or not, depending on the settings, for viewers that don't support layers, they just all show. To "flatten" the layers, you just need to modify the PDF so that the viewer doesn't think there is any optional content. The easiest way is to delete the OCProperties dictionary from the Catalog. Once you have the catalog object, use "remove" passing the name of the OCPropreties dictionary.

catalog.remove(PdfName.OCPROPERTIES) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!