zoukankan      html  css  js  c++  java
  • java合并pdf

    一.开发准备

        下载pdfbox-app-1.7.1.jar包;下载地址:http://download.csdn.net/detail/yanning1314/4852276

    二.简单小例子

          在开发中在根据实际情况进行修改,下面是主要API的应用

    package com.shine.efcms.struts;
    import java.io.File;  
    import java.io.IOException;  
    import org.apache.pdfbox.util.PDFMergerUtility;  
    
    public class test {  
       
      private static String[] getFiles(String folder) throws IOException {  
          File _folder = new File(folder);  
          String[] filesInFolder;     
     
          if(_folder.isDirectory()){  
                filesInFolder = _folder.list();  
                return filesInFolder;  
           } else {  
                throw new IOException("Path is not a directory");  
           }  
        }  
     
        public static void main(String[] args) throws Exception {  
          
            //pdf合并工具类
            PDFMergerUtility mergePdf = new PDFMergerUtility();  
    
            String folder = "F:/test";  
            String destinationFileName = "mergedTest.pdf";  
              
            String[] filesInFolder = getFiles(folder);     
      
            for(int i = 0; i < filesInFolder.length; i++){ 
                //循环添加要合并的pdf存放的路径
                mergePdf.addSource(folder + File.separator + filesInFolder[i]);  
            }  
            
            //设置合并生成pdf文件名称
            mergePdf.setDestinationFileName(folder + File.separator + destinationFileName);  
            //合并pdf
            mergePdf.mergeDocuments();  
        }  
             
    }  
  • 相关阅读:
    闭包
    this
    函数声明,表达式,构造函数
    算法学习_栈
    LeetCode刷题_140
    2020/3/20 刷题
    2020/3/19 刷题
    2020/3/13_C++实验课
    刷题(主要是DFS) 2020年3月12日
    DFS的一些题2020/3/11
  • 原文地址:https://www.cnblogs.com/hongwz/p/6245874.html
Copyright © 2011-2022 走看看