Free Support Forum - groupdocs.com

TIF image cannot remove Title, Subject, Authors, and copyright fields using .NET

Hi Dear Sir/Madam,

The attached TIF image file had it’s Title, Subject, Authors, and copyright fields modified. After I use the official codes to remove the metadata, I noticed all four of these fields still contain data.

Here’s the test tif file.

Here’s the code we used https://docs.groupdocs.com/display/metadatanet/Working+with+EXIF+Metadata
We are using GroupDocs.Metadata v18.6

Btw, we have checked the “Camera serial number” field contained data , which was removed during the conversion process. Is it the expected behavoir, or this is a bug of GroupDocs.Metadata library?

Please have a check and let me know if you have any problem.

@Glority_Developer,

Thanks for using GroupDocs.Metadata and sharing your concerns with us.

We have checked your provided tif image and it doesn’t contain any EXIF Tags or EXIF Info, however, it contains the following XMP metadata:

[MicrosoftPhoto:CameraSerialNumber] = test
[dc:title] = title
[dc:creator] = paul d
[dc:rights] = copyright
[dc:description] = title

Would you please confirm whether are you working with EXIF Info or XMP metadata. Also, please provide us the source code you are using to get, add/update or remove metadata separately. We shall be looking forward to your response.

Here is source code our used:
FormatBase format = new TiffFormat(filePath);
((TiffFormat)format).RemoveXmpData();
ExifInfo exif = ((TiffFormat)format).GetExifInfo() ?? new ExifInfo();
List tags = new List();
tags.Add(new TiffAsciiTag(TiffTagIdEnum.Artist, string.Empty));
tags.Add(new TiffAsciiTag(TiffTagIdEnum.Copyright, string.Empty));
exif.Tags = tags.ToArray();
((TiffFormat)format).UpdateExifInfo(exif);
format.Save(outPath);
We can’t find any function to update tiff XMP metadata title,subject. Looking forward to your response.

@Glority_Developer,

Thanks for sharing the source code with us.

We are able to reproduce your reported issue at our end. We have logged it in our Issue Tracking System as METADATANET-2418 for further investigation. We shall keep you informed in case of any updates in this regard.

Following is the sample code to update the XMP metadata in Tiff:

using (TiffFormat tiff = new TiffFormat("Flowerboy_orginal (1).tif"))
{
        // get xmp wrapper
        XmpPacketWrapper xmpPacket = tiff.GetXmpData();

        // create xmp wrapper if not exists
        if (xmpPacket == null)
        {
                    xmpPacket = new XmpPacketWrapper();
        }

         // check if DublinCore schema exists
         if (!xmpPacket.ContainsPackage(Namespaces.DublinCore))
         {
                   // if not - add DublinCore schema
                   xmpPacket.AddPackage(new DublinCorePackage());
         }

         // get DublinCore package
         DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore);                    
                   
         // set subject
         dublinCorePackage.SetSubject("New subject");                    
         // set title
         dublinCorePackage.SetTitle("New title");
         // update XMP package
         tiff.SetXmpData(xmpPacket);

         // commit changes
         tiff.Save("Flowerboy_orginal (1)_output.tif");                    
                    
 }

Hope it helps.

We use this code try to update title and subject, title can be updated but SetSubject() will update tags not subject.
Source code our used:
if (xmpPacket == null)
{
xmpPacket = new XmpPacketWrapper();
}
if (!xmpPacket.ContainsPackage(Namespaces.DublinCore))
{
xmpPacket.AddPackage(new DublinCorePackage());
}
DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore);
for (int i = 0; i < options.DocumentData.Count; ++i)
{
DOCUMENTENUM data = (DOCUMENTENUM)options.DocumentData[i];
switch(data)
{
case DOCUMENTENUM.Title:
{
dublinCorePackage.SetTitle(string.Empty);
break;
}
case DOCUMENTENUM.Subject:
{
dublinCorePackage.SetSubject(“test”);
break;
}
default:
break;
}
}
if(format is TiffFormat)
{
((TiffFormat)format).SetXmpData(xmpPacket);
}
source_metadata.png (13.3 KB)
target_metadata.png (19.4 KB)

@Glority_Developer,

Thanks for providing details.

We are able to reproduce your reported issue at our end. We have logged it in our Issue Tracking System as METADATANET-2420 for further investigation. We shall keep you informed in case of any updates in this regard.

@Glority_Developer,

We further investigated your issue and noticed that you are checking metadata values using the default “file properties” dialog provided by Windows OS. Windows OS allows users to obtain some metadata values as follows:

  1. Right-click some image containing metadata
  2. Select the “Properties” menu item
  3. Switch on the “Details” tab

On the selected tab you can see some common information about the image. But the displayed values are not bound to particular metadata standards. Any field can display EXIF, XMP or IPTC properties depending on actual metadata values associated with the image. And obviously, it’s not guaranteed that a field displaying some metadata value will have the same name as the appropriate property in a particular standard. That’s why the “Details” tab cannot be used to check any values added by GroupDocs.Metadata.

In case you would have any questions, please feel free to let us know.

@ali.ahmed

Do you have any progress on this issue? Btw, “Camera serial number” field was removed during the conversion process. Is it the expected behavior, or this is a bug of GroupDocs.Metadata library?

@Glority_Developer,

Thanks for coming back.

Please update and get subject’s value using following code snippet are provide your feedback.

using (TiffFormat tiff = new TiffFormat(@"D:\Flowerboy_orginal.tif"))
{
    tiff.XmpValues.Schemes.DublinCore.SetSubject("test subject");
    tiff.Save(@"D:\Flowerboy_orginal_output.tif");
}

using (TiffFormat tiff = new TiffFormat(@"D:\Flowerboy_orginal_output.tif"))
{
    foreach (string dublinCoreSubject in tiff.XmpValues.Schemes.DublinCore["dc:subject"].ToStringArray())
    {
        Console.WriteLine(dublinCoreSubject);
    }
}

Would you please further explain the conversion process?

@Glority_Developer,

The issues you have found earlier (logged as METADATANET-2418 and METADATANET-2420 ) has been fixed in this release.

Thanks for the update. However, our license can’t be used to test GroupDocs v18.9. Is there any way we can test it without license? If we verify it’s fixed, then we may consider to purchase license again.

@Glority_Developer,

In that case, you can get a Temporary License to verify the fix. You can post your request for the Temporary License here.

We tested v19.3, but we found Subject can’t be deleted. Tilte and Auther can be deleted. Do you have the code sample to remove Subject?

@Glority_Developer,

There are 2 ways to remove the Subject field from a TIF image:

  • Using TiffFormat.CleanMetadata() method - Cleans all the metadata including Subject field.
  • Using TiffFormat.XmpValues.Schemes.DublinCore.SetSubject() method - To set/remove only the Subject field.

The following code snippet uses both of the above-mentioned ways:

// Remove Subject field.
using (TiffFormat tiff = new TiffFormat("Flowerboy_orginal.tif"))
{
    // To remvoe only the Subject field, pass empty string to the SetSubject() method.
	// TiffFormat.XmpValues.Schemes.DublinCore.SetSubject(string.Empty);

    // Use TiffFormat.CleanMetadata() method to clean all metadata fields.
	tiff.CleanMetadata();

    // Save file
	tiff.Save("Flowerboy_orginal_output.tif");
}

// Get subject field of saved file for verification.
using (TiffFormat tiff = new TiffFormat("Flowerboy_orginal_output.tif"))
{
	foreach (string dublinCoreSubject in tiff.XmpValues.Schemes.DublinCore.Subjects)
	{
		Console.WriteLine(dublinCoreSubject);
	}
}

We have tried the method you mentioned, but it won’t remove Subject property which we see using the system file property > Details.

The Subject your API tries to remove is for “Tags”, not the Subject property we see in Details. However, it doesn’t remove “Tags”, either.

Do you have the API to remove the Subject property we see in Details?

@Glority_Developer,

As we have mentioned in this reply, the “Details” tab in file’s Properties dialogue in Windows cannot be used to check any values added by GroupDocs.Metadata because displayed values are not bound to particular metadata standards. Any field can display EXIF, XMP or IPTC properties depending on actual metadata values associated with the image.

If we have a look at the Windows Imaging Component documentation, WIC reads and writes the Subject value (see the “TIFF Policy” -> “Read Paths” and “Write Paths”) from the path /ifd/{ushort=40095}. The tag with id 40095 is actually a part of EXIF metadata stored in the image. So, we can find it among the other EXIF tags using the TiffFormat.ExifValues.Tags collection.

Since this tag is not widely used, GroupDocs.Metadata doesn’t provide any shortcut property to get or set its value. However, you still can replace or remove the tag with the code snippet below:

ushort tagId = 40095; // tagid used for Subject field in the file's Properties dialogue in Windows
using (TiffFormat tiff = new TiffFormat(@"D:\input.tif"))
{
    List<TiffTag> tags = new List<TiffTag>(tiff.ExifValues.Tags);

    for (int i = tags.Count - 1; i >= 0; i--)
    {
        TiffTag tag = tags[i];

        // Change the condition to remove multiple tags
        if ((int)tag.DefinedTag == tagId)
        {
            tags.Remove(tag);
            break;
        }
    }

    // To update the value of the tag
    //tags.Add(new TiffByteTag((TiffTagIdEnum)tagId, Encoding.Unicode.GetBytes("new subject")));

    // Update the whole tag collection
    tiff.ExifValues.Tags = tags.ToArray();
    tiff.Save(@"D:\output.tif");
}

We also have logged it in our Issue Tracking System (ID: METADATANET-2824) to provide the feature of setting or removing individual TIFF tags instead of replacing the tags collection. We shall keep you informed in case of any updates regarding this feature.

@Glority_Developer

We implemented an improvement in the API against METADATANET-2824. Please download latest version of the API and share your feedback.