IText在PDF上编辑或删除图层 [英] IText edit or remove the layer on PDF

查看:1876
本文介绍了IText在PDF上编辑或删除图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H全部,

我正在使用IText在PDF上添加文本图层。
现在我想编辑PDF上的现有图层,图层也仅由IText创建。似乎IText没有这样的方法来支持。

I am Using IText for adding text layers on PDF. Now i want to edit the existing layers on the PDF, layers are also created by IText only. Seems IText dont have such methods to suppport.

我想到的另一种方法是删除现有的Layer并在其位置放置新层。 IText也不支持似乎删除。谢谢这些吗?

I thought of other way around is remove existing Layer and place new layer on its place. Seems remove also not supported by IText. Any way todo these?

谢谢你们。

推荐答案

As在评论中,有问题的图层是iText确实称之为图层的图层,但实际上PDF版本的内容被称为可选内容组。

As it turned out in comments, the layers in question are what iText indeed calls layers but what actually in PDF lingo is called optional content groups.

确实有一个实用程序类用于在iText Xtra包中删除这些层(不是extrajars,而是itext-xtra.jar): com.itextpdf.text.pdf.ocg.OCGRemover 使用类 OCGParser 在同一个包中。

There indeed is a utility class for removing such layers in the iText Xtra package (not the extrajars, but itext-xtra.jar): com.itextpdf.text.pdf.ocg.OCGRemover which makes use of the class OCGParser in the same package.

/**
 * Class that knows how to remove OCG layers.
 */
public class OCGRemover
{
    /**
     * Removes layers from a PDF document
     * @param reader    a PdfReader containing a PDF document
     * @param layers    a sequence of names of OCG layers
     * @throws IOException
     */
    public void removeLayers(PdfReader reader, String... layers) throws IOException
    [...]
}

将该方法应用于<$ c后$ c> PdfReader 你显然必须保存更改,例如通过 PdfStamper。

After applying that method to a PdfReader you obviously have to save the changes, e.g. by means of a PdfStamper.

这篇关于IText在PDF上编辑或删除图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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