Metadata Свойство (PdfDocument)
В этом разделе
Возвращает или устанавливает метаданные, связанные с этим PDF документом.
Синтаксис
'Declaration
Public Property Metadata As Byte[]
public byte[] Metadata { get; set; }
public: __property byte[] get_Metadata();
public: __property void set_Metadata(
byte[]*
);
public:
property byte[] Metadata {
byte[] get();
void set(array<byte>^ );
}
Пример
Вот пример, показывающий, как получить информацию о метаданных XML PDF документа:
''' <summary>
''' Parses a PDF document metadata.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
Public Shared Sub ParsePdfDocumentMetadata(pdfFilename As String)
' open PDF document
Using pdfDocument As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' create a memory stream from metadata bytes
Using mem As New System.IO.MemoryStream(pdfDocument.Metadata)
' create XML reader
Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(mem)
' parse XML metadata of PDF document
Dim indentIndex As Integer = 0
While xmlReader.Read()
Select Case xmlReader.NodeType
Case System.Xml.XmlNodeType.Element
System.Console.WriteLine("{1}<{0}>", xmlReader.Name, GetIndent(indentIndex))
indentIndex += 1
Exit Select
Case System.Xml.XmlNodeType.Text
System.Console.WriteLine("{1} {0}", xmlReader.Value, GetIndent(indentIndex))
Exit Select
Case System.Xml.XmlNodeType.EndElement
indentIndex -= 1
System.Console.WriteLine("{1}</{0}>", xmlReader.Name, GetIndent(indentIndex))
Exit Select
End Select
End While
End Using
End Using
End Using
End Sub
Private Shared Function GetIndent(indexntIndex As Integer) As String
Dim indent As New System.Text.StringBuilder()
For i As Integer = 0 To indexntIndex - 1
indent.Append(" ")
Next
Return indent.ToString()
End Function
/// <summary>
/// Parses a PDF document metadata.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
public static void ParsePdfDocumentMetadata(string pdfFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument pdfDocument = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// create a memory stream from metadata bytes
using (System.IO.MemoryStream mem = new System.IO.MemoryStream(pdfDocument.Metadata))
{
// create XML reader
using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(mem))
{
// parse XML metadata of PDF document
int indentIndex = 0;
while (xmlReader.Read())
{
switch (xmlReader.NodeType)
{
case System.Xml.XmlNodeType.Element:
System.Console.WriteLine("{1}<{0}>", xmlReader.Name, GetIndent(indentIndex));
indentIndex++;
break;
case System.Xml.XmlNodeType.Text:
System.Console.WriteLine("{1} {0}", xmlReader.Value, GetIndent(indentIndex));
break;
case System.Xml.XmlNodeType.EndElement:
indentIndex--;
System.Console.WriteLine("{1}</{0}>", xmlReader.Name, GetIndent(indentIndex));
break;
}
}
}
}
}
}
private static string GetIndent(int indexntIndex)
{
System.Text.StringBuilder indent = new System.Text.StringBuilder();
for (int i = 0; i < indexntIndex; i++)
indent.Append(" ");
return indent.ToString();
}
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также