本文介绍了iTextSharp - 如何打开/读取/提取文件附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些PDF全部带有两个附带静态名称的文件。我想使用iTextSharp将这些文件解压缩到临时目录,以便我可以进一步使用它们。我尝试按照教程,但我遇到了问题 iTextSharp.text.pdf.PdfReader 没有 getCatalog()方法,如下面的示例所示。

I have some PDF's all with two attached files with static names. I would like to use iTextSharp to extract these files to a temp directory so that I can work with them further. I tried following the tutorial here but I ran into problems when the iTextSharp.text.pdf.PdfReader didn't have a getCatalog() method as shown in the bottom example.

关于如何提取附件的任何建议?让我们简单地说PDF文档位于C:\ test.pdf,两个附件存储为attach1.xml和attach2.xml。

Any advice on how I can extract the attachments? Let's just say for ease that the PDF document is at "C:\test.pdf" and the two attachments are stored as "attach1.xml" and "attach2.xml".

推荐答案

我最终找到了一种方法 - 尽管不是完全以编程方式。我添加了一个名为pdftk.exe的二进制文件,它是PDF ToolKit,它具有提取附件的命令行选项。

I ended up finding a way to do this - although not exactly programmatically. I included a binary called "pdftk.exe" which is PDF ToolKit, which has command-line options to extract the attachments.

为了澄清,我添加了pdftk.exe,然后通过 Process.Start(./ pdftk,contains_attachments.pdf unpack_files output \C:\\output_directory \)调用它。请注意,pdftk不会输出到带有反斜杠的文件夹。你可以在这里找到pdftk:

To clarify, I added pdftk.exe, then called it via Process.Start("./pdftk", "contains_attachments.pdf unpack_files output \"C:\\output_directory\""). Note that pdftk will not output to a folder with a trailing backslash. You can find pdftk here: http://www.accesspdf.com/pdftk/

将.exe文件添加到项目后,需要将其属性设置为始终复制或如果更新则复制。

After adding the .exe file to the project, you need to set its properties to "Copy always" or "Copy if newer".

这篇关于iTextSharp - 如何打开/读取/提取文件附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:07