To set Tiff tags in Java, you need to specify the tag’s code, name, and value, as explained here.
But certain tags hold a peculiarity of having a “Count 2” attribute, which means that one tag can receive two values:
Setting these tags in Java requires this code in addition to PDFBox codes.
private static IIOMetadataNode createShortField(int tiffTagNumber, String name, int val1, int val2) {
IIOMetadataNode field = new IIOMetadataNode("TIFFField");
field.setAttribute("number", Integer.toString(tiffTagNumber));
field.setAttribute("name", name);
IIOMetadataNode arrayNode = new IIOMetadataNode("TIFFShorts");
field.appendChild(arrayNode);
IIOMetadataNode valueNode1 = new IIOMetadataNode("TIFFShort");
arrayNode.appendChild(valueNode1);
valueNode1.setAttribute("value", Integer.toString(val1));
IIOMetadataNode valueNode2 = new IIOMetadataNode("TIFFShort");
arrayNode.appendChild(valueNode2);
valueNode2.setAttribute("value", Integer.toString(val2));
return field;
}