文件导出为PDF Asp.net [英] Export Doc to PDF Asp.net

查看:241
本文介绍了文件导出为PDF Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用这个code,以一个FormView导出到Word中。
其作品great..But我希望它导出为PDF格式,以便它不能编辑。或者可能是一个Word文档,这样不是身体能做出改变。

So I am using this code, to export a formview to Word. Its works great..But I want it to export to PDF so that it cannot be edited. Or may be to a word doc so that not body can make changes.

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition",
    "attachment;filename=Report.doc");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-word";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    FormView1.DataBind();
    FormView1.RenderControl(hw);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
}

问题是,即使当我改变了内容类型和头部元素在上面code,它说,该输出PDF格式有错误。

The problem is, even when I change the content type and header element in the above code, it says that the output pdf has errors.

我真的想要么将文档转换为PDF或使用该code生成PDF。

I really want to either convert the doc to pdf or generate pdf using this code.

请帮忙。

谢谢..

推荐答案

在ASP.NET中创建PDF最好的方法是在使用插件像iTextSharp的。我已经在过去使用它,它非常简单,并且免费。

Your best bet to create PDFs in ASP.NET is to use a plug in like iTextSharp. I have used it in the past and it's very simple and free.

http://itextpdf.com/

这篇关于文件导出为PDF Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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