logo Aspose.PDF使用教程 我也要发布文档

获取附件信息


FileSpecification对象能提供包括名称、描述、MIMEType和参数在内的附件属性信息。前三个属性从他们的名字可以很明显地看出他们的作用,而参数属性提供了有关文件的参数信息。这些参数包括校验,创建日期,审核日期和大小。为了获得这些参数,首先需要确保Params参数属性不为空。

你可以从Document文件对象的EmbeddedFiles Collection集合中获取FileSpecification对象。 这个EmbeddedFiles集合包含PDF文档的所有附件。

》》》免费下载Aspose.Pdf试用版

获取附件信息的代码示例如下:

C#

//open document
Document pdfDocument = new Document("input.pdf");
//get particular embedded file
FileSpecification fileSpecification = pdfDocument.EmbeddedFiles[1];
//get the file properties
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);
}
 
VB.NET
'open document
Dim pdfDocument As New Document("input.pdf")
'get particular embedded file
Dim fileSpecification As FileSpecification = pdfDocument.EmbeddedFiles(1)
'get the file properties
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 IsNot Nothing Then
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)
End If