1

I have written the below code in java for printing a simple pdf file,

public class Test {

    public static void main(String[] args) throws PrinterException, IOException {

        PrinterJob pj= PrinterJob.getPrinterJob();
        List<PrintService> plist= new ArrayList<PrintService>();

        for (PrintService ps: pj.lookupPrintServices()) {
            plist.add(printService);
        }

        for (PrintService ps: plist) {
            if (printService.getName().contains("MyPrinterName")) {
                pj.setJobName("test");
                pj.setPrintService(printService);
                print(pj, "C:\\Users\\been\\Desktop\\hi.pdf", MediaTray.TOP);
            }
        }
    }

    private static void print(final PrinterJob pj, final String path, final MediaTray tray) throws IOException, PrinterException {

        PrintRequestAttributeSet pas= new HashPrintRequestAttributeSet();
        pas.add(tray);           

            PDDocument document = PDDocument.load(path);
            pj.setPageable(document);
            pas.add(new PageRanges(1, 2));
            pj.print(printRequestAttributeSet);


    }

}

I'm using pdfbox 1.8.0 jar to read a pdf file. I used eclips with JDK1.6.0_43 as a development platform. I can able to get the print in windows OS, but when i run the same code in solaris os i didnt get the print out. My print get a job with zero page. Can you please help. Many Thanks.

stacktome
  • 790
  • 2
  • 9
  • 32

0 Answers0