You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "guy.smadja@optic-box.com" <gu...@optic-box.com> on 2015/01/11 14:44:16 UTC

PDFBOX as a windows Service

Hello

We launch as a dos command an application that listen incoming request to print documents with PDFBOX:
PDDocument document = PDDocument.load(new URL(d[1]));
PrinterJob printJob = PrinterJob.getPrinterJob();
if (printer == null) {
System.out.println("printer " + d[0] + " not found. Default printer choosen");
                PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
                printJob.setPrintService(printService);
} else {
          PrintService[] printServices = PrinterJob.lookupPrintServices();
          for (PrintService printService : printServices) {
                      if (printService.getName().equals(printer)){
                          printJob.setPrintService(printService);
                          break;
}
}
document.print(printJob);
document.close();

Everything seems perfect.

But when I put this application as a Windows Service the document is Half of its size.
Do you have an Idea ?

Thanks


Guy Smadja
Opticemarket.com
http://www.optic-box.com
Tel : 01 76 71 08 32


RE: PDFBOX as a windows Service

Posted by "guy.smadja@optic-box.com" <gu...@optic-box.com>.
Thank you for the response.

-----Message d'origine-----
De : Frank van der Hulst [mailto:drifter.frank@gmail.com] 
Envoyé : dimanche 11 janvier 2015 23:53
À : users@pdfbox.apache.org
Objet : Re: PDFBOX as a windows Service

Hi Guy,

When you set up the Service, you can tell Windows what credentials to use to run the job. By default, it will be Local Admin, but you can give it any AD user (and password).

Try running the job under your own credentials.

Frank


On Mon, Jan 12, 2015 at 11:12 AM, John Hewson <jo...@jahewson.com> wrote:

> Hi Guy,
>
> The print(PrinterJob job) method of PDDocument calls job.printDialog() 
> which shows the system print dialog where the user can specify custom 
> print settings.
>
> Window services run under a non-interactive user account, rather than 
> running as the current user. That means you won’t see the print 
> dialog, and you won’t get any of the default print settings belonging 
> to the your desktop user.
>
> I suspect that your desktop user has set some custom printing 
> preferences and these are being passed to Java either via 
> printDialog() or as the PrinterJob defaults. Try calling the 
> silentPrint(job) method on PDDocument to bypass the dialog. If that 
> does not work, you will need to specify the print settings you want using the PrinterJob object.
>
> -- John
>
> > On 11 Jan 2015, at 05:44, guy.smadja@optic-box.com wrote:
> >
> > Hello
> >
> > We launch as a dos command an application that listen incoming 
> > request
> to print documents with PDFBOX:
> > PDDocument document = PDDocument.load(new URL(d[1])); PrinterJob 
> > printJob = PrinterJob.getPrinterJob(); if (printer == null) { 
> > System.out.println("printer " + d[0] + " not found. Default printer
> choosen");
> >                 PrintService printService =
> PrintServiceLookup.lookupDefaultPrintService();
> >                 printJob.setPrintService(printService);
> > } else {
> >           PrintService[] printServices =
> PrinterJob.lookupPrintServices();
> >           for (PrintService printService : printServices) {
> >                       if (printService.getName().equals(printer)){
> >                           printJob.setPrintService(printService);
> >                           break;
> > }
> > }
> > document.print(printJob);
> > document.close();
> >
> > Everything seems perfect.
> >
> > But when I put this application as a Windows Service the document is
> Half of its size.
> > Do you have an Idea ?
> >
> > Thanks
> >
> >
> > Guy Smadja
> > Optic <http://opticemarket.com/>e 
> > <http://opticemarket.com/>market.com <
> http://opticemarket.com/>
> > http://www.optic-box.com <http://www.optic-box.com/> Tel : 01 76 71 
> > 08 32
>
>

Re: PDFBOX as a windows Service

Posted by Frank van der Hulst <dr...@gmail.com>.
Hi Guy,

When you set up the Service, you can tell Windows what credentials to use
to run the job. By default, it will be Local Admin, but you can give it any
AD user (and password).

Try running the job under your own credentials.

Frank


On Mon, Jan 12, 2015 at 11:12 AM, John Hewson <jo...@jahewson.com> wrote:

> Hi Guy,
>
> The print(PrinterJob job) method of PDDocument calls job.printDialog()
> which shows the system print dialog where the user can specify custom
> print settings.
>
> Window services run under a non-interactive user account, rather than
> running as the current user. That means you won’t see the print dialog,
> and you won’t get any of the default print settings belonging to the
> your desktop user.
>
> I suspect that your desktop user has set some custom printing
> preferences and these are being passed to Java either via printDialog()
> or as the PrinterJob defaults. Try calling the silentPrint(job) method on
> PDDocument to bypass the dialog. If that does not work, you will need
> to specify the print settings you want using the PrinterJob object.
>
> -- John
>
> > On 11 Jan 2015, at 05:44, guy.smadja@optic-box.com wrote:
> >
> > Hello
> >
> > We launch as a dos command an application that listen incoming request
> to print documents with PDFBOX:
> > PDDocument document = PDDocument.load(new URL(d[1]));
> > PrinterJob printJob = PrinterJob.getPrinterJob();
> > if (printer == null) {
> > System.out.println("printer " + d[0] + " not found. Default printer
> choosen");
> >                 PrintService printService =
> PrintServiceLookup.lookupDefaultPrintService();
> >                 printJob.setPrintService(printService);
> > } else {
> >           PrintService[] printServices =
> PrinterJob.lookupPrintServices();
> >           for (PrintService printService : printServices) {
> >                       if (printService.getName().equals(printer)){
> >                           printJob.setPrintService(printService);
> >                           break;
> > }
> > }
> > document.print(printJob);
> > document.close();
> >
> > Everything seems perfect.
> >
> > But when I put this application as a Windows Service the document is
> Half of its size.
> > Do you have an Idea ?
> >
> > Thanks
> >
> >
> > Guy Smadja
> > Optic <http://opticemarket.com/>e <http://opticemarket.com/>market.com <
> http://opticemarket.com/>
> > http://www.optic-box.com <http://www.optic-box.com/>
> > Tel : 01 76 71 08 32
>
>

RE: PDFBOX as a windows Service

Posted by "guy.smadja@optic-box.com" <gu...@optic-box.com>.
Thank you for the response.

-----Message d'origine-----
De : John Hewson [mailto:john@jahewson.com] 
Envoyé : dimanche 11 janvier 2015 23:12
À : users@pdfbox.apache.org
Objet : Re: PDFBOX as a windows Service

Hi Guy,

The print(PrinterJob job) method of PDDocument calls job.printDialog() which shows the system print dialog where the user can specify custom print settings.

Window services run under a non-interactive user account, rather than running as the current user. That means you won’t see the print dialog, and you won’t get any of the default print settings belonging to the your desktop user.

I suspect that your desktop user has set some custom printing preferences and these are being passed to Java either via printDialog() or as the PrinterJob defaults. Try calling the silentPrint(job) method on PDDocument to bypass the dialog. If that does not work, you will need to specify the print settings you want using the PrinterJob object.

-- John

> On 11 Jan 2015, at 05:44, guy.smadja@optic-box.com wrote:
> 
> Hello
>  
> We launch as a dos command an application that listen incoming request to print documents with PDFBOX:
> PDDocument document = PDDocument.load(new URL(d[1])); PrinterJob 
> printJob = PrinterJob.getPrinterJob(); if (printer == null) { 
> System.out.println("printer " + d[0] + " not found. Default printer choosen");
>                 PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
>                 printJob.setPrintService(printService);
> } else {
>           PrintService[] printServices = PrinterJob.lookupPrintServices();
>           for (PrintService printService : printServices) {
>                       if (printService.getName().equals(printer)){
>                           printJob.setPrintService(printService);
>                           break;
> }
> }
> document.print(printJob);
> document.close();
>  
> Everything seems perfect.
>  
> But when I put this application as a Windows Service the document is Half of its size.
> Do you have an Idea ?
>  
> Thanks
>  
>  
> Guy Smadja
> Optic <http://opticemarket.com/>e <http://opticemarket.com/>market.com 
> <http://opticemarket.com/> http://www.optic-box.com 
> <http://www.optic-box.com/> Tel : 01 76 71 08 32


Re: PDFBOX as a windows Service

Posted by John Hewson <jo...@jahewson.com>.
Hi Guy,

The print(PrinterJob job) method of PDDocument calls job.printDialog()
which shows the system print dialog where the user can specify custom
print settings.

Window services run under a non-interactive user account, rather than
running as the current user. That means you won’t see the print dialog,
and you won’t get any of the default print settings belonging to the
your desktop user.

I suspect that your desktop user has set some custom printing
preferences and these are being passed to Java either via printDialog()
or as the PrinterJob defaults. Try calling the silentPrint(job) method on
PDDocument to bypass the dialog. If that does not work, you will need
to specify the print settings you want using the PrinterJob object.

-- John

> On 11 Jan 2015, at 05:44, guy.smadja@optic-box.com wrote:
> 
> Hello
>  
> We launch as a dos command an application that listen incoming request to print documents with PDFBOX:
> PDDocument document = PDDocument.load(new URL(d[1]));
> PrinterJob printJob = PrinterJob.getPrinterJob();
> if (printer == null) {
> System.out.println("printer " + d[0] + " not found. Default printer choosen");
>                 PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
>                 printJob.setPrintService(printService);
> } else {
>           PrintService[] printServices = PrinterJob.lookupPrintServices();
>           for (PrintService printService : printServices) {
>                       if (printService.getName().equals(printer)){
>                           printJob.setPrintService(printService);
>                           break;
> }
> }
> document.print(printJob);
> document.close();
>  
> Everything seems perfect.
>  
> But when I put this application as a Windows Service the document is Half of its size.
> Do you have an Idea ?
>  
> Thanks
>  
>  
> Guy Smadja
> Optic <http://opticemarket.com/>e <http://opticemarket.com/>market.com <http://opticemarket.com/>
> http://www.optic-box.com <http://www.optic-box.com/>
> Tel : 01 76 71 08 32