将文件附加到 PDF [英] Attaching files to a PDF

查看:73
本文介绍了将文件附加到 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将文件附加到我在运行时生成的 PDF.

I am struggling with attaching files to a PDF that I am generating at runtime.

我在 MVC 框架中使用 C# ASP.net.我最初使用 ABCpdf 从 HTML 视图创建了 PDF,但后来我意识到,我还需要将文件附加到 PDF.我改用 iText 并设法使用 iTextSharp for PDF - 如何添加文件附件?

I'm using C# ASP.net in the MVC framework. I originally created the PDF using ABCpdf from a HTML View but I then realised, I also needed to attach files to the PDF. I switched to using iText and I have managed to attach a file to the PDF using the solution at iTextSharp for PDF - how add file attachments?

我现在遇到的问题是我似乎无法将这些附件作为 PDF 中的链接引用.

The problem I have now is that I can't seem to reference these attachments as links within the PDF.

iText in Action"一书建议我可以使用注释或文档级附件.不过,我觉得这本书不容易理解,代码也不容易理解.互联网上的文章似乎也缺乏这方面的帮助,但很抱歉我错过了任何东西.

The "iText in Action" book suggests I can use annotations or document level attachments. I don't find the book easy to follow or the code easy to understand though. There also seems to be scarce help on this around in the way of articles on the internet but apologies is I have missed anything.

这是我第一次在这里提问,如果我做错了,我深表歉意.

This is the first time I have asked a question here so my apologies if I have done this incorrectly.

推荐答案

很抱歉你不喜欢我的书.

I'm sorry you didn't like my book.

你读过第 16 章了吗?您想将文件作为文档级附件嵌入,如下所示:

Did you read chapter 16? You want to embed a file as a document-level attachment like this:

PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(writer, ... );
fs.AddDescription("specificname", false);
writer.AddFileAttachment(fs);

在文档内,您想要创建一个链接,以打开以关键字特定名称"描述的 PDF 文档.这是通过一个动作完成的:

Inside the document, you want to create a link to that opens the PDF document described with the keyword "specificname". This is done through an action:

PdfTargetDictionary target = new PdfTargetDictionary(true);
target.EmbeddedFileName = "specificname";
PdfDestination dest = new PdfDestination(PdfDestination.FIT);
dest.AddFirst(new PdfNumber(1));
PdfAction action = PdfAction.GotoEmbedded(null, target, dest, true);

您可以将此操作用于注释、块等...例如:

You can use this action for an annotation, a Chunk, etc... For instance:

Chunk chunk = new Chunk(" (see info)");
chunk.SetAction(action);

认为这适用于任何附件是一种常见的误解.但是,ISO-32000-1 非常清楚 GotoE(mbedded) 功能:

It is a common misconception to think that this will work for any attachment. However, ISO-32000-1 is very clear about the GotoE(mbedded) functionality:

12.6.4.4 嵌入式 Go-To 操作嵌入式转到操作 (PDF 1.6) 类似于远程转到操作但允许跳转到或从嵌入在另一个 PDF 文件中的 PDF 文件(参见 7.11.4,嵌入式文件流").流").

12.6.4.4 Embedded Go-To Actions An embedded go-to action (PDF 1.6) is similar to a remote go-to action but allows jumping to or from a PDF file that is embedded in another PDF file (see 7.11.4, "Embedded File Streams"). Streams").

如果您想询问我想将任何文件(例如 Docx、jpg、... 文件)附加到我的 PDF 并向 PDF 添加操作以在单击链接时打开此类文件",那么您问的是 PDF 规范中不支持的内容.

If you meant to ask "I want to attach any file (such as a Docx, jpg,... file) to my PDF and add an action to the PDF that opens such a file upon clicking a link," then you're asking something that isn't supported in the PDF specification.

请随意阅读 ISO-32000-1.如果你不理解我的书,你将不得不做额外的努力来尝试阅读 PDF 标准......

Feel free to read ISO-32000-1. If you didn't understand my book, you'll have to do an extra effort trying to read the PDF standard...

这篇关于将文件附加到 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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