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;\">測(cè)試測(cè)試會(huì)測(cè)試情況及測(cè)試意見</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;\">測(cè)試測(cè)試會(huì)根據(jù)測(cè)試測(cè)試規(guī)定的測(cè)試程序和測(cè)試測(cè)試對(duì)</span><span style=\"font-family: 宋體; font-size: 16px;" +
"\">1</span><span style=\";font-family: 宋體; font-size: 16px;" +
"\">家測(cè)試人的測(cè)試測(cè)試進(jìn)行了認(rèn)真的測(cè)試,具體情況如下:</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();
//新建一個(gè)空白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 相互轉(zhuǎn)換
doc.save(os, SaveFormat.PDF);
long now = System.currentTimeMillis();
log.info("轉(zhuǎn)換了{}頁(yè), 共耗時(shí){}秒", doc.getPageCount(), ((now - old) / 1000.0));
} catch (Exception e) {
throw new BaseException("轉(zhuǎn)換錯(cuò)誤:", e);
}finally {
}
}
打破零回復(fù)...
登錄 慧都網(wǎng)發(fā)表評(píng)論