如何通过asp.net将word文档转换为pdf。我通过FileUpload& amp;浏览一个ms-word文件。当我点击确定时,它会自动将该文件转换为PDF。任何人都可以指导我怎么可能。我得到了谷歌的一些代码,但那是不完整的。如果有人知道解决方案,请与我分享。
答案 0 :(得分: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);
}
}
参考这些:
Convert word to pdf file for codebehind in asp.net in c#
Convert DOC to PDF
a .NET dll for office 2010 to convert word to pdf and code in c#
Convert word to pdf using free third party dll
iTextSharp也是一种选择。
希望这有帮助..
答案 1 :(得分:0)