Building the Doc that will be printed

suggest change

Doc is an interface and the Java Print Service API provide a simple implementation called SimpleDoc.

Every Doc instance is basically made of two aspects:

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 INPUT_STREAM.PDF one:

DocFlavor pdfDocFlavor = DocFlavor.INPUT_STREAM.PDF;

Now, we can create a new instance of SimpleDoc:

Doc doc = new SimpleDoc(pdfFileInputStream, pdfDocFlavor , null);

The doc object now can be sent to the print job request (see Creating a print job from a print service).

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents