0

我正在尝试将 HTML 代码转换为 JPEG 图像。它有点工作,但当我尝试使用条形码时它不起作用。

服务器端,我正在使用:

我正在使用 CODE128 协议对 EAN133 条码进行编码,当我想在网页上显示它时它可以工作(我使用它HttpUtility.HtmlEncode(code_barre)以便很好地解释条码),然后我使用条码字体来显示条码,这就是我的图片有问题:

在此处输入图像描述

如您所见,它是格式良好的条形码“纯文本”,并具有以下 CSS:

@font-face { font-family: 'code_128regular'; src: url('/Assets/Fonts/code128-webfont.eot'); src: url('/Assets/Fonts/code128-webfont.eot?#iefix') format('embedded-opentype'), url('/Assets/Fonts/code128-webfont.woff2') format('woff2'), url('code128-webfont.woff') format('woff'), url('/Assets/Fonts/code128-webfont.ttf') format('truetype'), url('/Assets/Fonts/code128-webfont.svg#code_128regular') format('svg'); font-weight: normal; font-style: normal;} .test{font-family:'code_128regular'; font-size:70px;}

我应该变成这样:

在此处输入图像描述

但它没有,即使我使用相对路径导入 Bootstrap CSS,而当我尝试使用IronPDF生成 PDF 时它可以工作

感谢关注

编辑:这是生成的 HTML:

<html>
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
    <link rel='stylesheet' type='text/css' href='Assets/Bootstrap/css/bootstrap.min.css'>
    <script type='text/javascript' src='Assets/Bootstrap/js/bootstrap.min.js'></script>
</head>
<style>
    @font-face {
        font-family: 'code_128regular';
        src: url('/Assets/Fonts/code128-webfont.eot');
        src: url('/Assets/Fonts/code128-webfont.eot?#iefix') format('embedded-opentype'), url('/Assets/Fonts/code128-webfont.woff2') format('woff2'), url('code128-webfont.woff') format('woff'), url('/Assets/Fonts/code128-webfont.ttf') format('truetype'), url('/Assets/Fonts/code128-webfont.svg#code_128regular') format('svg');
        font-weight: normal;
        font-style: normal;
    }

    .test {
        font-family: 'code_128regular';
        font-size: 70px;
    }
</style>
<center><p class='test'>&#204;MXCUTGRIP305-07D&#206;</p><p>MXCUTGRIP305-07</p></center>
</html>
4

1 回答 1

1

NReco ImageGenerator 在内部使用 wkhtmltoimage 命令行工具,因此实际上您可以期待相同的行为。在您的情况下,wkhtmltoimage 似乎出于某种原因忽略了您的自定义字体;首先尝试使用 woff、woff2 或 ttf 字体文件而不是 eot。如果您使用接受 HTML 作为 .NET 字符串的“GenerateImage”方法,所有外部引用都应该是绝对的。

以下 HTML 模板对我来说很好用(我使用了来自 google 字体的“Libre Barcode 128”):

<html>
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Libre+Barcode+128&amp;lang=en" />  
</head>
<style>
    .test {
        font-family: 'Libre Barcode 128';
        font-size: 70px;
    }
</style>
<center><p class='test'>&#204;MXCUTGRIP305-07D&#206;</p><p>MXCUTGRIP305-07</p></center>
</html>
于 2017-10-24T13:41:18.600 回答