如何将Type 3 Font中编写的文本从一个pdf移动到另一个pdf? [英] How to move text written in Type 3 Font from one pdf to other pdf?

查看:668
本文介绍了如何将Type 3 Font中编写的文本从一个pdf移动到另一个pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pdf,其中包含用Type 3 Font编写的文本。

I have a pdf which include text written in Type 3 Font.

我想从中获取一些文本并将其写入完全相同形状的其他pdf中。

I want to get some text from it and write it into other pdf in exactly same shape.

我正在使用itext。请给我一个提示。

I am using itext. Please give me a tip.

编辑:我附上了我的代码。

edit: I attached my code.

DocumentFont f = renderInfo.getFont(); 
String str = renderInfo.getText();
x = renderInfo.getBaseline().getStartPoint().get(Vector.I1);

在这段代码中,我想将str写入x值位置。
在类型3字体中,它是否有效?

In this code, I want to write str into x value position. In Type 3 Font, is it work?

推荐答案

您可以使用一个页面的一部分复制到一个新页面像这样的代码:

You can copy parts of one page to a new one using code like this:

    InputStream resourceStream = getClass().getResourceAsStream("from.pdf");
    PdfReader reader = new PdfReader(new FileOutputStream("from.pdf"));
    Rectangle pagesize = reader.getPageSizeWithRotation(1);
    Document document = new Document(pagesize);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("areaOfFrom.pdf"));
    document.open();

    PdfContentByte content = writer.getDirectContent();
    PdfImportedPage page = writer.getImportedPage(reader, 1);

    content.saveState();
    content.rectangle(0, 350, 360, 475);
    content.clip();
    content.newPath();
    content.addTemplate(page, 0, 0);
    content.restoreState();

    document.close();
    reader.close();

这会变成你的

进入

不幸的是,隐藏的内容仅仅是...... 隐藏 ......但它仍然存在。您可以特别用隐藏文字标记线条并尝试复制并粘贴它们。

Unfortunately, though, that hidden content is merely... hidden... but it is still there. You can especially mark the lines with that hidden text and try to copy&paste them.

如果您想要完全删除隐藏文本(或者仅仅通过复制所需文本),您必须检查导入页面的内容并过滤它。我担心iText还没有明确支持这样的东西。它可以使用iText低级API完成,但这是相当有用的。

If you want to completely remove that hidden text (or start out by merely copying the desired text), you have to inspect the content of the imported page and filter it. I'm afraid iText does not yet explicitly support something like that. It can be done using the iText lowlevel API but it is quite some work.

这篇关于如何将Type 3 Font中编写的文本从一个pdf移动到另一个pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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