use of digilib.conf.DigilibRequest in project digilib by robcast.
the class PDFStreamWorker method renderPDF.
/**
* @throws DocumentException
* @throws InterruptedException
* @throws ExecutionException
* @throws IOException
* @throws ImageOpException
*/
protected OutputStream renderPDF() throws InterruptedException, ExecutionException, IOException, ImageOpException {
long start_time = System.currentTimeMillis();
// create document object
PdfWriter writer = new PdfWriter(outstream);
PdfDocument pdfdoc = new PdfDocument(writer);
doc = new Document(pdfdoc, PageSize.A4);
logger.debug("PDF: {} doc.open()ed ({}ms)", outstream, (System.currentTimeMillis() - start_time));
// add title page
PDFTitlePage titlepage = new PDFTitlePage(job_info);
titlepage.createPage(doc);
// add pages
NumRange pgs = job_info.getPages();
for (int p : pgs) {
// start new page
doc.add(new AreaBreak());
logger.debug("PDF: adding Image {} to {}", p, outstream);
// copy request and set page number (as new Parameter)
DigilibRequest pageRequest = new DigilibRequest(dlConfig, job_info);
pageRequest.put("pn", new Parameter("pn", p, p));
// create ImageJobInformation
ImageJobDescription iji = ImageJobDescription.getRawInstance(pageRequest, job_info.getDlConfig());
iji.prepareScaleParams();
addImage(doc, iji);
logger.debug("PDF: done adding Image {} to {}", p, outstream);
}
logger.debug("PDF: done adding all Images to {}", outstream);
doc.close();
logger.debug("PDF: {} doc.close() ({}ms)", outstream, (System.currentTimeMillis() - start_time));
writer.flush();
writer.close();
return outstream;
}
Aggregations