0

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).

vdua
  • 1,281
  • 1
  • 14
  • 24
  • You need to show us the code used to print with – MadProgrammer Dec 09 '12 at 19:00
  • Sorry but, I didn't get you. This is the entire code that I am using to print my image file (C:\\logs\\qrcode.gif). Attribute set is null. ( I have tried setting the resolution but my printer only supports 180 DPI). I am selecting the printer by its name ( which is a very obvious code), I felt that code might not be of any help. – vdua Dec 10 '12 at 08:27

0 Answers0