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





In This Topic

SetMetadata Method (GdPicturePDF)

In This Topic
Sets up a metadata of the currently loaded PDF document according to what you have specified.

The toolkit supports XMP format of metadata, which is the standard for embedding metadata in files. For further assistance, please refer to the core XMP specification published as ISO standard 16684-1.

Syntax
'Declaration
 
Public Function SetMetadata( _
   ByVal XMP As String _
) As GdPictureStatus
public GdPictureStatus SetMetadata( 
   string XMP
)
public function SetMetadata( 
    XMP: String
): GdPictureStatus; 
public function SetMetadata( 
   XMP : String
) : GdPictureStatus;
public: GdPictureStatus SetMetadata( 
   string* XMP
) 
public:
GdPictureStatus SetMetadata( 
   String^ XMP
) 

Parameters

XMP
A new value of the metadata as a string in the XMP standardized 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.

Just to inform you, that the currently stored metadata entries will be overwritten according to the values you have specified.

Example
How to add or replace the specified metadata of the PDF document.
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    If gdpicturePDF.LoadFromFile("test.pdf", True) = GdPictureStatus.OK Then
        'Let's say that metadata.xmp are your required metadata you want to add/replace.
        Dim metadataFile As System.IO.StreamReader = New System.IO.StreamReader("metadata.xmp")
        Dim xmp As String = metadataFile.ReadToEnd()
        metadataFile.Close()
        'Now you can change the metadata here.
        If gdpicturePDF.SetMetadata(xmp) = GdPictureStatus.OK Then
            If gdpicturePDF.SaveToFile("test.pdf") = GdPictureStatus.OK Then
                xmp = gdpicturePDF.GetMetadata()
                If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                    MessageBox.Show("The changed metadata are:" + vbCrLf + xmp, "Example: SetMetadata")
                End If
            Else
                MessageBox.Show("The file can't be saved.", "Example: SetMetadata")
            End If
        Else
            MessageBox.Show("The SetMetadata() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), "Example: SetMetadata")
        End If
    Else
        MessageBox.Show("The file can't be loaded.", "Example: SetMetadata")
    End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    if (gdpicturePDF.LoadFromFile("test.pdf", true) == GdPictureStatus.OK)
    {
        //Let's say that metadata.xmp are your required metadata you want to add/replace.
        System.IO.StreamReader metadataFile = new System.IO.StreamReader("metadata.xmp");
        string xmp = metadataFile.ReadToEnd();
        metadataFile.Close();
        //Now you can change the metadata here.
        if (gdpicturePDF.SetMetadata(xmp) == GdPictureStatus.OK)
        {
            if (gdpicturePDF.SaveToFile("test.pdf") == GdPictureStatus.OK)
            {
                xmp = gdpicturePDF.GetMetadata();
                if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    MessageBox.Show("The changed metadata are:\n" + xmp, "Example: SetMetadata");
                }
            }
            else
            {
                MessageBox.Show("The file can't be saved.", "Example: SetMetadata");
            }
        }
        else
        {
            MessageBox.Show("The SetMetadata() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), "Example: SetMetadata");
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", "Example: SetMetadata");
    }
}
See Also