In My Code, I am doing Find and Replacing some specific Words in Word File Using Spire.Doc
and Exporting in PDF File using Microsoft.Office.Interop.Word
Packages its Working fine for me on local Server but not working on AWS hosted Server in ASP.Net
[Working in local]
[Server image has Grammar issue]
//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();