• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PDFMergerUtility类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.pdfbox.multipdf.PDFMergerUtility的典型用法代码示例。如果您正苦于以下问题:Java PDFMergerUtility类的具体用法?Java PDFMergerUtility怎么用?Java PDFMergerUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: addCoverpage

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
private void addCoverpage() throws IOException {
    float leading = 1.5f * FONT_SIZE_TITLE;
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    FONT_STYLE_COVER = PDTrueTypeFont.loadTTF(document, MainApp.class.getResourceAsStream(FONT_MERRIWEATHER_BOLD));
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setNonStrokingColor(25, 81, 107);
    contentStream.fillRect(0, 0, page.getMediaBox().getWidth(), (page.getMediaBox().getHeight() / 2) - 10);
    contentStream.fillRect(0, (page.getMediaBox().getHeight() / 2) + 10, page.getMediaBox().getWidth(), (page.getMediaBox().getHeight() / 2) - 10);
    contentStream.setNonStrokingColor(248, 173, 50);
    contentStream.fillRect(0, (page.getMediaBox().getHeight() / 2) - 10, page.getMediaBox().getWidth(), 20);

    contentStream.beginText();
    contentStream.setNonStrokingColor(Color.WHITE);
    contentStream.setFont(FONT_STYLE_COVER, FONT_SIZE_AUTHOR);
    contentStream.newLineAtOffset(20, 20);
    contentStream.showText(authorContent);
    contentStream.setFont(FONT_STYLE_COVER, FONT_SIZE_TITLE);
    contentStream.newLineAtOffset((page.getMediaBox().getWidth() / 2) - 20, 600);
    List<String> lines = wrapText((page.getMediaBox().getWidth() / 2) - 20);
    for (String line : lines) {
        contentStream.showText(line);
        contentStream.newLineAtOffset(0, -leading);
    }
    contentStream.endText();

    contentStream.close();
    File temp = File.createTempFile("coverpage-zds", ".pdf");
    document.save(temp);
    document.close();

    PDFMergerUtility mergerUtility = new PDFMergerUtility();
    mergerUtility.addSource(temp);
    mergerUtility.addSource(destPdfPath);
    mergerUtility.setDestinationFileName(destPdfPath);
    mergerUtility.mergeDocuments();
}
 
开发者ID:firm1,项目名称:zest-writer,代码行数:39,代码来源:PdfUtilExport.java


示例2: testMergeGovernmentForms

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/47140209/pdfbox-files-are-sharing-common-cosstream-after-flatten">
 * PDFBox files are sharing common COSStream after flatten
 * </a>
 * <br/>
 * <a href="https://studentloans.gov/myDirectLoan/downloadForm.action?searchType=library&shortName=general&localeCode=en-us">
 * GeneralForbearance.pdf
 * </a>
 * <p>
 * Indeed, flattening, merging, and early closing of source documents
 * do not mingle well.
 * </p>
 */
@Test
public void testMergeGovernmentForms() throws IOException {
    try (   InputStream resource1 = getClass().getResourceAsStream("GeneralForbearance.pdf");
            InputStream resource2 = getClass().getResourceAsStream("GeneralForbearance.pdf")) {
        PDDocument destination = PDDocument.load(resource1);

        PDDocument source = PDDocument.load(resource2);
        source.getDocumentCatalog().getAcroForm().flatten(); //comment out just this line and the destination.save will pass

        PDFMergerUtility appender = new PDFMergerUtility();

        appender.appendDocument(destination, source);

        source.close(); //comment out just this line and the destination.save will pass

        destination.save(new File(RESULT_FOLDER, "PrintMergeIssue.pdf"));
        destination.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:33,代码来源:FlattenAndMerge.java


示例3: concatena

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
public void concatena(InputStream anterior, InputStream novo, OutputStream saida, List<String> marcadores)
        throws IOException
{
    PDFMergerUtility pdfMerger = new PDFMergerUtility();
    pdfMerger.setDestinationStream(saida);
    PDDocument dest;
    PDDocument src;
    MemoryUsageSetting setupMainMemoryOnly = MemoryUsageSetting.setupMainMemoryOnly();
    if (anterior != null)
    {
        dest = PDDocument.load(anterior, setupMainMemoryOnly);
        src = PDDocument.load(novo, setupMainMemoryOnly);
    }
    else
    {
        dest = PDDocument.load(novo, setupMainMemoryOnly);
        src = new PDDocument();
    }
    int totalPages = dest.getNumberOfPages();
    pdfMerger.appendDocument(dest, src);
    criaMarcador(dest, totalPages, marcadores);
    saida = pdfMerger.getDestinationStream();
    dest.save(saida);
    dest.close();
    src.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:27,代码来源:MergeDocuments.java


示例4: mergePDF

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
public static boolean mergePDF(IContext context,List<FileDocument> documents,  IMendixObject mergedDocument ){
	int i = 0;
	PDFMergerUtility  mergePdf = new  PDFMergerUtility();
	for(i=0; i < documents.size(); i++)
	{
	    FileDocument file = documents.get(i);
	    InputStream content = Core.getFileDocumentContent(context, file.getMendixObject());
	    mergePdf.addSource(content);            
	}
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	mergePdf.setDestinationStream(out);
	try {
		mergePdf.mergeDocuments(null);
	} catch (IOException e) {
		throw new RuntimeException("Failed to merge documents" + e.getMessage(), e);
		
	}
	 
	Core.storeFileDocumentContent(context, mergedDocument, new ByteArrayInputStream(out.toByteArray()));

	out.reset();
	documents.clear();
	
	return true;	
}
 
开发者ID:mendix,项目名称:RestServices,代码行数:26,代码来源:Misc.java


示例5: concatenate

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
public static void concatenate(List infiles, OutputStream out, long maxMemory, long maxDisk) throws IOException {
    final PDFMergerUtility merger = new PDFMergerUtility();
    for (Object infile : infiles) {
        if (infile instanceof File) {
            merger.addSource((File) infile);
        } else if (infile instanceof InputStream) {
            merger.addSource((InputStream) infile);
        } else if (infile instanceof String) {
            merger.addSource((String) infile);
        } else {
            die("concatenate: invalid infile ("+infile.getClass().getName()+"): "+infile);
        }
    }
    merger.setDestinationStream(out);
    merger.mergeDocuments(MemoryUsageSetting.setupMixed(maxMemory, maxDisk));
}
 
开发者ID:cobbzilla,项目名称:cobbzilla-utils,代码行数:17,代码来源:PdfMerger.java


示例6: writeTo

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
@Override
public boolean writeTo(final String filename) {
    if (!swapped) {
        return super.writeTo(filename);
    }
    swapToDisk();
    Utilities.shutdownAndAwaitTermination(swapExecutor, "Swap");
    try {
        LOG.trace("Merging...");
        Instant start = Instant.now();
        final PDFMergerUtility mergerUtility = new PDFMergerUtility();
        mergerUtility.setDestinationFileName(filename + ".pdf");
        for (Path path : FileUtils.getPaths(getTempDir(), "partial_*")) {
            mergerUtility.addSource(path.toFile());
        }
        mergerUtility.mergeDocuments(Utilities.getMemorySettings(Environment.getMergeCacheSize()));
        Instant end = Instant.now();
        LOG.trace("Merging took: " + Duration.between(start, end).toMillis() + "ms");
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (tempDir != null) {
            FileUtils.removeTempDir(tempDir);
        }
    }
    return isEqual;
}
 
开发者ID:red6,项目名称:pdfcompare,代码行数:28,代码来源:AbstractCompareResultWithSwap.java


示例7: testMergePreFlattenedGovernmentForms

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/47140209/pdfbox-files-are-sharing-common-cosstream-after-flatten">
 * PDFBox files are sharing common COSStream after flatten
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/18JbNK1gBivSARvv9kgd5FE8xnD_9-_15/view?usp=drivesdk">
 * GovFormPreFlattened.pdf
 * </a>
 * <p>
 * Indeed, even merely merging, and early closing of pre-flattened source documents
 * do not mingle well.
 * </p>
 */
@Test
public void testMergePreFlattenedGovernmentForms() throws IOException {
    try (   InputStream resource1 = getClass().getResourceAsStream("GovFormPreFlattened.pdf");
            InputStream resource2 = getClass().getResourceAsStream("GovFormPreFlattened.pdf")) {
        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
        PDDocument src = PDDocument.load(resource1);
        PDDocument dest = PDDocument.load(resource2);
        pdfMergerUtility.appendDocument(dest, src);
        src.close(); //if we don't close the src then we don't have an error
        dest.save(new File(RESULT_FOLDER, "PreFlattenedMergeIssue.pdf"));
        dest.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:27,代码来源:FlattenAndMerge.java


示例8: merge

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
@Programmatic
public byte[] merge(final List<File> fileList) throws IOException {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    final PDFMergerUtility ut = new PDFMergerUtility();
    for (File file : fileList) {
        ut.addSource(file);
    }

    ut.setDestinationStream(baos);
    ut.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());

    return baos.toByteArray();
}
 
开发者ID:estatio,项目名称:estatio,代码行数:16,代码来源:PdfBoxService2.java


示例9: merge

import org.apache.pdfbox.multipdf.PDFMergerUtility; //导入依赖的package包/类
public static InputStream merge(InputStream originalPDF, byte[] titleBlock) throws IOException {

        ByteArrayOutputStream tempOutStream = new ByteArrayOutputStream();
        PDFMergerUtility mergedDoc = new PDFMergerUtility();

        InputStream titleBlockStream = new ByteArrayInputStream(titleBlock);

        mergedDoc.addSource(titleBlockStream);
        mergedDoc.addSource(originalPDF);

        mergedDoc.setDestinationStream(tempOutStream);
        mergedDoc.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());

        return new ByteArrayInputStream(tempOutStream.toByteArray());


    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:18,代码来源:TitleBlockGenerator.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ConfigurableProvider类代码示例发布时间:2022-05-22
下一篇:
Java ZkInterruptedException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap