VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf Namespace / PdfDocument Class / Metadata Property
Example



In This Topic
    Metadata Property (PdfDocument)
    In This Topic
    Gets or sets metadata associated with this PDF document.
    Syntax
    'Declaration
     
    Public Property Metadata As Byte()
    public byte[] Metadata {get; set;}
    public: __property byte[]* get_Metadata();
    public: __property void set_Metadata( 
       byte[]* value
    );
    public:
    property array<byte>^ Metadata {
       array<byte>^ get();
       void set (    array<byte>^ value);
    }
    Example
    This example shows how to get information about XML metadata of PDF document.
    ''' <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();
    }
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also