iText - 可点击的图片应该打开ms word附件 [英] iText - clickable image should open ms word attachment

查看:202
本文介绍了iText - 可点击的图片应该打开ms word附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使图像可单击以便打开附加的ms word文档?我在这里有一些PDF文件,其中有一些图像(图标下方带有ms文件名的ms字图标),通过点击图像打开附加的ms word文档,我想知道如何使用iText库执行此操作。我可以添加图像并附加ms word文档,但我还没弄清楚如何应用somwthing就像一个动作(GoToE似乎只适用于PDF附件)或链接?

How can I make an image clickable so the attached ms word document opens? I have some PDFs here where there are some images (ms word icon with the ms word file name beneath the icon) which open the attached ms word document by clicking on the images and I wondered how can I do this with the iText library. I can add the images and attach the ms word documents but I haven't figured out how I can apply somwthing like an action (GoToE seems only available for PDF attachments) or a link?

推荐答案

请查看ISO-32000-1中的第12.6.4.4节(即PDF规范)。该部分标题为嵌入式转到行动:

Please take a look at section 12.6.4.4 in ISO-32000-1 (that is the PDF specification). That section is titled "Embedded Go-To Actions":

正如您所知,您描述的行为是按规范进行的。 GoToE 操作用于跳转并形成嵌入另一个PDF文件的PDF文件。不支持其他文档格式,因为。

As you've found out, the behavior you describe is by specification. The GoToE action is for jumping to and form a PDF file that is embedded in another PDF file. Other document formats aren't supported because.

您唯一的选择是引入文件附件注释而不是嵌入式文件以及GoToE操作。例如,参见 FileAttachmentAnnot 示例:

Your only option is to introduce a file attachment annotation instead of an Embedded file along with a GoToE action. See for instance the FileAttachmentAnnot example:

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    Rectangle rect = new Rectangle(36, 700, 136, 800);
    PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(
            writer, PATH, "test.docx", null);
    PdfAnnotation attachment =
            PdfAnnotation.createFileAttachment(writer, rect, "Click me" , fs);
    PdfAppearance app = writer.getDirectContent().createAppearance(100, 100);
    Image img = Image.getInstance(IMG);
    img.scaleAbsolute(100, 100);
    img.setAbsolutePosition(0, 0);
    app.addImage(img);
    attachment.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
    writer.addAnnotation(attachment);
    document.close();
}

在这个例子中,我们创建一个 PdfAnnotation 我们为此注释定义了自定义外观(而不是引脚或回形针符号)。我用了一张图片,因为这就是你想要的东西。查看结果此处(这适用于Adobe Reader,但不适用于所有PDF观众支持这个)。

In this example, we create a PdfAnnotation and we define a custom appearance for this annotation (instead of the pin or the paperclip symbol). I used an image because that's what you seem to want. Check out the result here (this works with Adobe Reader, but not all PDF viewers support this).

这篇关于iText - 可点击的图片应该打开ms word附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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