我们如何通过asp.net将word文档转换为pdf。我通过 FileUpload 浏览了一个 ms-word 文件,当我点击 OK 时,它会自动将该文件转换为 PDF。谁能指导我怎么可能。我通过谷歌得到了一些代码,但那是不完整的。如果有人知道解决方案,请与我分享。
问问题
3477 次
2 回答
0
private Microsoft.Office.Interop.Word.ApplicationClass MSdoc;
//Use for the parameter whose type are not known or say Missing
object Unknown = Type.Missing;
private void word2PDF(object Source, object Target)
{ //Creating the instance of Word Application
if (MSdoc == null)MSdoc = new Microsoft.Office.Interop.Word.ApplicationClass();
try
{
MSdoc.Visible = false;
MSdoc.Documents.Open(ref Source, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
MSdoc.Application.Visible = false;
MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (MSdoc != null)
{
MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);
//WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown);
}
// for closing the application
WordDoc.Quit(ref Unknown, ref Unknown, ref Unknown);
}
}
请参阅以下内容:在 c# 中将word转换为pdf
文件,以便在 asp.net 中进行代码隐藏
iTextSharp 也是一种选择。
希望这有帮助..
于 2012-06-06T07:53:11.507 回答
0
@Niranjan Kala's answer is a well and good option
still if you need an another option you can go for: which provides SDK's for the same..
于 2012-06-06T07:58:00.630 回答