PDF Batch Printing

Questions, tips and tricks and techniques for scripting in Servoy

PDF Batch Printing

Postby kwpsd » Tue Jul 23, 2013 12:46 am

Servoy 6.1.4
Smart Client

We have a need to batch print 3,000+ PDF documents every month. The PDF documents are stored as byte arrays in a table with column type MEDIA (BLOB). What is the best method to print the PDFs as a batch process?

We are able to print a single PDF document using Adobe Reader (version 10) launched as an external Windows process. However, when we attempt to batch print multiple PDF documents, the first document prints, then Adobe Reader hangs the solution until:

1. we manually close Adobe Reader

2. Adobe Reader times out (after several minutes).

We also can batch print PDF documents directly from the solution using an old version of jPedal, however, these print reduced size, and we cannot figure out how to adjust the print scale.

Would someone be kind enough to provide direction and, perhaps, a code example?

Thanks!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: PDF Batch Printing

Postby m.vanklink » Tue Jul 23, 2013 8:20 am

We are using apache pdfbox (http://pdfbox.apache.org) for printing PDF documents:

Code: Select all
var _file_name = 'file_to_print.pdf'
var _printer_name = 'printer_to_print_to'
var _printerJob = Packages.java.awt.print.PrinterJob.getPrinterJob()
var _printServices = Packages.javax.print.PrintServiceLookup.lookupPrintServices(null, null)
for (var _i=0; _i<_printServices.length; _i++) {
   if (_printServices[_i].getName() == _printer_name) {
      _printerJob.setPrintService(_printServices[_i])
      break
   }
}
var _document = Packages.org.apache.pdfbox.pdmodel.PDDocument.load(_file_name)
_document.silentPrint(_printerJob)


You can put the pdb_box-jar in the beans directory.
Michel van Klink
Vision Development
m.vanklink
 
Posts: 70
Joined: Thu Feb 23, 2012 9:15 am
Location: The Netherlands

Re: PDF Batch Printing

Postby robysimo09 » Tue Jul 23, 2013 10:04 am

Hi

I downloaded the .jar file, put it into beans directory and tried.
I use the same code that you write in the last reply.
I send the output to my printer, I saw a new line in the printer queue but only for a second. then disappear and the printer doesn't print.

What's the error in your opinion?
I use servoy 5.2.15.

In the _file_name variable I set the full path of the pdf file. If I set only the name I give an error.
Is it correct?
Thank you very much.
Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: PDF Batch Printing

Postby m.vanklink » Tue Jul 23, 2013 10:47 am

Yes, correct, _file_name is full path to the pdf-file. Servoy 5.2.x should be okay, we are using 5.2.16. If there appears a line in the printer queue it looks like the file is delivered to the printer.
The printer has to be able to handle pdf-documents, maybe that's the problem. Or maybe the file is not a (correct) pdf file.
Michel van Klink
Vision Development
m.vanklink
 
Posts: 70
Joined: Thu Feb 23, 2012 9:15 am
Location: The Netherlands

Re: PDF Batch Printing

Postby robysimo09 » Tue Jul 23, 2013 11:33 am

Thank you for fast answer.

The file is a correct pdf file ( I tried with different files ).
What does it mean "The printer has to be able to handle pdf-documents"?
If I open the pdf file and push the print button of Acrobat Reader I print correctly the file.

Thank you very much.
Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: PDF Batch Printing

Postby kwpsd » Tue Jul 23, 2013 11:53 pm

Hi, Michel.

Thank you for your response.

Using your code example and the Apache PDFBox jar, I am able to print PDF documents, but there are a couple of issues:

1. Printing is slow! It takes approximately 40 seconds to print each PDF document.

2. The resulting printout does not represent the PDF document as viewed in Adobe Reader. For example, the summary at the bottom of the document prints several inches up from the bottom thereby over-writing a portion of the printout.

3. Like jPedal, the printed PDF document is reduced in size (about 80%).

I suspect the slow printing has something to do with the document rendering process in PDFBox and that there is nothing I can do to speed this up. By comparison, when I print using Adobe Reader, the document starts printing in about 10 seconds. Does this observation match your own experience?

I looked at the on-line PDFBox documentation under PDDocument and could not find anything regarding print scaling. Do your documents print at 80% as well? If not, how did you get around this? I was looking for a 'FIt to Page' setting but could find none. Again, by comparison, Adobe Reader prints the same PDF document full page with no reduction in size.

Any further help you may provide will be greatly appreciated.
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: PDF Batch Printing

Postby kwpsd » Wed Jul 24, 2013 1:15 am

Answering my own post.

For PDFBox:

Adding the following line of code (after the document has printed) helps to speed things up:

Code: Select all
    _document.close()


I still do not know how to scale the PDF document. However, I did discovered that my printer default paper setting was set to size 'B4'. Changing the default size to 'letter' results in the PDF document being printed full page.

This had no effect on jPedal which is still printing at a scale of approximately 80%.
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: PDF Batch Printing

Postby m.vanklink » Wed Jul 24, 2013 8:19 am

You are right, I omitted that. The example code came from a try block, _document.close() was in the finally block.

I am not experiencing these problems of not printing (Roberto) or not printing exactly the same as Acrobat Reader (Kim), so I'm afraid I cannot help you with that.
Michel van Klink
Vision Development
m.vanklink
 
Posts: 70
Joined: Thu Feb 23, 2012 9:15 am
Location: The Netherlands

Re: PDF Batch Printing

Postby robysimo09 » Wed Jul 24, 2013 9:30 am

Hi

what version of bean you use?
I downloaded pdfbox-1.8.2.jar and put it directly on beans directory. Is this correct?
Thank you
Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am

Re: PDF Batch Printing

Postby m.vanklink » Wed Jul 24, 2013 9:44 am

I'm using 1.7.0 and have put pdfbox-1.7.0.jar and also the files fontbox-1.7.0.jar and jempbox-1.7.0.jar directly in the beans directory.

See also: http://pdfbox.apache.org/dependencies.html, commons-logging is already shipped with Servoy in the lib directory
Michel van Klink
Vision Development
m.vanklink
 
Posts: 70
Joined: Thu Feb 23, 2012 9:15 am
Location: The Netherlands

Re: PDF Batch Printing

Postby robysimo09 » Wed Jul 24, 2013 10:16 am

So sorry.
I haven't read the dependencies.
It work with last version of files.

Thank you very much for help.
Bye
Roberto
robysimo09
 
Posts: 108
Joined: Fri Sep 04, 2009 9:06 am


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests