本文整理汇总了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);
}
}
示例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);
}
}
示例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");
}
示例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;
}