I am using java print API to print image and some text to a thermal printer. I tried using the Printable interface but I was not able to draw a String as well as Image. So I read a file from the filesystem and then print it directly. There are separate print commands to print images and text. Here is the code that I use
try {
textStream = new FileInputStream("C:\\logs\\qrcode.gif");
} catch (FileNotFoundException ffne) {
}
if (textStream != null && printer != null) {
DocFlavor myFormat = DocFlavor.INPUT_STREAM.GIF;
// Create a Doc
Doc myDoc = new SimpleDoc(textStream, myFormat, null);
DocPrintJob job = printer.createPrintJob();
try {
job.print(myDoc,set);
} catch (PrintException e) {
logger.log(Level.SEVERE,e.getMessage(),e);
}
}
The size of the image is 360 X 360 and printer resolution is 180DPI but the image that is getting print is very small
Here is an image https://i.stack.imgur.com/oK3sX.jpg
But when I print the image file directly it takes the full page. (There is an option which you can select to print the page to entire frame). How to do the same using Java ? I have also implemented the printable interface but the printed image gets shifted to the right. I couldn't align it on the left end (when I use drawImage at 0,0 it was drawing from the middle and hence not coming up on the entire page).