在我的代码中,我正在Spire.Doc
使用包查找和替换 Word 文件中的某些特定单词并在 PDF 文件中导出Microsoft.Office.Interop.Word
它在本地服务器上工作正常,但不适用于 AWS 托管服务器ASP.Net
[在当地工作]
[服务器图像有语法问题]
//doc creation
Spire.Doc.Document doc = new Spire.Doc.Document(Server.MapPath("~/Download/demo.docx"));
doc.Replace("todayDate", DateTime.Now.Date.ToString("dd-MM-yyyy"), true, true);
doc.Replace("App_Name", AppName, true, true);
doc.Replace("App_Date", App_Date, true, true);
doc.Replace("Sales_Name", SalesName, true, true);
doc.Replace("App_Address", App_Address, true, true);
doc.Replace("Sales_Address", Sales_Address, true, true);
doc.Replace("csNO", csNO, true, true);
doc.Replace("tnmntNO", TenamentNO, true, true);
doc.SaveToFile(string.Concat(Server.MapPath("~/hukam/"), App_id, ".docx"), FileFormat.Auto);
doc.Close();
//pdf genration
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
Word._Application oword = new Word.Application();
oword.Visible = false;
object oMissing = System.Reflection.Missing.Value;
object isVisible = true;
object readOnly = false;
object oInput = string.Concat(Server.MapPath("~/hukam/"), App_id, ".docx");
string oOutput = string.Concat(Server.MapPath("~/hukam/"), App_id, ".pdf");
Word._Document oDoc = oword.Documents.Open(oInput,oMissing,readOnly,oMissing);
oDoc.Activate();
oDoc.EmbedTrueTypeFonts = true;
if (oDoc.Paragraphs.Count > 0)
{
foreach (Paragraph p in oDoc.Paragraphs)
{
p.Range.Font.Name = "Shruti";
}
}
if (oDoc.Footnotes.Count > 0)
{
foreach (Footnote fn in oDoc.Footnotes)
{
fn.Range.Font.Name = "Shruti";
}
}
oDoc.ExportAsFixedFormat(oOutput, WdExportFormat.wdExportFormatPDF);
oDoc.Close();
oword.Quit();