{
LOG.debug("Using unknown TIFF image writer: " + metadata.getNativeMetadataFormatName());
return;
}
IIOMetadataNode root = new IIOMetadataNode(SUN_TIFF_FORMAT);
IIOMetadataNode ifd;
if (root.getElementsByTagName("TIFFIFD").getLength() == 0)
{
ifd = new IIOMetadataNode("TIFFIFD");
ifd.setAttribute("tagSets",
"com.sun.media.imageio.plugins.tiff.BaselineTIFFTagSet");
root.appendChild(ifd);
}
else
{
ifd = (IIOMetadataNode)root.getElementsByTagName("TIFFIFD").item(0);
}
// standard metadata does not work, so we set the DPI manually
ifd.appendChild(createRationalField(282, "XResolution", dpi, 1));
ifd.appendChild(createRationalField(283, "YResolution", dpi, 1));
ifd.appendChild(createShortField(296, "ResolutionUnit", 2)); // Inch
ifd.appendChild(createLongField(278, "RowsPerStrip", image.getHeight()));
ifd.appendChild(createAsciiField(305, "Software", "PDFBOX"));
if (image.getType() == BufferedImage.TYPE_BYTE_BINARY &&
image.getColorModel().getPixelSize() == 1)
{
// set PhotometricInterpretation WhiteIsZero
// because of bug in Windows XP preview
ifd.appendChild(createShortField(262, "PhotometricInterpretation", 0));
}
try
{
metadata.mergeTree(SUN_TIFF_FORMAT, root);