【问题标题】:how to set baseuri in converterproperties in itext7 html to pdf converter如何在itext7 html到pdf转换器的converterproperties中设置baseuri
【发布时间】:2020-10-20 16:10:48
【问题描述】:

after converting into pdf 我正在尝试使用 Itext7 将 html 转换为 pdf。我希望将引导 css 包含在 pdf 中。我正在尝试设置 baseuri,但它不起作用。 这是我的代码:

using (MemoryStream stream = new System.IO.MemoryStream())
    {
        ConverterProperties properties = new ConverterProperties();
        properties.SetBaseUri("/css/"); // I tried this in many ways 
        properties.SetFontProvider(new DefaultFontProvider(true, true, true));
        HtmlConverter.ConvertToPdf(GridHtml, new PdfWriter(stream), properties);
        return File(stream.ToArray(), "application/pdf", "test1.pdf");
    }

this is the view before downloading in browser

【问题讨论】:

    标签: c# html pdf


    【解决方案1】:

    在 html 内容中包含您的 css 文件,例如 <link rel="stylesheet" type="text/css" href="mycss.css"/>

    并设置你的 CSS 内容的基本 uri

    ConverterProperties properties = new ConverterProperties();
    properties.SetBaseUri("Content//css//");
    

    【讨论】:

      猜你喜欢
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 2018-04-07
      相关资源
      最近更新 更多