Search in sources :

Example 1 with DigilibRequest

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;
}
Also used : NumRange(digilib.util.NumRange) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ImageJobDescription(digilib.image.ImageJobDescription) DigilibRequest(digilib.conf.DigilibRequest) Parameter(digilib.util.Parameter) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 Document (com.itextpdf.layout.Document)1 AreaBreak (com.itextpdf.layout.element.AreaBreak)1 DigilibRequest (digilib.conf.DigilibRequest)1 ImageJobDescription (digilib.image.ImageJobDescription)1 NumRange (digilib.util.NumRange)1 Parameter (digilib.util.Parameter)1