Reference Guide
GdPicture14.WPF Namespace / GdViewer Class / PdfGetMetadata Method
Example





In This Topic
    PdfGetMetadata Method (GdViewer)
    In This Topic
    Returns the metadata of the currently displayed PDF document, if any are stored in the PDF. If the document currently displayed in the GdViewer control is not the PDF file, the method will fail.
    Syntax
    'Declaration
     
    
    Public Function PdfGetMetadata() As String
    public string PdfGetMetadata()
    public function PdfGetMetadata(): String; 
    public function PdfGetMetadata() : String;
    public: string* PdfGetMetadata(); 
    public:
    String^ PdfGetMetadata(); 

    Return Value

    The value of the document's metadata as a string in the XML format. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that this method is only meaningful for PDF documents, otherwise it returns an empty string. We strongly recommend using the GetStat method to identify the specific reason for the method's failure.
    Example
    How to retrieve the PDF metadata associated with the loaded PDF document.
    'We assume that the GdViewer1 control has been properly integrated.
    If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
        Dim message As String = "The current file is: " + GdViewer1.GetLastPath()
        If GdViewer1.GetDocumentType() = DocumentType.DocumentTypePDF Then
            message += vbCrLf + "PDF Version: " + GdViewer1.PdfGetVersion() +
                       vbCrLf + "Keywords: " + GdViewer1.PdfGetKeywords()
            'Retrieving the PDF metadata.
            Dim metadata As String = GdViewer1.PdfGetMetadata()
            If GdViewer1.GetStat() = GdPictureStatus.OK Then
                Dim metadataFile As String = filename.Replace(".pdf", "_metadata.xmp")
                System.IO.File.WriteAllText(metadataFile, metadata)
                message += vbCrLf + "Metadata has been successfully saved. File: " + metadataFile
            Else
                message += vbCrLf + "Metadata has not been retrieved. Status: " + GdViewer1.GetStat().ToString()
            End If
        Else
            message += vbCrLf + "This file is not a PDF document, its format is: " + GdViewer1.GetDocumentType().ToString()
        End If
                
        MessageBox.Show(message, "GdViewer.PdfGetMetadata")
    Else
        MessageBox.Show("The file can't be loaded. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.PdfGetMetadata")
    End If
    //We assume that the GdViewer1 control has been properly integrated.
    if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
    {
        string message = "The current file is: " + GdViewer1.GetLastPath();
        if (GdViewer1.GetDocumentType() == DocumentType.DocumentTypePDF)
        {
            message += "\nPDF Version: " + GdViewer1.PdfGetVersion() +
                       "\nKeywords: " + GdViewer1.PdfGetKeywords();
            //Retrieving the PDF metadata.
            string metadata = GdViewer1.PdfGetMetadata();
            if (GdViewer1.GetStat() == GdPictureStatus.OK)
            {
                string metadataFile = filename.Replace(".pdf", "_metadata.xmp");
                System.IO.File.WriteAllText(metadataFile, metadata);
                message += "\nMetadata has been successfully saved. File: " + metadataFile;
            }
            else
                message += "\nMetadata has not been retrieved. Status: " + GdViewer1.GetStat().ToString();
        }
        else
        {
            message += "\nThis file is not a PDF document, its format is: " + GdViewer1.GetDocumentType().ToString();
        }
        MessageBox.Show(message, "GdViewer.PdfGetMetadata");
    }
    else
        MessageBox.Show("The file can't be loaded. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.PdfGetMetadata");
    See Also