本文介绍了ASP.NET MVC:渲染视图生成PDF:使用iTextSharp的或更好的解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到显示在HTML和打印版本。 HTML版本确实jQuery的标签等,而打印机友好的具有零脚本和外部依赖性,无主布局,不需要额外的按键,内嵌CSS,而且可以没有问题地保存为HTML。

由于我使用星火视图引擎,我虽然也许这是使用iTextSharp的引擎生成PDF是一个好主意。但几段后,我决定这是太麻烦了,因为一)我将不得不重写整个收据(来源星火观点是大约5页长)B)我有问题iTextSharp的由头 - 例如,编号列表不停符号,无缩进和indentationLeft左缩进=20没有工作 - 的也许是因为缺少文件,但见(一)

所以,我对PDF的要求很简单:我想保持相同的HTML,但插入个人收入之间的分页符(是的,我有一个单一的文件数的)

有没有生成视图/ HTML PDF不用重写认为一个简单的方法一个奇怪的引擎?

更新:试过社区HTMLDOC版本;没有使用内嵌我的CSS样式,错误地显示为货币统一code符号。 做挑CSS,但失败的货币符号; 通过设置字符集为UTF-8解决。 wkhtmltopdf似乎是不错,但我还没有搞清楚如何设置分页符...


解决方案

最后使用wkhtmltopdf当我设置的编码,我发现它是如何设置分页符,并处理我的CSS很不错的,工作正常。在的问题是,它不能正确处理标准输入/出Windows版本(不记得了,如果是在进出不起作用) - 可固定在最近的版本,但我确定与临时文件

I display receipt in both HTML and printer-friendly version. HTML version does jQuery tabs, etc, while printer-friendly has zero scripts and external dependencies, no master layout, no additional buttons, inline CSS, and can be saved as HTML without problems.

Since I use Spark View Engine, I though maybe it's a good idea to generate PDF using iTextSharp engine. But after few paragraphs I decided it's too cumbersome, because a) I would have to rewrite entire receipt (source Spark view is about 5 pages long) b) I had problems with iTextSharp from beginning - for example, numbered lists kept bulleted, with no indentation, and indentationLeft="20" didn't work - maybe because of lack of documentation, but see (a).

So, my requirements for PDF are very simple: I want to keep the same HTML but insert page breaks between individual receipts (yes I have several ones in a single document).

Is there a simple way to generate PDF from view/HTML without rewriting the view using a strange engine?

UPDATE: tried community HTMLDoc version; didn't use my inline CSS styles, incorrectly displayed Unicode symbols for currencies. wkhtmltopdf did pick the CSS but failed for currency symbol; solved by setting charset to utf-8. wkhtmltopdf seems to be nice but I'm yet to figure out how to set page breaks...

解决方案

Finally used wkhtmltopdf which works fine when I set encoding, I found out how to setup page breaks, and it processes my CSS very nice. On issue is that it can't correctly process stdin/out in Windows version (don't remember if it's in or out that doesn't work) - may be fixed in recent versions, but I'm ok with temp files.

这篇关于ASP.NET MVC:渲染视图生成PDF:使用iTextSharp的或更好的解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:18