How to open a pdf and respective print dialogbox on a single action (button click) without showing pdf on web screen?

Viewed 39

I need to print a pdf on my action. On a single button click I want to generate a pdf without showing it on web screen and simultaneously pop up print dialogue box to print that pdf. Currently, this scenario is perfectly working on my local machine, but whenever any other system tries to access my machine (using my URL i.e. http://myMchineIPaddress:8081/) then print dialogue box is poped up on my machine and not from the machine who is actually giving the print command.

Is there any way to open print dialogue box on machine from which print command is actually given ?

Below is the code which I am using:

// configurePrinterJob
            PrinterJob printerJob = PrinterJob.getPrinterJob();
            Book book = new Book();
            PageFormat documentPageFormat = new PageFormat();
            documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
            book.append(subpdfDocument.getPrintable(0), documentPageFormat);
            printerJob.setPageable(book);

            PrintService printService = PrintServiceFinder.findPrintService(printer);
            if (printService != null) {
                printerJob.setPrintService(printService);
            } else {
                logger.warn("[PRINT] - Printer not found in the printerlist");
            }

            subpdfDocument.print(printerJob);
            subpdfDocument.close();

 public void print(PrinterJob printJob) throws PrinterException
{
    print(printJob, false);
}


private void print(PrinterJob job, boolean silent) throws PrinterException {
    if (job == null) {
        throw new PrinterException("The given printer job is null.");
    } else {
        job.setPageable(new PDPageable(this, job));
        if (silent || job.printDialog()) {
            job.print();
        }
    }
}
0 Answers
Related