GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / SetKeywords Method
A new value of the Keywords property as a string.
Example





In This Topic
SetKeywords Method (GdPicturePDF)
In This Topic
Sets up new keywords associated with the currently loaded PDF document into the document information dictionary and in the document catalog's metadata as well.

If the loaded PDF document contains metadata stored in the Metadata entry in the document catalog, the newly specified Keywords are synchronized with those metadata. That means, you will be able to see the changed value of this property using the Acrobat's Document Properties dialogue box. At the same, if you need to add and store any kind of structured information into your existing document, you can also use the GdPicturePDF.SetMetadata method instead.

Please use comma or semi-colon as word separators in the specified Keywords parameter for single keywords.

Syntax
'Declaration
 
Public Sub SetKeywords( _
   ByVal Keywords As String _
) 
public void SetKeywords( 
   string Keywords
)
public procedure SetKeywords( 
    Keywords: String
); 
public function SetKeywords( 
   Keywords : String
);
public: void SetKeywords( 
   string* Keywords
) 
public:
void SetKeywords( 
   String^ Keywords
) 

Parameters

Keywords
A new value of the Keywords property as a string.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Just to remind you that the newly specified Keywords are fully synchronized with existing metadata, if any are included in the loaded PDF document. Likewise, you can also use the GdPicturePDF.SetMetadata method to store any kind of structured information there.

Example
How to set up new keywords associated with your already existing or newly created PDF document.
For the existing documents the keywords are stored into the document information dictionary.
Using gdpicturePDF As New GdPicturePDF()
    If gdpicturePDF.LoadFromFile("test.pdf", True) = GdPictureStatus.OK Then
        Dim keywords As String = gdpicturePDF.GetKeywords()
        Dim status As GdPictureStatus = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            MessageBox.Show("The original keywords of this PDF are: " + keywords, "Example: SetKeywords")
            'These keywords are stored in the document information dictionary.
            gdpicturePDF.SetKeywords("For Whom the Bell Tolls,Indian Camp,The Sun Also Rises,A Farewell to Arms,The Old Man and the Sea")
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If gdpicturePDF.SaveToFile("test.pdf") = GdPictureStatus.OK Then
                    keywords = gdpicturePDF.GetKeywords()
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        MessageBox.Show("The new keywords of this PDF are: " + keywords, "Example: SetKeywords")
                    End If
                Else
                    MessageBox.Show("The file can't be saved.", "Example: SetKeywords")
                End If
            Else
                MessageBox.Show("The SetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords")
            End If
        Else
            MessageBox.Show("The GetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords")
        End If
    Else
        MessageBox.Show("The file can't be loaded.", "Example: SetKeywords")
    End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    if (gdpicturePDF.LoadFromFile("test.pdf", true) == GdPictureStatus.OK)
    {
        string keywords = gdpicturePDF.GetKeywords();
        GdPictureStatus status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            MessageBox.Show("The original keywords of this PDF are: " + keywords, "Example: SetKeywords");
            //These keywords are stored in the document information dictionary.
            gdpicturePDF.SetKeywords("For Whom the Bell Tolls,Indian Camp,The Sun Also Rises,A Farewell to Arms,The Old Man and the Sea");
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (gdpicturePDF.SaveToFile("test.pdf") == GdPictureStatus.OK)
                {
                    keywords = gdpicturePDF.GetKeywords();
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        MessageBox.Show("The new keywords of this PDF are: " + keywords, "Example: SetKeywords");
                    }
                }
                else
                {
                    MessageBox.Show("The file can't be saved.", "Example: SetKeywords");
                }
            }
            else
            {
                MessageBox.Show("The SetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords");
            }
        }
        else
        {
            MessageBox.Show("The GetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords");
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", "Example: SetKeywords");
    }
}
For newly created PDF/A documents the keywords are stored as the structured metadata into the document catalog dictionary.
Using gdpicturePDF As New GdPicturePDF()
    If gdpicturePDF.NewPDF(PdfConformance.PDF_A_1b) = GdPictureStatus.OK Then
        Dim status As GdPictureStatus = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4)
        If status = GdPictureStatus.OK Then
            'Create your own PDF content here.
            '...
            'These keywords are stored in the document catalog dictionary as the structured metadata.
            gdpicturePDF.SetKeywords("For Whom the Bell Tolls,Indian Camp,The Sun Also Rises,A Farewell to Arms,The Old Man and the Sea")
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If gdpicturePDF.SaveToFile("test.pdf") = GdPictureStatus.OK Then
                    Dim keywords As String = gdpicturePDF.GetKeywords()
                    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                        MessageBox.Show("The new keywords of this PDF are: " + keywords, "Example: SetKeywords")
                    End If
                Else
                    MessageBox.Show("The file can't be saved.", "Example: SetKeywords")
                End If
            Else
                MessageBox.Show("The SetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords")
            End If
        Else
            MessageBox.Show("The NewPage() method has failed with the status: " + status.ToString(), "Example: SetKeywords")
        End If
    Else
        MessageBox.Show("The file can't be created.", "Example: SetKeywords")
    End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    if (gdpicturePDF.NewPDF(PdfConformance.PDF_A_1b) == GdPictureStatus.OK)
    {
        GdPictureStatus status = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4);
        if (status == GdPictureStatus.OK)
        {
            //Create your own PDF content here.
            //...
            //These keywords are stored in the document catalog dictionary as the structured metadata.
            gdpicturePDF.SetKeywords("For Whom the Bell Tolls,Indian Camp,The Sun Also Rises,A Farewell to Arms,The Old Man and the Sea");
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (gdpicturePDF.SaveToFile("test.pdf") == GdPictureStatus.OK)
                {
                    string keywords = gdpicturePDF.GetKeywords();
                    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        MessageBox.Show("The new keywords of this PDF are: " + keywords, "Example: SetKeywords");
                    }
                }
                else
                {
                    MessageBox.Show("The file can't be saved.", "Example: SetKeywords");
                }
            }
            else
            {
                MessageBox.Show("The SetKeywords() method has failed with the status: " + status.ToString(), "Example: SetKeywords");
            }
        }
        else
        {
            MessageBox.Show("The NewPage() method has failed with the status: " + status.ToString(), "Example: SetKeywords");
        }
    }
    else
    {
        MessageBox.Show("The file can't be created.", "Example: SetKeywords");
    }
}
See Also