Home  >  Article  >  Web Front-end  >  Html代码保存为Pdf文件_html/css_WEB-ITnose

Html代码保存为Pdf文件_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:48:361072browse

前段时间Insus.NET有实现了《上传Text文档并转换为PDF》 和《截取视图某一段另存为部分视图(Partial View)》 。现今Insus.NET想结合上面两篇来实现另外一个功能,就是把截取的Html保存为pdf文件。

上一篇把Text文档转换为pdf是直接把文件进行转换。现在我们不必把html代码保存为文件之后再转换。使用iTextSharp组件转换pdf,它由字符串也可以转换。因此我们不必绕一个圈了。


在控制器中,写一个转换pdf的操作,下面有两代码是把字符串转换为byte的,得到的byte刚才匹配iTextSharp的转入参数类型。

 byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);


完整代码示例:

 

在视图中,我添加一个铵钮,修改一下url路径:


演示:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn