对于iTextSharp的PDF - 如何添加文件附件? [英] iTextSharp for PDF - how add file attachments?

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

问题描述

我使用iTextSharp的创建在C#中的PDF文档。我想其他文件附加到PDF。我在刚刚尝试做这么麻烦的负荷。这里的例子 表现出一定的批注,这显然是附件

I am using iTextSharp to create a PDF document in C#. I would like to attach another file to the PDF. I'm having just loads of trouble trying to do so. The examples here show some annotations, which apparently attachments are.

这是我已经试过:

writer.AddAnnotation(its.pdf.PdfAnnotation.CreateFileAttachment(writer, new iTextSharp.text.Rectangle(100,100,100,100), "File Attachment", its.pdf.PdfFileSpecification.FileExtern(writer, "C:\\test.xml")));



那么,什么情况是它的PDF添加注释(显示为一个小评论声音气球),我不想要的。的test.xml显示在附件在Adobe Reader窗格中,但它无法读取或保存,其文件大小是不明所以很可能是它从来没有被正确安装。

Well, what happens is it does add an annotation on the PDF (appears as a little comment voice balloon), which i don't want. test.xml is shown in the attachments pane in Adobe Reader, but it can't be read or saved, and its file size is unknown so it's likely that it's never being properly attached.

任何建议

推荐答案

好了,我得到了一些代码工作进行安装:

Well, I got some code working to attach it:

its.Document PDFD = new its.Document(its.PageSize.LETTER);
its.pdf.PdfWriter writer;
writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create));
its.pdf.PdfFileSpecification pfs = its.pdf.PdfFileSpecification.FileEmbedded(writer, "C:\\test.xml", "New.xml", null);
writer.AddFileAttachment(pfs);



其中,它的=iTextSharp.text

where "its"="iTextSharp.text"

现在阅读附件!

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

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