是否可以使用PdfSharp从PDF中提取嵌入文件和附件?如果是的话我们怎样才能实现它。
提前致谢
答案 0 :(得分:0)
似乎PDFSharp不直接支持attachments,但您可能尝试实现附件提取支持:您需要在PDF Reference 1.7中描述的PDF文档中查找 / FS 流在第3.10.3节和附录H的注释94中。
答案 1 :(得分:-1)
你可以试试Apose.pdf,它非常适合从PDF中提取嵌入的文件和附件。 请尝试以下操作。
Document pdfDocument = new Document(@"C:\tmp\AddAttachment_out.pdf");
// Get embedded files collection
EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles;
Console.WriteLine("Total files : {0}", embeddedFiles.Count);
int count = 1;
// Loop through the collection to get all the attachments
foreach (FileSpecification fileSpecification in embeddedFiles)
{
Console.WriteLine("Name: {0}", fileSpecification.Name);
Console.WriteLine("Description: {0}",
fileSpecification.Description);
Console.WriteLine("Mime Type: {0}", fileSpecification.MIMEType);
// Check if parameter object contains the parameters
/*if (fileSpecification.Params != null)
{
Console.WriteLine("CheckSum: {0}",
fileSpecification.Params.CheckSum);
Console.WriteLine("Creation Date: {0}",
fileSpecification.Params.CreationDate);
Console.WriteLine("Modification Date: {0}",
fileSpecification.Params.ModDate);
Console.WriteLine("Size: {0}", fileSpecification.Params.Size);
}*/
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0,
fileContent.Length);
FileStream fileStream = new FileStream("C:\\Tmp\\" + count + "_out" + ".pdf",
FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Close();
count += 1;
}