Skip to main content

Insert a text banner in TIFF

2 replies [Last post]
Anonymous

Just wondering if there is any idea how to insert a banner in a TIFF file. Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23

I am afraid that I do not know what you are asking. Would you please elaborate?

> Just wondering if there is any idea how to insert a
> banner in a TIFF file. Thanks

pmckee816
Offline
Joined: 2009-02-22

I am attempting to do a similar task. Basically, I need to be able to read in a tiff file that might be tiled, compressed, uncompressed, single tiff or multipage tiff. On a multipage tiff, I need to add a banner (multilined message of approximately 100 words) to the top of the page outside the original image (increase the top border). Then I need to write the new image back out as a tiff file. I am able to do this with PDF documents using iText but iText does not support tiled tiffs (or some other tiff formats). Using iText, I am able to place the banner on multipage PDFs of 700+ pages in just a few seconds. I need to do the same with tiffs. The tiffs that I must work with range in size from 8x11 to J-Long sizes. I have used highlight.java from http://www.geocities.com/marcoschmidt.geo/java-highlight.html as a base for adding a banner on tiled tiffs but I haven't been able to figure out how to increase the top border or to work with multipage tiffs.
The code I am using is:
/*
* Highlight.java
*
* Created on June 3, 2005, 10:54 AM
* Original code from http://www.geocities.com/marcoschmidt.geo/java-highlight.html
*/

/*
* Highlight.java (requires Java 1.4+)
*/

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.util.*;

/**
* This command line program loads an image,
* highlights a rectangular section and
* saves the modified image to a new file.
*/
public class Highlight {
public static void main(String[] args) throws Exception {
// make sure we have exactly three arguments
if (args.length != 3)
{
System.err.println("Usage: java Highlight INFILE OUTFILE MESSAGE");
System.exit(1);
}
// load input image
BufferedImage image = ImageIO.read(new File(args[0]));

// do the highlighting
Graphics graphics = image.getGraphics();
Color fcolor = new Color(0, 0, 0, 255);
graphics.setColor(fcolor);

String MESSAGE = args[2];
String MESSAGE1 = "This document contains unclassified technical data exported under the authority of TA 1234-56 Expiration 2004-12-31.";
String MESSAGE2 = "These commodieites are authorized by the U.S. Government for export only to COUNTRY for use by XXXXXXX.They may not be";
String MESSAGE3 = "transferred, transshipped on a non-continuous voyage, or otherwise be disposed of in any other country in their original form";
String MESSAGE4 = "or afterbeing incorporated into other end-items, without prior written approval of the U.S. Department of state.";
String MESSAGE5 = "USERNAME Re-validate or destroy 14 days from 20050520 in accordance with EPP070. ";

graphics.setFont(new Font("Courier",Font.PLAIN,25));

Font fnt = graphics.getFont();
System.out.println(fnt);
//graphics.drawString("Highlight " + new Date() + " " + MESSAGE1, 50, 50);
graphics.drawString(MESSAGE1, 50, 50);
graphics.drawString(MESSAGE2, 50, 75);
graphics.drawString(MESSAGE3, 50, 100);
graphics.drawString(MESSAGE4, 50, 125);
graphics.drawString(MESSAGE5, 50, 150);
// save modified image
String format = "TIF";
if (args[1].toLowerCase().endsWith(".png")) {
format = "PNG";
}
ImageIO.write(image, format, new File(args[1]));
// System.exit(0)
}

Any suggestions on how to make this work or a better way to accomplish this would be appreciated.