|
|
|
@ -33,7 +33,7 @@ public final class PDFConverUtil {
|
|
|
|
|
final private static Map<TypeEnum, List<String>> types = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public static enum TypeEnum {
|
|
|
|
|
WORD, EXCEL, PPT, PPTX, OTHER
|
|
|
|
|
WORD, EXCEL, PPT, PPTX, IMG, OTHER
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
@ -41,7 +41,8 @@ public final class PDFConverUtil {
|
|
|
|
|
types.put(EXCEL, Arrays.asList("XLS", "XLSX"));
|
|
|
|
|
types.put(PPT, Arrays.asList("PPT"));
|
|
|
|
|
types.put(PPTX, Arrays.asList("PPTX"));
|
|
|
|
|
types.put(OTHER, Arrays.asList("OOXML", "RTF HTML", "OpenDocument", "PDF","EPUB", "XPS", "SWF"));
|
|
|
|
|
types.put(IMG, Arrays.asList("JPEG", "JPG", "PNG"));
|
|
|
|
|
types.put(OTHER, Arrays.asList("OOXML", "RTF HTML", "OpenDocument", "EPUB", "XPS", "SWF"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -51,14 +52,14 @@ public final class PDFConverUtil {
|
|
|
|
|
**/
|
|
|
|
|
public static boolean imgToPdf(InputStream inputStream, OutputStream outputStream) {
|
|
|
|
|
|
|
|
|
|
Document document = null;
|
|
|
|
|
Document document = null; PdfWriter pdfWriter = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
// 创建文档,设置PDF页面的大小 A2-A9, 个人觉得A3最合适
|
|
|
|
|
document = new Document(PageSize.A6, 20, 20, 20, 20);
|
|
|
|
|
document = new Document(PageSize.A6, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
// 新建pdf文档,具体逻辑看.getInstance方法
|
|
|
|
|
PdfWriter.getInstance(document, outputStream);
|
|
|
|
|
pdfWriter = PdfWriter.getInstance(document, outputStream);
|
|
|
|
|
|
|
|
|
|
document.open();
|
|
|
|
|
document.newPage();
|
|
|
|
@ -97,6 +98,7 @@ public final class PDFConverUtil {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
close(document, pdfWriter);
|
|
|
|
|
closeOutput(outputStream);
|
|
|
|
|
closeInput(inputStream);
|
|
|
|
|
}
|
|
|
|
@ -466,6 +468,9 @@ public final class PDFConverUtil {
|
|
|
|
|
if (types.get(PPTX).contains(fileSuffix)) {
|
|
|
|
|
return pptxToPdf(inputStream, outputStream);
|
|
|
|
|
}
|
|
|
|
|
// if (types.get(IMG).contains(fileSuffix)) {
|
|
|
|
|
// return imgToPdf(inputStream, outputStream);
|
|
|
|
|
// }
|
|
|
|
|
if (types.get(OTHER).contains(fileSuffix)) {
|
|
|
|
|
return wordToPdfByAspose(inputStream, outputStream);
|
|
|
|
|
}
|
|
|
|
@ -483,7 +488,6 @@ public final class PDFConverUtil {
|
|
|
|
|
*/
|
|
|
|
|
private static String getFileSuffix(String fileName) {
|
|
|
|
|
String[] split = fileName.split("\\.");
|
|
|
|
|
int length = split.length;
|
|
|
|
|
return split[length - 1];
|
|
|
|
|
return split[split.length - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|