У меня была эта проблема, поэтому я преобразовал Word Word в PDF программно. Теперь мне нужно вызвать одноименный файл PDF в браузере. (Doc1.docx to Doc1.pdf) Вы можете использовать переменные для вызова документов. Это бэкэнд-код на C #, который прекрасно справляется с задачей. Также не забудьте добавить ссылку на библиотеку объектов Microsoft Word 12.0. Вызовите этот метод или сделайте его классом. Затем позвоните документу после этого.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Office.Interop.Word;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ApplicationClass wordApplication = new ApplicationClass();
Document wordDocument = null;
object paramSourceDocPath = @"D:\Websites\Docs\Doc1.docx";
object paramMissing = Type.Missing;
string paramExportFilePath = @"D:\Websites\Docs\Doc1.pdf";
WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
bool paramOpenAfterExport = false;
WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
try
{
// Open the source document.
wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing);
// Export it in the specified format.
if (wordDocument != null)
wordDocument.ExportAsFixedFormat(
paramExportFilePath,
paramExportFormat,
paramOpenAfterExport,
paramExportOptimizeFor,
paramExportRange,
paramStartPage,
paramEndPage,
paramExportItem,
paramIncludeDocProps,
paramKeepIRM,
paramCreateBookmarks,
paramDocStructureTags,
paramBitmapMissingFonts,
paramUseISO19005_1,
ref paramMissing);
}
catch (Exception ex)
{
// Respond to the error
}
finally
{
// Close and release the Document object.
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
wordDocument = null;
}
// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}