1

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]

enter image description here

[Server image has Grammar issue]

enter image description here

//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();
jishan siddique
  • 1,848
  • 2
  • 12
  • 23

1 Answers1

1

I tried to resolved it by changing some of the code and its worked fine for me. Here I'm posting the answer. Might be Helpful for someone.
            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.Replace("txtNondh", txtNon, true, true);

            doc.SaveToFile(string.Concat(Server.MapPath("~/hukam/"), App_ID, ".docx"), FileFormat.Auto);

            doc.Close();

            //creating PDF
            RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
            wordProcessor.LoadDocument(string.Concat(Server.MapPath("~/hukam/"), App_ID, ".docx"), DocumentFormat.OpenXml);

            //Specify export options:
            PdfExportOptions options = new PdfExportOptions();
            options.DocumentOptions.Author = "ArpitPatel";
            options.Compressed = false;
            options.ImageQuality = PdfJpegImageQuality.Highest;

            //Export the document to the stream:
            using (FileStream pdfFileStream = new FileStream(string.Concat(Server.MapPath("hukam/"), App_ID, ".pdf"), FileMode.Create))
            {
                wordProcessor.ExportToPdf(pdfFileStream, options);
            }

Thanks & Regards