iTextPdf 5.5.1 - Converting large HTML to single Page PDF with Custom fonts

时间:2017-08-04 12:22:52

标签: java itext html-to-pdf xmlworker

I am having HTML document including CSS Styles. I want to create one pdf file with custom fonts and the height as per the document contents.

I followed this implementations Adjust page size based on amount of HTML data But it wants separate HTML and CSS. I provide it whole document string as HTML and left the CSS String null. It gave me exception. Moreover if there is any examples to implement custom fonts in Java Please help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="de">
    <head>
        <title>Proforma-Quittung 27.03.17 11:18 2017/2432</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <style type="text/css">
            @font-face {
            font-family: "Roboto Mono";
            src: url('RobotoMono-Bold.ttf') format('ttf'), url('RobotoMono-BoldItalic.ttf') format('ttf'), url('RobotoMono-Italic.ttf') format('ttf'), url('RobotoMono-Light.ttf') format('ttf'), url('RobotoMono-LightItalic.ttf') format('ttf'), url('RobotoMono-Medium.ttf') format('ttf'), url('RobotoMono-MediumItalic.ttf') format('ttf'), url('RobotoMono-Regular.ttf') format('ttf'), url('RobotoMono-Thin.ttf') format('ttf'), url('RobotoMono-ThinItalic.ttf') format('ttf');
            }
            body {
            font-family: "Roboto Mono";
            font-size: 10pt;
            width: 100%;
            margin: 0pt;
            }
            .documentType {
            text-transform: uppercase;
            }
            h1 {
            text-align: center;
            font-size: 16pt;
            font-weight: normal;
            }
            h2 {
            text-align: center;
            font-size: 10pt;
            font-weight: normal;
            margin: 0pt;
            }
            tr.manual_imprint td {
            border-bottom:1pt dotted black;
            height: 30pt;
            vertical-align: bottom;
            }
            h3 {
            text-align: center;
            font-size: 13pt;
            font-weight: normal;
            }
            h3.left {
            font-size: 13pt;
            text-align: left;
            }
            hr {
            height: 1pt;
            color: black;
            background-color: black;
            border: 0pt;
            }
            table {
            width: 100%;
            border: 0pt;
            padding: 0pt;
            border-spacing: 0pt;
            }
            tr.lineitem_head td {
            border-bottom:1pt solid black;
            }
            tr.total td {
            border-top:1pt solid black;
            border-bottom:3pt double black;
            font-size: 12pt;
            font-weight: bold;
            }
            td {
            overflow: hidden;
            }
            td.left {
            max-width: 1px;
            text-align: left;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            }
            td.left_indent {
            text-align: left;
            padding-left: 7pt;
            }
            td.right {
            text-align: right;
            vertical-align: top;
            white-space: nowrap;
            }
        </style>
    </head>
    <body>
        <h1>Tischlerei Helmut Meyer_676647</h1>
        <h3 class="left documentType">Proforma-Quittung</h3>
        <table class="order">
            <tr class="lineitem_head">
                <td></td>
                <td class="right">27.03.17 11:18</td>
            </tr>
        </table>
        <table class="lineitems">
            <colgroup>
                <col width="100%" />
                <col width="0%" />
            </colgroup>
            <tbody>
                <tr class="lineitem" data-net="3,78 €">
                    <td class="left">1x&nbsp;Filter Kalita</td>
                    <td class="right">4,50 €</td>
                </tr>
                <tr class="lineitem" data-net="3,03 €">
                    <td class="left">1x&nbsp;Latte</td>
                    <td class="right">3,60 €</td>
                </tr>
                <tr class="lineitem" data-net="7,38 €">
                    <td class="left">1x&nbsp;Skywalker/250g</td>
                    <td class="right">7,90 €</td>
                </tr>
                <tr class="lineitem" data-net="8,32 €">
                    <td class="left">1x&nbsp;Playground Love</td>
                    <td class="right">8,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;Dschaggah Khan</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
                <tr class="lineitem" data-net="12,06 €">
                    <td class="left">1x&nbsp;King Kongo</td>
                    <td class="right">12,90 €</td>
                </tr>
            </tbody>
            <tfoot>
                <tr class="total">
                    <td class="left">Total</td>
                    <td class="right">50,70 €</td>
                </tr>
                <tr class="net">
                    <td class="left">Netto</td>
                    <td class="right">46,62 €</td>
                </tr>
                <tr class="tax">
                    <td class="left">7,00 VAT</td>
                    <td class="right">2,79 €</td>
                </tr>
                <tr class="tax">
                    <td class="left">19,00 VAT</td>
                    <td class="right">1,29 €</td>
                </tr>
            </tfoot>
        </table>
    </body>
</html>

0 个答案:

没有答案