Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Printing a string from Java (INPUT_STREAM/BYTE_ARRAY)

jtyremanOct 1 2013

Hi all,

got the following code:

        DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.AUTOSENSE;

        Doc myDoc = new SimpleDoc(content.getBytes(), psInFormat, null);

        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

        PrintService[] services =

            PrintServiceLookup.lookupPrintServices(psInFormat, aset);

        aset.add(new Copies(1));

        // this step is necessary because I have several printers configured

        PrintService myPrinter = null;

        for (int i = 0; i < services.length; i++) {

            String svcName = services[i].toString();

            System.out.println("service found: " + svcName);

            if (svcName.contains("BranchTest")) {

                myPrinter = services[i];

            }

        }

        if (myPrinter != null) {

            DocPrintJob job = myPrinter.createPrintJob();

            try {

                PrintJobWatcher pjw = new PrintJobWatcher(job);

                job.print(myDoc, aset);

                pjw.waitForDone();

   

                } catch (Exception pe) {

                pe.printStackTrace();

            }

        } else {

            returnString = "no printer services found";

        }

    }

the issue is that on eclipse within a windows environment this works perfectly, but on linux with only a ppd installed for the printer it errors, it looks like it is interpreting the string as postscript?

2 Questions:

A ) is there a different way of printing a string through Java


B) is there a way of printing a string in POSTSCRIPT?

Many Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2013
Added on Oct 1 2013
0 comments
264 views