首页 > 解决方案 > OpenHTMLToPDF 构建非漏洞文档

问题描述

我正在使用 OpenHTMLToPDF 生成 pdf 文件。使用 Velocity 呈现 html,然后使用 OpenHTMLToPDF 呈现 pdf。在这个文档中有 2 页,第一个很好,但第二个是空的,但是我的渲染方法中的 html 也可以。我不明白小姐在哪里?有没有人之前看到过这样的事情?或者有什么想法?

void createPdf(OutputStream os, String html) throws IOException {
    try {
        PdfRendererBuilder builder = new PdfRendererBuilder();
        builder.useFastMode();
        builder.usePdfUaAccessbility(true);
        builder.withHtmlContent(html, "/");
        builder.toStream(os);
        builder.run();
    } catch (Exception var9) {
        throw new IOException("Error during creating pdf. Check out your parameters.");
    } finally {
        os.close();
    }
}

UPD

<html>
<head>
    <title> Quick Quote Report</title>
    <style>
        @font-face {
            font-family: bold;
            src: url(file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/./fonts/Bold/Bold.ttf);
        }
        @font-face {
            font-family: regularFont;
            src: url(file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/./fonts/regular/regular);
        }
        @font-face {
            font-family: demibold;
            src: url(file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/./fonts/Demibold/Demibold.ttf);
        }
        @font-face {
            font-family: lightFont;
            src: url(file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/./fonts/Light/Light.ttf);
        }
        page {
            background: white;
            display: block;
            margin: 0 auto;
            margin-bottom: 0.5cm;
            box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
        }
        page[size="A4"] {
            width: 21cm;
            height: 29.7cm;
        }
        .regularTitle {
            font-family: regularFont;
        }
        .boldTitle {
            font-family: bold;
        }
        .demiboldTitle {
            font-family: demibold;
        }
        .lightTitle {
            font-family: lightFont;
        }
        h1 {
            font-weight: normal;
        }
        table {
            border-collapse: collapse;
            margin-top: 20px;
        }
        th {
            border: none;
            border-bottom: 0.5px solid black;
            height: 20px;
        }
        td {
            border: none;
            border-bottom: 0.5px solid black;
            height: 60px;
        }
        td.footer {
            border: none;
            font-family: lightFont;
        }
    </style>
</head>
<body>
        <img src="file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps//img/manulife-logo-en.jpeg" style="width: 3cm;"/>

        <h1 class="lightTitle" style="font-size: 30pt; color: black; padding-top: 30px;">Insure Right</h1>
        <h2 class="demiboldTitle" style="font-size: 12pt; color: black; padding-top: 10px;">The amount of life insurance that may be right for you.</h2>
        <div class="lightTitle" style="font-size: 10pt; color: black; padding-top: 0px;">Based on the information you provided, here’s the amount of life insurance you may need.</div>

        <table style="width: 100%;">
            <tr>
                <td class="regularTitle" style="height: 20px; font-size: 12px; width: 50%; text-align: left;">Dec 04, 2019</td>
                <th class="regularTitle" style="font-size: 12px; color: white; text-align: left; background-color: #034EA2; width: 25%; padding-left: 30px;">Amount of insurance</th>
                <th class="regularTitle" style="font-size: 12px; color: white; text-align: left; background-color: #034EA2; width: 25%; padding-left: 30px;">Cost per month</th>
            </tr>
            <tr>
                <td class="demiboldTitle" style="font-size: 16px; color: black; text-align: left;">Quick Quote Results</td>
                <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #DCF2FD; padding-left: 30px;">$0</td>
                <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #DCF2FD; padding-left: 30px;">$0.00</td>
            </tr>
                                <tr>
                    <td class="demiboldTitle" style="font-size: 16px; color: black; text-align: left;">Adjusted to fit your budget</td>
                    <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #DCF2FD; padding-left: 30px;">$0</td>
                    <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #DCF2FD; padding-left: 30px;">$0.00</td>
                </tr>
                        </table>

        <h2 class="demiboldTitle" style="font-size: 17px; color: black; padding-top: 20px;">Consider Synergy</h2>
        <div class="lightTitle" style="font-size: 12px; color: black; padding-top: 0px;">Manulife’s unique combination insurance, called  Synergy , includes a life insurance policy, a disability insurance policy and a critical illness insurance policy - all in one affordable, easy-to-manage package.</div>
        <div class="lightTitle" style="font-size: 12px; color: black; padding-top: 20px;">Here’s an estimate of how much combination insurance you may need based on the information you entered in the Quick Quote which only estimates your life insurance needs.</div>

        <table style="width: 100%">
            <tr>
                <th class="regularTitle" style="font-size: 12px; width: 50%; text-align: left;">Dec 04, 2019</th>
                <th class="regularTitle" style="font-size: 12px; color: black; text-align: left; background-color: #00bf66; width: 25%; padding-left: 30px;">Amount of insurance</th>
                <th class="regularTitle" style="font-size: 12px; color: black; text-align: left; background-color: #00bf66; width: 25%; padding-left: 30px;">Cost per month</th>
            </tr>
            <tr>
                <td class="demiboldTitle" style="font-size: 16px; color: black; text-align: left;">Quick Quote Results</td>
                <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #e8f9ea; padding-left: 30px;">$0</td>
                <td class="demiboldTitle" style="font-size: 16px; color: black; background-color: #e8f9ea; padding-left: 30px;">$0.00</td>
            </tr>
        </table>
                            <div style="padding-top: 150px">
                            <div class="lightTitle" style="font-size: 10px; color: black;">ABOUT YOUR QUICK QUOTE ESTIMATE</div>
            <div class="lightTitle" style="line-height: 1.3; text-align: justify; font-size: 10px; color: black; padding-top: 5px;">We’ve used a few assumptions to estimate the amount of insurance, which may or may not reflect your unique insurance needs. The cost estimated is for Manulife’s Family Term, Term-20 life insurance for  a male, age 28, non-smoker, single, children: 0, annual income of $0, total debts of $0, total savings of $30,000, total existing life insurance of $75,000. </div>
            <div class="lightTitle" style="font-size: 10px; color: black; padding-top: 20px;">ABOUT YOUR QUICK QUOTE SYNERGY ESTIMATE</div>
            <div class="lightTitle" style="line-height: 1.3; text-align: justify; font-size: 10px; color: black; padding-top: 5px;">We’ve used the same assumptions to estimate the total Synergy amount of insurance, which may or may not reflect your unique insurance needs. The cost estimated is for a Synergy Term 10 solution of  for a male, age 28, non-smoker, single, children: 0, annual income of $0, total debts of $0, total savings of $30,000, total existing life insurance of $75,000. </div>
        </div>

        <table style="margin-top:  60px;  width: 100%; border: none;">
            <tr>
                <td class="footer" style="width: 50%; height: 11px; font-size: 10px; color: black; text-align: left">MANULIFE INSURANCE - INSURERIGHT</td>
                <td class="footer" style="font-family: demibold; width: 50%; height: 11px; font-size: 10px; color: black; text-align: right">1</td>
            </tr>
        </table>


        <img src="file:///Users/macbookpro/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps//img/manulife-logo-en.jpeg" style="width: 3cm; padding-top: 10px"/>

        <div class="lightTitle" style="padding-top: 35px; font-size: 10px; color: black;">DISCLAIMERS</div>
        <div class="lightTitle" style="line-height: 1.3;text-align: justify; padding-top: 5px; font-size: 10px; color: black;">content</div>
        <div class="lightTitle" style="font-size: 10px; color: black; padding-top: 20px;">FAMILY TERM 20</div>
        <div class="lightTitle" style="line-height: 1.3; text-align: justify; font-size: 10px; color: black; padding-top: 5px;">content</div>
                        <div class="lightTitle" style="padding-top: 20px; font-size: 10px; color: black;">SYNERGY TERM 10</div>
            <div class="lightTitle" style="line-height: 1.3; text-align: justify; padding-top: 5px; font-size: 10px; color: black;">content</div>
                    <div class="lightTitle" style="font-size: 10px; color: black; padding-top: 20px;">YOUR CALCULATION IS BASED ON THESE ASSUMPTIONS:</div>
        <ul class="lightTitle" style="line-height: 1.3; padding: 0px; margin-left: 0.4cm; font-size: 10px; color: black;">
                <li>Funeral costs of $15,000</li>
                                <li>Unless you are single and have no children, your savings or assets are not liquidated to help cover expenses or loss of income associated with your death</li>
                        </ul>
        <div class="lightTitle" style="line-height: 1.3; text-align: justify; font-size: 10px; color: black; padding-top: 5px;">Interest and inflation rates are not used in 
        <table style="margin-top:  545px;  width: 100%; border: none;">
            <tr>
                <td class="footer" style="width: 50%; height: 11px; font-size: 10px; color: black; text-align: left">logo</td>
                <td class="footer" style="font-family: demibold; width: 50%; height: 11px; font-size: 10px; color: black; text-align: right">2</td>
            </tr>
        </table>
</body>

空内容从第二个 img 标签开始直到结束

标签: javavelocityopenhtmltopdf

解决方案


推荐阅读