• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help Printing

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to print a jpeg that is stored as a BufferdImage. I do not want to have to save the file to the hard drive first so I thought I wound try BufferedImage. No luck, keep getting the error "data is not of the declared type". Im sure it has to do with the line when I pass the buffered image object to Doc: "Doc doc = new SimpleDoc(image, flavor, das);" The code is below. The code has it loading a file from the hard drive, when I integrate this into my program, I will simply pass the bufferedimage to it. Thanks!
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.imageio.*;
public class Printing {
public static void main(String args[]) throws Exception {
String filename = "ad.jpg";
PrintRequestAttributeSet pras =
new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();

BufferedImage image = ImageIO.read(new FileInputStream(filename));
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(image, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}
}
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic