itext7 pdfhtml 2.0.2没有背景和边框

时间:2018-06-01 07:33:24

标签: java itext7 pdfhtml

找不到任何文档,请帮忙。 我试图使用itext 7 / pdfhtml 2.0.2从html字符串生成简单的pdf,并且无法使其渲染背景和边框。只看到带有文本的空pdf - 没有背景和边框。也许有一个参数或什么?这是我在itext网站上找到的代码(尝试使用和不使用ConverterProperties#setBaseUri的机器人):

    OutputStream os=resp.getOutputStream();

    ConverterProperties properties = new ConverterProperties();
    properties.setBaseUri(url.toString());
    PdfWriter writer = new PdfWriter(os,
            new WriterProperties().setFullCompressionMode(true));
    HtmlConverter.convertToPdf(buf.toString(), writer, properties);
    os.close();

html很简单:只有一个div,而css就是它:

<html>
<head>
    <meta charset="UTF-8"/>
   <link rel='stylesheet' type='text/css' href='/css/html2pdf.css' />
    <title>
        HTML 2 PDF
    </title>
</head>
<body>
    <div id="maincontainer">
        <div id="rightruler"></div>
    <div id="infoBox0" class="infoItem resizey" contenteditable="true" style="position: absolute; display: block; margin: 0px; left: 633px; top: 2

</body>

和css:

@font-face
{
    font-family: helv-light;
    src: url("../fonts/helveticaneuelight-webfont.ttf");
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

@font-face
{
    font-family: helv;
    src: url("../fonts/helveticaneue-webfont.ttf");
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

@font-face
{
    font-family: helv-medium;
    src: url("../fonts/helveticaneuemedium-webfont.ttf");
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

@font-face
{
    font-family: helv-bold;
    src: url("../fonts/helveticaneuebold-webfont.ttf");
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

html
{
    margin: 0;
    padding: 0;
    height: 100%;
}

body
{
    font-family: helv-light;
    margin: 0;
    padding: 0;
    min-height: 100%;
    box-sizing: border-box;
    color: #555555;
}
div#maincontainer
{
    width: 100%;
    border: 1px solid #555555;
    color: #ffffff;
    overflow: auto;
    position: relative;
    background-color: #774400;
}
div.infoItem
{
    display: inline-block;
    position: relative;
    width: 10em;
    height: 4em;
    border: 1px solid #ffffff;
    background-color: #000000;
    color: #ffffff;
    padding: .5em;
    outline: none;
    box-sizing: border-box;
}

0 个答案:

没有答案