如何转换Word文档以编程
问题描述:
我尝试使用此代码生成word文档的PDF:如何转换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文件编程?
答
既然你正在构建HTML的API easyPDF做转换要转换,您可以使用iTextSharp API从HTML转为PDF:ITextSharp HTML to PDF?。 iTextSharp是免费的。
答
MS .NET Framework并不是默认提供什么,你将不得不使用THRID方API,它
答
使用了很多不同的选项后,这是迄今为止我们发现的最好的选项。昂贵的,但惊人的速度和多功能性,体面的(虽然不是很好)支持文档。 http://www.html-to-pdf.net/Support.aspx#csharp - 值得一看,如果它是一个商业项目,其成本可以传递。
此组件不是免费的) – Alex 2012-07-12 08:03:01
@Alex是的,它不是,我怀疑他们是任何免费的API,将提供功能 – HatSoft 2012-07-12 08:05:18