GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / SetPageMetadata Method / SetPageMetadata(String) Method
A new value of the metadata as a string in the XML format.
Example





In This Topic
SetPageMetadata(String) Method
In This Topic
Sets up the metadata of the currently selected page in the loaded PDF document according to what you have specified.
Syntax
'Declaration
 
Public Overloads Function SetPageMetadata( _
   ByVal XMP As String _
) As GdPictureStatus
public GdPictureStatus SetPageMetadata( 
   string XMP
)
public function SetPageMetadata( 
    XMP: String
): GdPictureStatus; 
public function SetPageMetadata( 
   XMP : String
) : GdPictureStatus;
public: GdPictureStatus SetPageMetadata( 
   string* XMP
) 
public:
GdPictureStatus SetPageMetadata( 
   String^ XMP
) 

Parameters

XMP
A new value of the metadata as a string in the XML format.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.

The currently stored metadata entries will be overwritten according to the values you have specified.

Example
How to set up the metadata linked with all pages of the PDF document.
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim count As Integer = gdpicturePDF.GetPageCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        Dim data As String = "", message As String = ""
        For i As Integer = 1 To count
            status = gdpicturePDF.SelectPage(i)
            If status = GdPictureStatus.OK Then
                data = "<head>" + vbCrLf +
                       "< meta name =""description"" content=""Brief description of the page."" />" + vbCrLf +
                       "< meta name =""keywords"" content=""metadata of the page"" />" + vbCrLf +
                       "< meta name =""author"" content=""John Doe"" />" + vbCrLf +
                       "< meta name =""pagenumber"" content=""" + i.ToString() + """ />" + vbCrLf + "</head>"
                status = gdpicturePDF.SetPageMetadata(data)
                If status = GdPictureStatus.OK Then
                    message = message + "The metadata for the page nr." + i.ToString() + " has been set successfully." + vbCrLf
                Else
                    message = message + "The SetPageMetadata() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
                End If
            Else
                message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
            End If
        Next
        If gdpicturePDF.SaveToFile("test_PageMetadata.pdf") = GdPictureStatus.OK Then
            message = message + "The file has been saved."
        Else
            message = message + "The file can't be saved."
        End If
            
        MessageBox.Show(message, "Example: SetPageMetadata")
    Else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), "Example: SetPageMetadata")
    End If
Else
    MessageBox.Show("The file can't be loaded.", "Example: SetPageMetadata")
End If
gdpicturePDF.Dispose()
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int count = gdpicturePDF.GetPageCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        string data = "", message = "";
        for (int i = 1; i <= count; i++)
        {
            status = gdpicturePDF.SelectPage(i);
            if (status == GdPictureStatus.OK)
            {
                data = "<head>\n< meta name =\"description\" content=\"Brief description of the page.\" />\n"+
                               "< meta name =\"keywords\" content=\"metadata of the page\" />\n"+
                               "< meta name =\"author\" content=\"John Doe\" />\n"+
                               "< meta name =\"pagenumber\" content=\"" + i.ToString() + "\" />\n</head>";
                status = gdpicturePDF.SetPageMetadata(data);
                if (status == GdPictureStatus.OK)
                    message = message + "The metadata for the page nr." + i.ToString() + " has been set successfully.\n";
                else
                    message = message + "The SetPageMetadata() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
            }
            else
                message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
        }
        if (gdpicturePDF.SaveToFile("test_PageMetadata.pdf") == GdPictureStatus.OK)
            message = message + "The file has been saved.";
        else
            message = message + "The file can't be saved.";
        MessageBox.Show(message, "Example: SetPageMetadata");
            
    }
    else
        MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), "Example: SetPageMetadata");
}
else
    MessageBox.Show("The file can't be loaded.", "Example: SetPageMetadata");
gdpicturePDF.Dispose();
See Also