|
|
|
@ -35,9 +35,10 @@ public class PrintToPdfUtil {
|
|
|
|
|
* @param imageFolderPath 图片文件夹地址
|
|
|
|
|
* @param pdfPath PDF文件保存地址
|
|
|
|
|
*/
|
|
|
|
|
public static void toPdf(String imageFolderPath, String pdfPath,List dirList) {
|
|
|
|
|
public static void toPdf(String imageFolderPath, String pdfPath,List dirList) throws IOException {
|
|
|
|
|
// 创建文档
|
|
|
|
|
Document doc = new Document(null, 0, 0, 0, 0);
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
|
try {
|
|
|
|
|
//判断文件夹是否存在
|
|
|
|
|
String pdfStr = pdfPath.substring(0, pdfPath.lastIndexOf("\\"));
|
|
|
|
@ -58,7 +59,7 @@ public class PrintToPdfUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 输入流
|
|
|
|
|
FileOutputStream fos = new FileOutputStream(pdfPath);
|
|
|
|
|
fos = new FileOutputStream(pdfPath);
|
|
|
|
|
|
|
|
|
|
//doc.open();
|
|
|
|
|
// 写入PDF文档
|
|
|
|
@ -73,6 +74,10 @@ public class PrintToPdfUtil {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
if(null != fos){
|
|
|
|
|
fos.flush();
|
|
|
|
|
fos.close();
|
|
|
|
|
}
|
|
|
|
|
if (doc.isOpen()) {
|
|
|
|
|
// 关闭文档
|
|
|
|
|
doc.close();
|
|
|
|
@ -82,8 +87,6 @@ public class PrintToPdfUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void imgFun(String imageFolderPath,File file, List dirList, Document doc){
|
|
|
|
|
// 图片地址
|
|
|
|
|
String imagePath = null;
|
|
|
|
|
// 读取图片流
|
|
|
|
|
BufferedImage img = null;
|
|
|
|
|
// 实例化图片
|
|
|
|
@ -137,7 +140,7 @@ public class PrintToPdfUtil {
|
|
|
|
|
} catch(Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
|
|
img.flush();
|
|
|
|
|
if (doc.isOpen()) {
|
|
|
|
|
// 关闭文档
|
|
|
|
|
doc.close();
|
|
|
|
@ -286,9 +289,10 @@ public class PrintToPdfUtil {
|
|
|
|
|
public static boolean mergePdfFiles(List files, String newfile) {
|
|
|
|
|
boolean retValue = false;
|
|
|
|
|
Document document = null;
|
|
|
|
|
PdfCopy copy = null;
|
|
|
|
|
try {
|
|
|
|
|
document = new Document(new PdfReader(files.get(0).toString()).getPageSize(1));
|
|
|
|
|
PdfCopy copy = new PdfCopy(document, new FileOutputStream(newfile));
|
|
|
|
|
copy = new PdfCopy(document, new FileOutputStream(newfile));
|
|
|
|
|
document.open();
|
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
|
PdfReader reader = new PdfReader(files.get(i).toString());
|
|
|
|
@ -306,6 +310,7 @@ public class PrintToPdfUtil {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
copy.close();
|
|
|
|
|
document.close();
|
|
|
|
|
}
|
|
|
|
|
return retValue;
|
|
|
|
|