如何转换Word文档PDF编程 [英] How convert word document to pdf programmatically

查看:217
本文介绍了如何转换Word文档PDF编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用这个code生成word文档:

I try to generate word document using this code:

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();

有谁知道如何这个词文档转换为PDF文件编程?

Does anyone know how to convert this word document to a PDF file programmatically?

推荐答案

既然你正在构建HTML转换,可以使用的 iTextSharp的 API去从HTML到PDF: iTextSharp的HTML到PDF 。 iTextSharp的是免费的。

Since you are building HTML to convert, you can use iTextSharp API to go from HTML to PDF: ITextSharp HTML to PDF?. iTextSharp is free.

这篇关于如何转换Word文档PDF编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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