使用 CSS 从 HTML 渲染 iTextSharp 中的 PDF [英] Render PDF in iTextSharp from HTML with CSS

查看:26
本文介绍了使用 CSS 从 HTML 渲染 iTextSharp 中的 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

知道如何使用 iTextSharp 呈现 PDF 以便它使用 CSS 呈现页面.css 可以嵌入在 HTML 中,也可以单独传入,我不在乎,只希望它起作用.

Any idea how to render a PDF using iTextSharp so that it renders the page using CSS. The css can either be embedded in the HTML or passed in separately, I don't really care, just want it to work.

非常感谢特定的代码示例.

Specific code examples would be greatly appreciated.

另外,我真的很想坚持使用 iTextSharp,不过如果你对其他东西有任何建议,它必须是免费的、开源的,并且拥有允许在商业软件中使用它的许可证.

Also, I would really like to stick with iTextSharp, though if you do have suggestions for something else, it's got to be free, open source, and have a license that permits using it in commercial software.

推荐答案

现在不可能,但没有什么能阻止你开始开源项目.我可能真的会开始一个,因为我也需要它!

It's not possible right now but nothing stops you from starting open-source project that will do it. I might actually start one, because I need it too!

基本上,您将需要将 html 和 css 标记转换为 iTextSharp 类的解析器.所以

变成了 iTextSharp.SimpleTable 等等.

Basically you will need parser that will convert html and css markup into iTextSharp classes. So <table> becames iTextSharp.SimpleTable and so on.

想出能够处理有限的 html 和 css 子集的原型会很容易.

It would be easy to come up with prototype that would be able to work with limited html and css subset.

更新:在这成为可能之前,我就是这样临时为自己解决的.只需两步:

Update: Until the time this will be possible, this is how I temporarily resolved it for myself. Only two steps:

  • 告诉您的用户下载名为 PDFCreator
  • 通过提供用于打印的样式表,使您所有的 html 报告都易于打印.

  • Tell your users to download open-source app called PDFCreator
  • Make all your html reports printer friendly by providing stylesheets for print.

如果您的某些多页报告需要在每个页面上都有标题,请在 THEAD html 标记中设置它们.

现在用户将能够打印友好,如果他们选择 PDFCreator 打印机驱动程序,他们甚至可以得到 PDF 格式的报告(还有其他 pdf 打印机驱动程序,但这个是免费和开源的).

Now users will be able to print-friendly and if they choose PDFCreator printer driver, they will even be able to get report in PDF format (there are other pdf printer drivers but this one is free and open-source).

我也知道 HTML 不如 PDF 灵活,但它可能已经足够好了.我正在与真实用户进行一些测试,他们实际上很喜欢它,因为他们现在不仅可以将任何内容打印为 PDF(甚至超出我的应用程序),而且他们的工作流程更快,因为他们不必下载并等到他们的 pdf 阅读器打开向上.他们只是直接从他们的网络浏览器打印(或导出为 pdf)他们在网站上看到的内容......有点道理.

Also I know HTML is not as flexible as PDF but it might be good enough. I was doing some tests with real users and they actually like it because not only they can now print anything to PDF (even beyond my app), also their workflow is faster because they don't have to download and wait until their pdf reader opens up. they just print (or export to pdf) what they see on website directly from their webbrowser... kind of makes sense.

这篇关于使用 CSS 从 HTML 渲染 iTextSharp 中的 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆