本文整理汇总了Java中org.apache.pdfbox.util.PDFMergerUtility类的典型用法代码示例。如果您正苦于以下问题:Java PDFMergerUtility类的具体用法?Java PDFMergerUtility怎么用?Java PDFMergerUtility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PDFMergerUtility类属于org.apache.pdfbox.util包,在下文中一共展示了PDFMergerUtility类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例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: pdfMerge
import org.apache.pdfbox.util.PDFMergerUtility; //导入依赖的package包/类
public void pdfMerge(OutputStream oos,Collection<PDDocument> pdfs) throws IOException, COSVisitorException {
PDDocument resultingPDF = new PDDocument();
PDFMergerUtility pmu = new PDFMergerUtility();
for (PDDocument pdf : pdfs) {
pmu.appendDocument(resultingPDF,pdf);
}
resultingPDF.save(oos);
}
示例5: 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;
}
示例6: PDFMerger
import org.apache.pdfbox.util.PDFMergerUtility; //导入依赖的package包/类
public PDFMerger(FileDao fileDao) {
merger = new PDFMergerUtility();
merger.setIgnoreAcroFormErrors(true);
this.fileDao = fileDao;
}
示例7: process
import org.apache.pdfbox.util.PDFMergerUtility; //导入依赖的package包/类
@Override
public Map<String, Object> process(Map<String, Object> sItem) throws Exception {
Map<String, Object> aResult = null;
if (sourceFactory != null) {
Map<String, Object> aSourceParams = new HashMap<String, Object>(sItem);
aSourceParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, getStepExecution());
PDDocumentContainer aContainer = null;
try {
aContainer = documentFactory.fromParts(sourceFactory, aSourceParams);
if (LOGGER.isInfoEnabled()) {
if ((aContainer == null) || (aContainer.getParts() == null)) {
LOGGER.info("No file to merge");
} else {
LOGGER.info("{} file(s) to merge", aContainer.getParts().size());
}
}
int aPartsCount = aContainer.getParts().size();
if (aPartsCount > 0) {
aResult = new HashMap<String, Object>(sItem);
Resource aDestinationResource = destinationFactory.getResource(aSourceParams);
File aDestFile = aDestinationResource.getFile();
if (aDestFile.exists()) {
if (forceReplace && !aDestFile.delete()) {
throw new IOException("Destination '" + aDestFile + "' cannot be replaced");
}
} else if (aDestFile.getParentFile() != null && !aDestFile.getParentFile().exists()
&& !aDestFile.getParentFile().mkdirs()) {
throw new IOException("Destination '" + aDestFile + "' directory cannot be created");
}
PDDocument destination = aContainer.getParts().get(0);
PDFMergerUtility merger = new PDFMergerUtility();
for(int i = 1; i < aPartsCount; i++) {
merger.appendDocument(destination, aContainer.getParts().get(i));
}
destination.save(aDestFile.getAbsolutePath());
aResult.put(key, aDestFile.getAbsolutePath());
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Merged to : {}", aResult.get(key));
}
}
} finally {
if (aContainer != null) {
aContainer.close();
}
}
}
return aResult;
}