Java多个PDF合并详解编程语言

import java.io.File; 
import java.io.IOException; 
 
import org.pdfbox.util.PDFMergerUtility; 
 
public class Test { 
 
	/** 
	 * @param args 
	 */ 
	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 { 
		PDFMergerUtility mergePdf = new PDFMergerUtility(); 
 
		String folder = "E:/print_notice"; 
		String destinationFileName = "hbTest.pdf"; 
 
		String[] filesInFolder = getFiles(folder); 
 
		for (int i = 0; i < filesInFolder.length; i++) 
			mergePdf.addSource(folder + File.separator + filesInFolder[i]); 
 
		mergePdf.setDestinationFileName(folder + File.separator + destinationFileName); 
		mergePdf.mergeDocuments(); 
 
		System.out.print("done"); 
	} 
 
} 

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/16333.html

(0)
上一篇 2021年7月19日 19:14
下一篇 2021年7月19日 19:14

相关推荐

发表回复

登录后才能评论