当前位置: 首页>>代码示例>>Java>>正文


Java PDFMergerUtility.mergeDocuments方法代码示例

本文整理汇总了Java中org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments方法的典型用法代码示例。如果您正苦于以下问题:Java PDFMergerUtility.mergeDocuments方法的具体用法?Java PDFMergerUtility.mergeDocuments怎么用?Java PDFMergerUtility.mergeDocuments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pdfbox.util.PDFMergerUtility的用法示例。


在下文中一共展示了PDFMergerUtility.mergeDocuments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import org.apache.pdfbox.util.PDFMergerUtility; //导入方法依赖的package包/类
@Override
public void merge(final List<String> inputUris, final String outputUri)
		throws COSVisitorException, IOException {

	if (CollectionUtils.isNotEmpty(inputUris) && StringUtils.isNotBlank(outputUri)) {

		final PDFMergerUtility merger = new PDFMergerUtility();

		for (final String input : inputUris) {
			merger.addSource(input);
		}

		merger.setDestinationFileName(outputUri);
		merger.mergeDocuments();

	} else {
		throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:20,代码来源:PDFGalImpl.java

示例2: mergePdfs

import org.apache.pdfbox.util.PDFMergerUtility; //导入方法依赖的package包/类
public void mergePdfs(List<InputStream> pdfFiles, String filename, OutputStream destStream) {
	PDFMergerUtility ut = new PDFMergerUtility();
	ut.setDestinationFileName(filename);
	ut.setDestinationStream(destStream);
	for(InputStream pdfFile: pdfFiles) {
		ut.addSource(pdfFile);
	}
	try {
		ut.mergeDocuments();
	} catch (COSVisitorException | IOException e) {
		throw new EsupDematEcException("Error merging pdf files- " + filename, e);
	}	
}
 
开发者ID:EsupPortail,项目名称:esup-dematec,代码行数:14,代码来源:TxPdfService.java

示例3: mergeAllPages

import org.apache.pdfbox.util.PDFMergerUtility; //导入方法依赖的package包/类
private static void mergeAllPages(final String directoryName) throws IOException,
        COSVisitorException {

    File[] files = new File(directoryName).listFiles();

    Arrays.sort(files, new Comparator<File>() {
        public int compare(File f1, File f2) {
            return Long.valueOf(f1.lastModified()).compareTo(
                    f2.lastModified());
        }
    });

    PDFMergerUtility ut = new PDFMergerUtility();
    for (File pdfFile : files) {
        ut.addSource(pdfFile);
    }

    ut.setDestinationFileName(directoryName + BACK_SLASH + "merged.pdf");
    logInfo("Starting merge at : " + directoryName + BACK_SLASH
            + "merged.pdf");
    ut.mergeDocuments();
    logInfo("Created merged pdf at : " + directoryName
            + BACK_SLASH + "merged.pdf");

}
 
开发者ID:wnds,项目名称:dainik-bhasker-pdf,代码行数:26,代码来源:Init.java

示例4: mergeAssets

import org.apache.pdfbox.util.PDFMergerUtility; //导入方法依赖的package包/类
public AggregatedAssetStatus mergeAssets(Collection<String> filenames) throws Exception {


        AggregatedAssetStatus status=new AggregatedAssetStatus();
        status.file=File.createTempFile("merged",".pdf");
        Collection<File> filesToDelete=new ArrayList<File>();
        PDFMergerUtility merger=new PDFMergerUtility();
        merger.setDestinationFileName(status.file.getAbsolutePath());

        for (String filename : filenames) {

            boolean canConvert=filename.toLowerCase().endsWith(".pdf");

            PDDocument document = new PDDocument();
            PDPage coverPage = new PDPage();
            document.addPage( coverPage );

            PDFont font = PDType1Font.HELVETICA_BOLD;

            PDPageContentStream contentStream = new PDPageContentStream(document, coverPage);

            contentStream.beginText();
            contentStream.setFont(font, 12);
            contentStream.moveTextPositionByAmount(100, 700);
            if (canConvert) {
                contentStream.drawString("eDossier generated cover page for: " + new File(filename).getName());
            } else {
                contentStream.drawString("eDossier placeholder for unsupported file type : " + new File(filename).getName());
            }
            contentStream.endText();

            contentStream.close();

            File temp= File.createTempFile("cover",".pdf");
            filesToDelete.add(temp);
            document.save(temp.getAbsolutePath());
            document.close();


            merger.addSource(temp.getAbsolutePath());
            if (canConvert) {
                merger.addSource(filename);
            } else {
                status.skippedFiles.add(filename);
            }
        }

        merger.mergeDocuments();

        for (File cleanupFile : filesToDelete) {
            cleanupFile.delete();
        }

        return status;
    }
 
开发者ID:kuali-mirror,项目名称:kpme,代码行数:56,代码来源:AssetAggregationServiceImpl.java


注:本文中的org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。