【问题标题】:How convert word document to pdf programmatically如何以编程方式将word文档转换为pdf
【发布时间】:2012-07-11 22:21:16
【问题描述】:

我尝试使用此代码生成 word 文档:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.ContentType = "application/doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; 
filename=" + DateTime.Now + ".doc");

var strHTMLContent = new StringBuilder();

strHTMLContent.Append(
    "<h1 title='Heading' align='Center'style='font-family: verdana; font 
-size: 80 % ;color: black'><u>Document Heading</u> </h1> ");

strHTMLContent.Append("<br>");
strHTMLContent.Append("<table align='Center'>");

// Row with Column headers
strHTMLContent.Append("<tr>");
strHTMLContent.Append("<td style='width:100px; background:# 99CC00'>
<b>Column1 </b>  </td>");

strHTMLContent.Append("<td style='width:100px;background:# 99CC00'>
<b>Column2 </b>  </td>");

strHTMLContent.Append("<td style='width:100px; background:# 99CC00'>
<b>Column 3</b></td>");
strHTMLContent.Append(" </tr> ");

// First Row Data
strHTMLContent.Append("<tr>");
strHTMLContent.Append(
    "<td style='width:100px'></td>");
strHTMLContent.Append(
    "<td style='width:100px'>b</td>");
strHTMLContent.Append(
    "<td style='width:100px'>c</td>");
strHTMLContent.Append("</tr>");

// Second Row Data
strHTMLContent.Append("<tr>");
strHTMLContent.Append(
    "<td style='width:100px'>d</td>");
strHTMLContent.Append(
    "<td style='width:100px'>e</td>");
strHTMLContent.Append(
    "<td style='width:100px'>f</td>");
strHTMLContent.Append("</tr>");

strHTMLContent.Append("</table>");

strHTMLContent.Append("<br><br>");
strHTMLContent.Append(
    "<p align='Center'> Note : This is a dynamically 
            generated word document  </p> ");
HttpContext.Current.Response.Write(strHTMLContent);
//  HttpContext.Current.Response.BinaryWrite(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();

有谁知道如何以编程方式将此 word 文档转换为 PDF 文件?

【问题讨论】:

    标签: c# asp.net pdf ms-word


    【解决方案1】:

    由于您正在构建要转换的 HTML,您可以使用 iTextSharp API 从 HTML 转换为 PDF:ITextSharp HTML to PDF?。 iTextSharp 是免费的。

    【讨论】:

      【解决方案2】:

      默认情况下,MS .Net Framework 不提供任何内容,您必须为其使用第三方 API

      例如,查看 API easyPDF 使用 C# http://www.pdfonline.com/easypdf/sdk/programming-pdf/csharp/index.htm?_kk=%2Bpdf%20%2Bc%23&_kt=0e3c1bed-3404-4289-8143-77333a737850&gclid=CPT--pXTk7ECFa4mtAodKn5ylw 进行转换的链接

      【讨论】:

      • @Alex 是的,它不是,我怀疑他们是否有任何免费的 API 可以提供该功能
      【解决方案3】:

      在使用了许多不同的选项后,这是迄今为止我们找到的最好的一个。昂贵,但惊人的速度和多功能性,以及体面(虽然不是很好)的支持文档。 http://www.html-to-pdf.net/Support.aspx#csharp - 如果是可以转嫁成本的商业项目,值得一看。

      【讨论】:

        猜你喜欢
        • 2010-09-07
        • 2011-12-02
        • 2011-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多