【问题标题】:HTML text with image to PDF带有图像的 HTML 文本到 PDF
【发布时间】:2022-02-18 18:25:25
【问题描述】:

在生成带有 IText 中图像的 PDF 时遇到问题。

我们能够使用 IText 生成文档的文本,但它不会拉动图像。

我们正在关注他们电子书中的文字https://kb.itextpdf.com/home/it7kb/ebooks/itext-7-converting-html-to-pdf-with-pdfhtml/chapter-1-hello-html-to-pdf

有问题的代码如下:

void createPdf(string baseUri, string html, string dest)
{
ConverterProperties properties = new ConverterProperties();
properties.SetBaseUri(baseUri);
HtmlConverter.ConvertToPdf(html, new FileStream(dest, FileMode.Create), properties);
}

据我们所知,问题在于字符串 baseUri

我们假设这是在 Visual Studio 中的 C# 项目中保存图像的目录,并且到目前为止使用以下内容作为字符串无济于事:

  1. /图片/
  2. /Images/NewLogo.png
  3. http://localhost:64070/Images/NewLogo.png

这些都没有生成 PDF 中的图像,任何帮助或建议将不胜感激。

【问题讨论】:

  • 感谢您的回复。您能否通过父文件夹/更具体一些?
  • 我们在解决方案下创建了一个名为 Images 的文件夹,用于存储要使用的图像。
  • 以下内容可能会有所帮助:stackoverflow.com/questions/69210758/…
  • 删除绒毛的编辑are fine;这个特殊的编辑也改进了标题(大写没有意义,标签不在标题中)。请不要进一步回滚
  • 问题是用户删除了 IText,这个特定问题与 IText 相关

标签: c# html pdf itext


【解决方案1】:

我们发现,如果我们将 BaseUri 设置为 url 上图像的位置,我们就可以在 PDF 上生成图像

【讨论】:

    猜你喜欢
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 2012-07-08
    • 2018-05-06
    • 1970-01-01
    相关资源
    最近更新 更多