开发者

Add an anchor to an attached file in ITextSharp

开发者 https://www.devze.com 2023-02-01 21:31 出处:网络
I was able to add an attachment to my PDF: PdfFileSpecification specification = PdfFileSpecification.FileEmbedded(writer, name, name, null);

I was able to add an attachment to my PDF:

 PdfFileSpecification specification = PdfFileSpecification.FileEmbedded(writer, name, name, null);
 writer.AddFileAttachment(specificat开发者_运维百科ion);

But now I would like to add something like a reference to this file in the text of my PDF. Is it possible that if a click that "link" the file is opened?

===EDIT===

According to the answer i also tried the following:

PdfFileSpecification specification = PdfFileSpecification.FileEmbedded(writer, name, name, null);
PdfAnnotation annotation = PdfAnnotation.CreateFileAttachment(writer, new iTextSharp.text.Rectangle(100, 200), "Link", specification);
chapter1.Add(annotation);

This adds the file to the document, and also writes the filename to the document, but it's not linked.


PDF supports "embedded go-to actions" for PDFs within PDFs. If you're embedded file isn't a PDF, that won't work... and it doesn't look like iText supports them at a higher level. You'd have to mess with the PdfAction's dictionary directly. Given that your previous question was about an audio file, I'm going to guess "no, that won't work".

PDF also supports "embedded file annotations". As does iText. PdfAnnotation.createFileAttachment(). One of the overrides takes a PdfFileSpecification.

Clicking on an embedded file annot gives the user the option to open the file or save it. I think that's as close as you're gonna get.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号