You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ranjith Kodikara <sr...@yahoo.com.INVALID> on 2016/06/18 11:57:24 UTC

Sending the PDF document silently to a pre-defined printer

Hi,
I use PDFBox for a long time in my system. What I do is downloading the PDF file through the URL and printing it. I print using the silentPrint() method. It goes to the default printer.
The requirement is to send the print to a pre-defined printer. Every client machine should have  the printer named "Receipt_Printer" added to it with  the exact name and the OS is windows. The program is to be modified to send the  "Receipt" pdf document to "Receipt_Printer" and other PDF's to default printer (with silentPrint() method).
Anyone knows how it can be sent to the "Receipt_Printer" bypassing default printer. I can offer the user to selectt the printer and proceed, but the requirement is to print invisibly to "Receipt_Printer" without offering the user to select the printer.
If anybody can help it'll be great.(or may be for commercial, we are ok)
thanks,Ranjith

Re: Sending the PDF document silently to a pre-defined printer

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 08.07.2016 um 19:15 schrieb Ranjith Kodikara:
> Hi,
> Thanks Tilman for reply.
> below is the code I am using. So with this code, is it possible to direct the output to a specific printer(not just the default printer)
>
>
>          PDDocument document = null;         try {            URL pdfFile = new URL(pdfURLStr);            document = PDDocument.load(pdfFile);            PrinterJob pr = PrinterJob.getPrinterJob();             if (this.defaultPrinter. equalsIgnoreCase("Y")) {                document.silentPrint(pr);                //document.print(pr);            } else {                if (pr.printDialog()) {                document.silentPrint(pr);                //document.print(pr);                }            }              document.close();         } catch (Exception ex) {            write_message(ex.getMessage()) ;            System.out.println("Error message : "+ex.getMessage());            ex.printStackTrace();        }
>   
>
>      On Saturday, June 18, 2016 8:00 PM, Tilman Hausherr <TH...@t-online.de> wrote:
>   
>
>   Am 18.06.2016 um 13:59 schrieb Ranjith Kodikara:
>>
>>    Hi,
>> I use PDFBox for a long time in my system. What I do is downloading the PDF file through the URL and printing it. I print using the silentPrint() method. It goes to the default printer.
>> The requirement is to send the print to a pre-defined printer. Every client machine should have  the printer named "Receipt_Printer" added to it with  the exact name and the OS is windows. The program is to be modified to send the  "Receipt" pdf document to "Receipt_Printer" and other PDF's to default printer (with silentPrint() method).
>> Anyone knows how it can be sent to the "Receipt_Printer" bypassing default printer. I can offer the user to selectt the printer and proceed, but the requirement is to print invisibly to "Receipt_Printer" without offering the user to select the printer.
>> If anybody can help it'll be great.(or may be for commercial, we are ok)
>> thanks,Ranjith
>>
>>      
>
> Would this help?
>
> https://stackoverflow.com/questions/4177531/force-target-printer-in-java


Hi,

Your code doesn't show that you did anything specific related to the 
link I mentioned. That code shows how to configure the PrinterJob object 
to use a specific printer.

So what you should do is:
- try the code from that question
- if it doesn't work, open a new stackoverflow question and include the 
code that you used.

I can't help you directly, I usually don't print, and this isn't really 
a PDFBox question.

Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Sending the PDF document silently to a pre-defined printer

Posted by Tilman Hausherr <TH...@t-online.de>.
I'm looking at the source code of PrintPDF, it has a "secret" option 
"-printerName". Here's the code that is used:

             PrinterJob printJob = PrinterJob.getPrinterJob();
             printJob.setJobName(new File(pdfFile).getName());

             if (printerName != null)
             {
                 PrintService[] printService = 
PrinterJob.lookupPrintServices();
                 boolean printerFound = false;
                 for (int i = 0; !printerFound && i < 
printService.length; i++)
                 {
                     if (printService[i].getName().contains(printerName))
                     {
                         printJob.setPrintService(printService[i]);
                         printerFound = true;
                     }
                 }
             }
             printJob.setPageable(new PDFPageable(document));

             if (silentPrint || printJob.printDialog())
             {
                 printJob.print();
             }

Note that this is for 2.0.2.

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Sending the PDF document silently to a pre-defined printer

Posted by Ranjith Kodikara <sr...@yahoo.com.INVALID>.
Hi,
Thanks Tilman for reply.
below is the code I am using. So with this code, is it possible to direct the output to a specific printer(not just the default printer)


        PDDocument document = null;         try {            URL pdfFile = new URL(pdfURLStr);            document = PDDocument.load(pdfFile);            PrinterJob pr = PrinterJob.getPrinterJob();             if (this.defaultPrinter. equalsIgnoreCase("Y")) {                document.silentPrint(pr);                //document.print(pr);            } else {                if (pr.printDialog()) {                document.silentPrint(pr);                //document.print(pr);                }            }              document.close();         } catch (Exception ex) {            write_message(ex.getMessage()) ;            System.out.println("Error message : "+ex.getMessage());            ex.printStackTrace();        } 
 

    On Saturday, June 18, 2016 8:00 PM, Tilman Hausherr <TH...@t-online.de> wrote:
 

 Am 18.06.2016 um 13:59 schrieb Ranjith Kodikara:
>
>
>  Hi,
> I use PDFBox for a long time in my system. What I do is downloading the PDF file through the URL and printing it. I print using the silentPrint() method. It goes to the default printer.
> The requirement is to send the print to a pre-defined printer. Every client machine should have  the printer named "Receipt_Printer" added to it with  the exact name and the OS is windows. The program is to be modified to send the  "Receipt" pdf document to "Receipt_Printer" and other PDF's to default printer (with silentPrint() method).
> Anyone knows how it can be sent to the "Receipt_Printer" bypassing default printer. I can offer the user to selectt the printer and proceed, but the requirement is to print invisibly to "Receipt_Printer" without offering the user to select the printer.
> If anybody can help it'll be great.(or may be for commercial, we are ok)
> thanks,Ranjith
>
>    


Would this help?

https://stackoverflow.com/questions/4177531/force-target-printer-in-java




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



  

Re: Sending the PDF document silently to a pre-defined printer

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 18.06.2016 um 13:59 schrieb Ranjith Kodikara:
>
>
>   Hi,
> I use PDFBox for a long time in my system. What I do is downloading the PDF file through the URL and printing it. I print using the silentPrint() method. It goes to the default printer.
> The requirement is to send the print to a pre-defined printer. Every client machine should have  the printer named "Receipt_Printer" added to it with  the exact name and the OS is windows. The program is to be modified to send the  "Receipt" pdf document to "Receipt_Printer" and other PDF's to default printer (with silentPrint() method).
> Anyone knows how it can be sent to the "Receipt_Printer" bypassing default printer. I can offer the user to selectt the printer and proceed, but the requirement is to print invisibly to "Receipt_Printer" without offering the user to select the printer.
> If anybody can help it'll be great.(or may be for commercial, we are ok)
> thanks,Ranjith
>
>    


Would this help?

https://stackoverflow.com/questions/4177531/force-target-printer-in-java




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Sending the PDF document silently to a pre-defined printer

Posted by Ranjith Kodikara <sr...@yahoo.com.INVALID>.


 Hi,
I use PDFBox for a long time in my system. What I do is downloading the PDF file through the URL and printing it. I print using the silentPrint() method. It goes to the default printer.
The requirement is to send the print to a pre-defined printer. Every client machine should have  the printer named "Receipt_Printer" added to it with  the exact name and the OS is windows. The program is to be modified to send the  "Receipt" pdf document to "Receipt_Printer" and other PDF's to default printer (with silentPrint() method).
Anyone knows how it can be sent to the "Receipt_Printer" bypassing default printer. I can offer the user to selectt the printer and proceed, but the requirement is to print invisibly to "Receipt_Printer" without offering the user to select the printer.
If anybody can help it'll be great.(or may be for commercial, we are ok)
thanks,Ranjith