Building the Doc that will be printedsuggest change
Doc is an interface and the Java Print Service API provide a simple implementation called
Doc instance is basically made of two aspects:
- the print data content itself (an E-mail, an image, a document etc)
- the print data format, called
DocFlavor(MIME type + Representation class).
Before creating the
Doc object, we need to load our document from somewhere. In the example, we will load an specific file from the disk:
FileInputStream pdfFileInputStream = new FileInputStream("something.pdf");
So now, we have to choose a
DocFlavor that matches our content. The
DocFlavor class has a bunch of constants to represent the most usual types of data. Let’s pick the
DocFlavor pdfDocFlavor = DocFlavor.INPUT_STREAM.PDF;
Now, we can create a new instance of
Doc doc = new SimpleDoc(pdfFileInputStream, pdfDocFlavor , null);
doc object now can be sent to the print job request (see Creating a print job from a print service).