Read and Edit PDF Page Label Metadata Using C#

EXIF (Exchangeable Image File Format) is a standard used by digital cameras that specifies metadata tags such as camera settings, image metrics, date and time information, and more.

Supported Image Formats

  • JPEG (read and write)

  • PNG (read and write)

  • RAW (read only)

  • TIFF (read and write)

  • WEBP (read and write)

GPS Tags

GPS tags are used by digital cameras that contain positioning information. They’re specified by the same standard as EXIF tags. This means that all methods described below are also applicable for GPS tags, but only for the following image formats:

  • JPEG (read and write)

  • TIFF (read and write)

Getting EXIF Tags

To retrieve EXIF tag data, use the following methods:

All the methods listed above require the image ID and the EXIF tag number.

The tag number may be different for every EXIF tag. This means that to get the exact EXIF tag you want, you have to loop through all tags. To get the total number of EXIF tags, use the TagCount method.

The code below shows how to list the EXIF tags of an image file:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Create a `StringBuilder` object to store tags.
StringBuilder report = new StringBuilder();
// Get tag count.
int tagCount = gdpictureImaging.TagCount(imageID);
for (int i = 1; i <= tagCount; i++)
{
    // Get tag ID.
    Tags tagID = gdpictureImaging.TagGetID(imageID, i);
    //Get tag type.
    TagType tagType = gdpictureImaging.TagGetType(imageID, i);
    // Get tag name.
    string tagName = gdpictureImaging.TagGetName(imageID, i);
    // Get tag value.
    string tagValue = gdpictureImaging.TagGetValueString(imageID, i);
    // Append tag data.
    report.AppendLine($"{tagID} {tagType} {tagName} {tagValue}");
}
Console.WriteLine($"{report}");
GdPictureDocumentUtilities.DisposeImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Create a `StringBuilder` object to store tags.
    Dim report As StringBuilder = New StringBuilder()
    ' Get tag count.
    Dim tagCount As Integer = gdpictureImaging.TagCount(imageID)

    For i = 1 To tagCount
        ' Get tag ID.
        Dim tagID As Tags = gdpictureImaging.TagGetID(imageID, i)
        ' Get tag type.
        Dim tagType As TagType = gdpictureImaging.TagGetType(imageID, i)
        ' Get tag name.
        Dim tagName As String = gdpictureImaging.TagGetName(imageID, i)
        ' Get tag value.
        Dim tagValue As String = gdpictureImaging.TagGetValueString(imageID, i)
        ' Append tag data.
        report.AppendLine($"{tagID} {tagType} {tagName} {tagValue}")
    Next

    Console.WriteLine($"{report}")
    GdPictureDocumentUtilities.DisposeImage(imageID)
End Using
Used Methods

Related Topics

Setting an EXIF Tag

To set an EXIF tag, use one of the following methods:

Both methods require the following parameters:

  • imageID — Image ID.

  • TagID — Tag ID, which is a member of the Tags enumeration.

  • TagType — Tag type, which is a member of the TagType enumeration.

  • TagData — The new value of the tag. It can be either a string or a byte value, depending on which method you use.

The code below shows how to modify an EXIF tag of an image file that specifies the date on which the image was taken:

using GdPictureImaging gdPictureImaging = new GdPictureImaging();
int imageID = gdPictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Get tag count.
int tagCount = gdPictureImaging.TagCount(imageID);
gdPictureImaging.TagSetValueString(imageID, Tags.TagExifDTOrig,
    TagType.TagTypeASCII, "2020:11:30 13:45:29");
// Save the image in a new file.
gdPictureImaging.SaveAsJPEG(imageID, @"C:\temp\output.jpg");
gdPictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdPictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Get tag count.
    Dim tagCount As Integer = gdPictureImaging.TagCount(imageID)
    gdPictureImaging.TagSetValueString(imageID, Tags.TagExifDTOrig,
        TagType.TagTypeASCII, "2020:11:30 13:45:29")
    ' Save the image in a new file.
    gdPictureImaging.SaveAsJPEG(imageID, "C:\temp\output.jpg")
    gdPictureImaging.ReleaseGdPictureImage(imageID)
End Using
Used Methods

Related Topics

Page labels in a PDF file are metadata assigned for a page, and they’re grouped as a page label range. By default, a PDF document has only one page label range, which starts from 1. It’s possible to add multiple page label ranges, and you can specify from which number each page label range starts.

Getting the Page Label

To get the page label of a PDF page, use the GetPageLabel method and specify the page number as its parameter.

To get the page label for all pages of a PDF document, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
int pageCount = gdpicturePDF.GetPageCount();
for(int i = 1; i <= pageCount; i++)
{
    // Get the page label.
    Console.WriteLine(gdpicturePDF.GetPageLabel(i));
}
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    For i = 1 To pageCount
        ' Get the page label.
        Console.WriteLine(gdpicturePDF.GetPageLabel(i))
    Next
End Using
Used Methods

Related Topics

Getting the Page Label Range

To get the page label range of a PDF document, use the GetPageLabelsRange method. It requires the page label range index as its parameter. The GetPageLabelsRange method returns the following values:

  • StartPage — Value of the starting position of the page label range.

  • Style — Style of the specified label range, which is a member of the PdfPageLabelStyle enumeration.

  • Prefix — If defined, the page label prefix.

  • NumPortion — Value of the numeric portion of the first page label.

A PDF document can have multiple page label ranges. To get the total amount in a PDF, use the GetPageLabelsRangeCount method.

Information

Use a condition to execute the GetPageLabelsRange method only when the amount of page label ranges is greater than 0, in case the PDF document doesn’t have any page label ranges set up.

To get the details of all page label ranges of a PDF document, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Get total amount of page label ranges.
int labelCount = gdpicturePDF.GetPageLabelsRangeCount();
int startPage = 0, numPortion = 0;
PdfPageLabelStyle style = 0 ;
String prefix = "";
// Execute only when there are more than zero page label ranges.
if(labelCount > 0)
{
    for (int i = 0; i < labelCount; i++)
    {
        // Get page label range details.
        gdpicturePDF.GetPageLabelsRange(i, ref startPage, ref style,
            ref prefix, ref numPortion);
        Console.WriteLine($"Page Label Range nr {i}:\nStart Page: {startPage}\n" +
            $"Prefix: {prefix}\nStyle: {style}\nNumber Portion: {numPortion}");
    }
}
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Get total amount of page label ranges.
    Dim labelCount As Integer = gdpicturePDF.GetPageLabelsRangeCount()
    Dim startPage = 0, numPortion = 0
    Dim style As PdfPageLabelStyle = 0
    Dim prefix = ""
    ' Execute only when there are more than zero page label ranges.
    If labelCount > 0 Then
        For i = 0 To labelCount - 1
            ' Get page label range details.
            gdpicturePDF.GetPageLabelsRange(i, startPage, style, prefix, numPortion)
            Console.WriteLine($"Page Label Range nr {i}:
    Start Page: {startPage}
    " & $"Prefix: {prefix}
    Style: {style}
    Number Portion: {numPortion}")
        Next
    End If
End Using
Used Methods

Related Topics

Adding a Page Label Range

To add a page label range to a PDF document, use the AddPageLabelsRange method. It requires the following parameters:

  • StartPage — Value of the starting position of the page label range.

  • Style — Style of the page label that’s a member of the PdfPageLabelStyle enumeration (such as Arabic numerals or lowercase Roman numerals).

  • Prefix — String prefix of each page label.

  • NumPortion — Value of the numeric portion of the first page label.

Information

Before adding a new page label range, delete all page label ranges previously added with the DeletePageLabels method.

To add a page label range for the last three appendix pages of a PDF document, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Delete previous page label ranges.
gdpicturePDF.DeletePageLabels();
// Get total amount of pages.
int pageCount = gdpicturePDF.GetPageCount();
// Add the page label range for the appendix pages.
gdpicturePDF.AddPageLabelsRange(pageCount - 2,
    PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "A-", 1);
// Save the PDF document.
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Delete previous page label ranges.
    gdpicturePDF.DeletePageLabels()
    ' Get total amount of pages.
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    ' Add the page label range for the appendix pages.
    gdpicturePDF.AddPageLabelsRange(pageCount - 2,
        PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "A-", 1)
    ' Save the PDF document.
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Adding Multiple Page Label Ranges

To add multiple page label ranges, use the AddPageLabelsRange method. Remember to use the AddPageLabelsRange method from the beginning of the PDF document to the end. This way, the next executed method won’t override the previous one.

To learn more about how to use the AddPageLabelsRange method, refer to the previous section.

To add three page label ranges for the title, main, and appendix pages, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Delete previous page label ranges.
gdpicturePDF.DeletePageLabels();
// Get total amount of pages.
int pageCount = gdpicturePDF.GetPageCount();
// Add the page label range for the title page.
gdpicturePDF.AddPageLabelsRange(1,
    PdfPageLabelStyle.PdfPageLabelStyleUndefined, "Title Page", 0);
// Add the page label range for the main pages.
gdpicturePDF.AddPageLabelsRange(2,
    PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "", 1);
// Add the page label range for the appendix pages.
gdpicturePDF.AddPageLabelsRange(pageCount - 2,
    PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "A-", 1);
// Save the PDF document.
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Delete previous page label ranges.
    gdpicturePDF.DeletePageLabels()
    ' Get total amount of pages.
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    ' Add the page label range for the title page.
    gdpicturePDF.AddPageLabelsRange(1, PdfPageLabelStyle.PdfPageLabelStyleUndefined, "Title Page", 0)
    ' Add the page label range for the main pages.
    gdpicturePDF.AddPageLabelsRange(2, PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "", 1)
    ' Add the page label range for the appendix pages.
    gdpicturePDF.AddPageLabelsRange(pageCount - 2, PdfPageLabelStyle.PdfPageLabelStyleDecimalArabicNumerals, "A-", 1)
    ' Save the PDF document.
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Deleting a Page Label Range

To delete a page label range, use the DeletePageLabelsRange method. It only requires the page label range index.

A PDF document can have multiple page label ranges. To get the total amount in a PDF, use the GetPageLabelsRangeCount method.

To delete the last page label range of a PDF document, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Get page label range count.
int rangeCount = gdpicturePDF.GetPageLabelsRangeCount();
// Delete the last page label range.
gdpicturePDF.DeletePageLabelsRange(rangeCount - 1);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Get page label range count.
    Dim rangeCount As Integer = gdpicturePDF.GetPageLabelsRangeCount()
    ' Delete the last page label range.
    gdpicturePDF.DeletePageLabelsRange(rangeCount - 1)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Modifying a Page Label Range

To modify an existing page label range, use any of the following methods:

All methods mentioned above require the page label range index and the value of the parameter you want to change.

The code example below shows how to change all parameters of a page label range:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Change the start page to `1`.
gdpicturePDF.SetPageLabelsRangeStartPage(0, 1);
// Change the style to uppercase letters.
gdpicturePDF.SetPageLabelsRangeStyle(0, PdfPageLabelStyle.PdfPageLabelStyleUppercaseLetters);
// Change the prefix to `Page `.
gdpicturePDF.SetPageLabelsRangePrefix(0, "Page ");
// Change the starting number to `5`.
gdpicturePDF.SetPageLabelsRangeNumPortion(0, 5);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Change the start page to `1`.
    gdpicturePDF.SetPageLabelsRangeStartPage(0, 1)
    ' Change the style to uppercase letters.
    gdpicturePDF.SetPageLabelsRangeStyle(0, PdfPageLabelStyle.PdfPageLabelStyleUppercaseLetters)
    ' Change the prefix to `Page `.
    gdpicturePDF.SetPageLabelsRangePrefix(0, "Page ")
    ' Change the starting number to `5`.
    gdpicturePDF.SetPageLabelsRangeNumPortion(0, 5)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

XMP (Extensible Metadata Platform) is an ISO standard used for creating and processing standardized and custom metadata for digital documents. It uses the RDF/XML syntax, which is embedded into a file. It consists of name/value pairs and allows using structured values and lists of values, as well as nesting them in other values.

Supported Image Formats

  • JPEG (read and write)

  • PNG (read and write)

  • TIFF (read and write)

  • WEBP (read and write)

Getting XMP Metadata from a PDF Document

To get the XMP metadata of a PDF document, use the GetMetadata method. This method doesn’t require any parameters and returns a string value of the document metadata in XMP format.

To get a PDF’s XMP metadata, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Get the XMP metadata.
string metadata = gdpicturePDF.GetMetadata();
Console.WriteLine(metadata);
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Get the XMP metadata.
    Dim metadata As String = gdpicturePDF.GetMetadata()
    Console.WriteLine(metadata)
End Using
Used Methods

Related Topics

Getting XMP Metadata from a PDF Page

To get the XMP metadata from a PDF page, use the GetPageMetadata method. Before using this method in your code, use the SelectPage method to specify from which page you want to get the XMP metadata.

The GetPageMetadata method doesn’t require any parameters and returns a string value of the document metadata in XMP format.

To get the XMP metadata of the first page of a PDF, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page of the PDF document.
gdpicturePDF.SelectPage(1);
// Get the XMP metadata.
string metadata = gdpicturePDF.GetPageMetadata();
Console.WriteLine(metadata);
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page of the PDF document.
    gdpicturePDF.SelectPage(1)
    ' Get the XMP metadata.
    Dim metadata As String = gdpicturePDF.GetPageMetadata()
    Console.WriteLine(metadata)
End Using
Used Methods

Related Topics

Setting XMP Metadata for a PDF Document

To set XMP metadata for a PDF document, use the SetMetadata method. It requires XMP metadata in the form of a string as its parameter.

To set XMP metadata for a PDF document from an XMP file, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Save the metadata to a string from a file.
String data = File.ReadAllText(@"C:\temp\metadata.xmp");
// Set the metadata from the string.
gdpicturePDF.SetMetadata(data);
gdpicturePDF.SaveToFile(@"C:\temp\source.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Save the metadata to a string from a file.
    Dim data = File.ReadAllText("C:\temp\metadata.xmp")
    ' Set the metadata from the string.
    gdpicturePDF.SetMetadata(data)
    gdpicturePDF.SaveToFile("C:\temp\source.pdf")
End Using
Used Methods

Related Topics

Setting XMP Metadata for a PDF Page

To set the XMP metadata for a PDF page, use the SetPageMetadata method. Before using this method in your code, use the SelectPage method to specify from which page you want to get the XMP metadata.

The GetPageMetadata method requires the XMP metadata as its parameter in the form of either a string or a byte array.

To set the XMP metadata of the first page of a PDF from a byte array, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Select the first page of the PDF document.
gdpicturePDF.SelectPage(1);
// Save the metadata to a byte array from a file.
byte[] data = File.ReadAllBytes(@"C:\temp\metadata.xmp");
// Set the metadata from the byte array.
gdpicturePDF.SetPageMetadata(data);
gdpicturePDF.SaveToFile(@"C:\temp\source.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Select the first page of the PDF document.
    gdpicturePDF.SelectPage(1)
    ' Save the metadata to a byte array from a file.
    Dim data = File.ReadAllBytes("C:\temp\metadata.xmp")
    ' Set the metadata from the byte array.
    gdpicturePDF.SetPageMetadata(data)
    gdpicturePDF.SaveToFile("C:\temp\source.pdf")
End Using
Used Methods

Related Topics

Adding a Custom XMP Metadata Entry to a PDF Document

To add a custom metadata entry to a PDF document in XMP format, use the SetCustomPDFInformation method. It requires the key and the value of the custom XMP metadata in the form of a string.

To add a custom XMP metadata entry to a PDF document describing from which department the file originates, use the following code:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Add custom XMP metadata.
gdpicturePDF.SetCustomPDFInformation("Department", "Human Resources");
gdpicturePDF.SaveToFile(@"C:\temp\source.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Add custom XMP metadata.
    gdpicturePDF.SetCustomPDFInformation("Department", "Human Resources")
    gdpicturePDF.SaveToFile("C:\temp\source.pdf")
End Using
Used Methods

Related Topics

IPTC is an extension of the EXIF standard, and it contains additional information not included in EXIF tags. This information refers to the image content to help manage and categorize images and includes the image category, copyright notice, and more. Custom IPTC tags can also be created.

Supported Image Formats

  • JPEG (read and write)

  • TIFF (read and write)

Getting IPTC Tags

To retrieve IPTC tag data, use the following methods:

All methods listed above require the image ID and the IPTC tag number.

The tag number may be different for every IPTC tag. This means that to get the exact IPTC tag you want, you have to loop through all tags. To get the total number of IPTC tags, use the IPTCCount method.

The code below shows how to list IPTC tags of an image file:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Create a `StringBuilder` object to store tags.
StringBuilder report = new StringBuilder();
// Get tag count.
int tagCount = gdpictureImaging.IPTCCount(imageID);
for (int i = 1; i <= tagCount; i++)
{
    // Get tag ID.
    IPTCTags tagID = gdpictureImaging.IPTCGetID(imageID, i);
    //Get tag type.
    TagType tagType = gdpictureImaging.IPTCGetType(imageID, i);
    // Get tag value.
    string tagValue = gdpictureImaging.IPTCGetValueString(imageID, i);
    // Append tag data.
    report.AppendLine($"{tagID} {tagType} {tagValue}");
}
Console.WriteLine($"{report}");
GdPictureDocumentUtilities.DisposeImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Create a `StringBuilder` object to store tags.
    Dim report As StringBuilder = New StringBuilder()
    ' Get tag count.
    Dim tagCount As Integer = gdpictureImaging.IPTCCount(imageID)
    For i = 1 To tagCount
        ' Get tag ID.
        Dim tagID As IPTCTags = gdpictureImaging.IPTCGetID(imageID, i)
        'Get tag type.
        Dim tagType As TagType = gdpictureImaging.IPTCGetType(imageID, i)
        ' Get tag value.
        Dim tagValue As String = gdpictureImaging.IPTCGetValueString(imageID, i)
        ' Append tag data.
        report.AppendLine($"{tagID} {tagType} {tagValue}")
    Next
    Console.WriteLine($"{report}")
    GdPictureDocumentUtilities.DisposeImage(imageID)
End Using
Used Methods

Related Topics

Setting an IPTC Tag

To set an IPTC tag, use one of the IPTCSetValueString method. It requires the following parameters:

  • imageID — Image ID.

  • IPTCTagID — IPTC tag ID, which is a member of the IPTCTags enumeration.

  • TagData — The new string value of the tag.

The code below shows how to modify an IPTC tag of an image file that specifies the location of the city the image was taken in:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Set the value of the `IPTCTagCity` tag.
gdpictureImaging.IPTCSetValueString(imageID, IPTCTags.IPTCTagCity, "New York");
gdpictureImaging.SaveAsJPEG(imageID, @"C:\temp\source.jpg");
GdPictureDocumentUtilities.DisposeImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Set the value of the `IPTCTagCity` tag.
    gdpictureImaging.IPTCSetValueString(imageID, IPTCTags.IPTCTagCity, "New York")
    gdpictureImaging.SaveAsJPEG(imageID, "C:\temp\source.jpg")
    GdPictureDocumentUtilities.DisposeImage(imageID)
End Using
Used Methods

Related Topics

Deleting an IPTC Tag

To delete an IPTC tag, use the IPTCDelete method. It requires the following parameters:

  • imageID — Image ID.

  • TagNo — IPTC tag number attached to the image.

The tag number may be different for every IPTC tag. This means that to get the exact IPTC tag you want, you have to loop through all tags. To get the total number of IPTC tags, use the IPTCCount method:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Get tag count.
int tagCount = gdpictureImaging.IPTCCount(imageID);
for (int i = 1; i <= tagCount; i++)
{
    // If the current tag is `IPTCTagCity`, then delete the tag.
    if(gdpictureImaging.IPTCGetID(imageID, i) == IPTCTags.IPTCTagCity)
        gdpictureImaging.IPTCDelete(imageID, i);
}
gdpictureImaging.SaveAsJPEG(imageID, @"C:\temp\source.jpg");
GdPictureDocumentUtilities.DisposeImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Get tag count.
    Dim tagCount As Integer = gdpictureImaging.IPTCCount(imageID)
    For i = 1 To tagCount
        ' If the current tag is `IPTCTagCity`, then delete the tag.
        If gdpictureImaging.IPTCGetID(imageID, i) Is IPTCTags.IPTCTagCity Then gdpictureImaging.IPTCDelete(imageID, i)
    Next
    gdpictureImaging.SaveAsJPEG(imageID, "C:\temp\source.jpg")
    GdPictureDocumentUtilities.DisposeImage(imageID)
End Using
Used Methods

Related Topics

Creating a Custom IPTC Tag

To create a custom IPTC tag, you have to add a new member to the IPTCTags enumeration and assign a value to it:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Create a `StringBuilder` object to store tag data.
StringBuilder report = new StringBuilder();
// Get tag count.
int tagCount = gdpictureImaging.IPTCCount(imageID);
// Add an empty custom tag to the `IPTCTags` enumeration.
IPTCTags customTag = (IPTCTags)(tagCount + 1);
// Set a value to the custom tag.
gdpictureImaging.IPTCSetValueString(imageID, customTag, "Custom tag value");
for (int i = 1; i <= tagCount + 1; i++)
{
    // Get tag ID.
    IPTCTags tagID = gdpictureImaging.IPTCGetID(imageID, i);
    // Get tag type.
    TagType tagType = gdpictureImaging.IPTCGetType(imageID, i);
    // Get tag value.
    string tagValue = gdpictureImaging.IPTCGetValueString(imageID, i);
    // Append tag data.
    report.AppendLine($"{tagID} {tagType} {tagValue}");
}
gdpictureImaging.SaveAsJPEG(imageID, @"C:\temp\source.jpg");
Console.WriteLine($"{report}");
GdPictureDocumentUtilities.DisposeImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Create a `StringBuilder` object to store tag data.
    Dim report As StringBuilder = New StringBuilder()
    ' Get tag count.
    Dim tagCount As Integer = gdpictureImaging.IPTCCount(imageID)
    ' Add an empty custom tag to the `IPTCTags` enumeration.
    Dim customTag As IPTCTags = CType(tagCount + 1, IPTCTags)
    ' Set a value to the custom tag.
    gdpictureImaging.IPTCSetValueString(imageID, customTag, "Custom tag value")
    For i = 1 To tagCount + 1
        ' Get tag ID.
        Dim tagID As IPTCTags = gdpictureImaging.IPTCGetID(imageID, i)
        'Get tag type.
        Dim tagType As TagType = gdpictureImaging.IPTCGetType(imageID, i)
        ' Get tag value.
        Dim tagValue As String = gdpictureImaging.IPTCGetValueString(imageID, i)
        ' Append tag data.
        report.AppendLine($"{tagID} {tagType} {tagValue}")
    Next
    gdpictureImaging.SaveAsJPEG(imageID, "C:\temp\source.jpg")
    Console.WriteLine($"{report}")
    GdPictureDocumentUtilities.DisposeImage(imageID)
End Using
Used Methods

Related Topics