I am trying to print barcode image files using java. I have Label Writer 450 Turbo. The label dimension is 2" X 0.75" inches, When I print the image from Photoshop with scale to fit option every thing works fine.
But with java code it does not scale the image in right way, so the barcode reader cannot read it anymore.
public class print {
public static void main(String[] str) {
// Input the file
FileInputStream textStream = null;
try {
textStream = new FileInputStream("barcode.jpg");
} catch (FileNotFoundException exp) {
return;
}
DocFlavor myFormat = DocFlavor.INPUT_STREAM.JPEG;
PageFormat format = new PageFormat();
format.setOrientation(PageFormat.PORTRAIT);
Doc myDoc = new SimpleDoc(textStream, myFormat, null);
// Build a set of attributes
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
// aset.add(new Copies(2));
aset.add(new MediaPrintableArea(0, 0, 0.75f, 2f,
MediaPrintableArea.INCH));
aset.add(PrintQuality.HIGH);
aset.add(new PrinterResolution(300, 600, PrinterResolution.DPI));
aset.add(OrientationRequested.LANDSCAPE);
PrintService[] services = PrintServiceLookup.lookupPrintServices(
myFormat, null);
if (services.length > 0) {
DocPrintJob job = services[5].createPrintJob();
for (Attribute temp : services[5].getAttributes().toArray())
System.out.println(temp.getName());
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
}
}
}
}
The barcode generated using krysalis barcode4j using the following settings
resolution -> 600
line height -> 15.35mm
Edit One: here is example of the two printed labels one using Photoshop with scale to fit option, and the other using java code