英文:
How to get NReco.PdfGenerator to honour `column-count` css property
问题
我有一个网页注册表格,我们需要将其通过电子邮件发送给我们的客户。该表格已经使用column-count
CSS属性分为两列。
不幸的是,当NReco.PdfGenerator生成PDF时,这些列会呈现为单列,打破了表格的流程。
例如,使用NReco网页上的在线PDF生成器和来自W3Schools的column-count
示例(是的,我知道!),我们只能看到生成了单列。
有人知道如何让NReco.PdfGenerator遵守column-count
属性,或者是否有另一个库可以成功地转换一些大型(9页)的网页表格吗?
更新
看起来这是与底层的wkhtmltopdf库相关的问题(现在已归档)。
有人知道有没有正在更新的这个库的分支吗?
英文:
I've got a web page enrolment form that we need to email to our customers. The form has been divided into 2 columns using the column-count
css property.
Unfortunately, when NReco.PdfGenerator generates the Pdf, these columns are rendered as a single column, breaking the flow of the form.
As an example, using the Online Pdf Generator on the NReco web page and the example for column-count
from W3Schools (yes, I know!), we can see only a single column generated.
Does anyone have any idea how to get NReco.PdfGenerator to honour the column-count
property, or of another library that can successfully transform some large (9 page) web forms?
Update
Looks like this is an issue with the underlying wkhtmltopdf library (which has now been archived)
Anyone know of a fork of this that is being updated?
答案1
得分: 1
wkhtmltopdf是基于QtWebKit 4.8的,这是一个相当古老的渲染引擎,不支持许多现代的CSS3功能,包括"column-count"。
你可以尝试这个解决方法来实现类似"column-count"的效果:https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1872(虽然不是100%的替代,因为它只适用于适合单页的内容)。另一种选择是使用像这样的js插件来将内容分割为"columns":https://github.com/adamwulf/Columnizer-jQuery-Plugin。
最后,你可以考虑使用基于现代无头Chrome的方法将HTML页面转换为PDF:https://gotenberg.dev/(部署不像wkhtmltopdf那么简单,它需要一个单独的Docker容器来运行),并使用现有的.NET客户端之一从C#代码中访问这个Web API。如果你喜欢NReco.PdfGenerator API的简单性,从技术上讲可以添加一个"HtmlToPdfConverter"实现,它将使用gotenberg API代替wkhtmltopdf。
英文:
As you already noticed wkhtmltopdf is based on QtWebKit 4.8 which is rather old rendering engine and it doesn't support many modern CSS3 things including "column-count".
You may try this workaround to achieve result that is similar to "column-count": https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1872 (not a 100% replacement as it works only for content that fits a single page). Another option can be usage of js plugin that splits content on 'columns' like this one: https://github.com/adamwulf/Columnizer-jQuery-Plugin
Finally, you can consider to use modern headless-Chrome based way to convert HTML pages to PDFs: https://gotenberg.dev/ (its deployment is not so simple as wkhtmltopdf -- it requires a separate docker container to run) and use one of existing .NET clients to access this web API from C# code. If you like NReco.PdfGenerator API simplicity technically it is possible to add 'HtmlToPdfConverter' implementation that will use gotenberg API instead of wkhtmltopdf.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论