• <menu id="w2i4a"></menu>
  • 首頁(yè) > 慧問(wèn) > 頻道

    html中有表格轉(zhuǎn)換成word再轉(zhuǎn)換成pdf 樣式 錯(cuò)誤

    發(fā)表于2022-03-14 回復(fù):0 查看:2415  |  
    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è)試意見(jiàn)</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>&nbsp;</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 {
    }
    }
    0個(gè)回答

    打破零回復(fù)...

    回復(fù)

    登錄 慧都網(wǎng)發(fā)表評(píng)論

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();