Hi, > a...@lanin.de hat am 5. Januar 2014 um 03:20 geschrieben: > > > > Hi all, > > first of all: yes I have read the FAQ. I know pdfbox is not thread safe. :-)
> I'm trying to render parts of a larger pdf to a BufferedImage. e.g. > pages 5, 7, 10, 52, 53 > However this is quite slow: My initial timing measurements show that > opening a pdf takes about half a second and rendering a single page > takes 0.8 - 2.5 seconds (Laptop; i7). So rendering e.g. 5 pages is 0.5 > + 5 * 1.5 = 8 seconds. I'm using loadNonSeq and > RenderUtil.convertToImage(page). I've also tried to use > drawer.drawPage directly without creating BufferedImages for each > page, same result. > > Again, I know pdfbox is not thread safe. But anyway I had an idea to > make it multi threaded: just open the document in each thread > separately! So at least in theory we get: 0.5 (5 times simultaneously) > + 2.5 (slowest page) = 3 seconds total which would be less than half > the time required before. OK, to open the pdf multiple times will eliminate the most obvious not thread safe thing (multithreaded access to one file), but there are other parts, like cached static values, which may be probelematic. But these are just guesses, in the end you have to give it a try. And, please let us know if you find something which could be refactored to be thread safe. > I haven't tested this yet, but maybe someone has already done > something like this? We are using PDFBox in a multithreaded environment to display and print pdfs. But the feature isn't a main use case so that the simultaneous usage of PDFBox doesn't happened that often. Maybe we are just lucky ;-) > Regards, > Alex BR Andreas Lehmkühler