public static void test2(){
String template = "<table style=\"border-collapse: collapse; width: 80%; border-width: 1px; border-spacing: " +
"0px; border-style: solid;\" align=\"center\"><tbody><tr><td style=\"border-style: solid; width: 18%;" +
" border-width: 1px;\" valign=\"center\" width=\"18%\"><p style=\"text-align: center;\"><strong><span" +
" style=\"font-family: 宋體; font-size: 16px;\">測試測試會測試情況及測試意見</span></strong></p></td><td " +
"style=\"border-style: solid; width: 80%; border-width: 1px;\" colspan=\"4\" valign=\"center\" " +
"width=\"80%\"><p style=\"text-indent: 32px; line-height: 24px;\"><span style=\";font-family: 宋體; " +
"font-size: 16px;\">測試測試會根據測試測試規定的測試程序和測試測試對</span><span style=\"font-family: 宋體; font-size: 16px;" +
"\">1</span><span style=\";font-family: 宋體; font-size: 16px;" +
"\">家測試人的測試測試進行了認真的測試,具體情況如下:</span></p></td></tr></tbody></table><p> </p>";
String srcPath = "/home/imic/project/test.docx";
String destPath = "/home/imic/project/test.pdf";
try {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml(template);
doc.save(srcPath, SaveFormat.DOCX);
} catch (Exception e) {
e.printStackTrace();
}
FileOutputStream os = null;
try {
long old = System.currentTimeMillis();
//新建一個空白pdf文檔
File pdfFile = FileUtils.createFile(destPath);
os = new FileOutputStream(pdfFile);
LoadOptions opt = new LoadOptions();
opt.setEncoding(Charset.forName("utf8"));
Document doc = new Document(srcPath, opt);
PdfSaveOptions pso = new PdfSaveOptions();
pso.setCompliance(PdfCompliance.PDF_17);
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互轉換
doc.save(os, SaveFormat.PDF);
long now = System.currentTimeMillis();
log.info("轉換了{}頁, 共耗時{}秒", doc.getPageCount(), ((now - old) / 1000.0));
} catch (Exception e) {
throw new BaseException("轉換錯誤:", e);
}finally {
}
}
打破零回復...
登錄 慧都網發表評論