PDFBox拆分单个PDF的多线程范围页面

时间:2020-07-02 23:35:08

标签: java multithreading pdf pdfbox runnable

我的PDFBox库有问题,我只有一个pdf,我必须将其拆分为n个文件,由于pdf非常大,因此在此操作中我需要非常快。因此,我使用了并行方法。我设法通过使用PageExtractor拆分了所有页面,但我注意到在某些情况下(并非总是如此),图像不可见。这是我的代码:

        Long endBu = sommario.getEndDoc();
        Long starBd = sommario.getStartBd();
        // range di pagine da estrarre per la bolletta unica
        PageExtractor pExBu = new PageExtractor(currentPdf);
        pExBu.setStartPage(startBu.intValue());
        pExBu.setEndPage(endBu.intValue());
        PDDocument pdfDocBu = null;
        try {
        
            pdfDocBu = pExBu.extract();
            String fileName = tempDirSplitter + nomeFileBolletta + "_" + TIPO_BOLLETTA.get(INDEX_BS_P_BD)
                    + Constants.PDF_EXTENSION;
         pdfDocBu.save(fileName);
                } finally {
            try {
                if (null != pdfDocBu) {

                    pdfDocBu.close();
                }
            } catch (IOException e) {
                getLogger().error("Errore Chiusura Pdf "+item.getIdDocumento() +  " - " + pdfDocBu.getNumberOfPages());
                e.printStackTrace();
            }
        }

这段代码属于可运行类型

0 个答案:

没有答案