Dear Team,
I have an asp.net application, in that one functionality I need to show the word document in the browser by highlighting few keywords in the word document.
Finding the keyword to highlight I am using below code.
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
public Microsoft.Office.Interop.Word.Document wordDocument { get; set; }
string dummyFile = “File path”;
wordDocument = appWord.Documents.Open(dummyFile);
var range = wordDocument.Range();
while (range.Find.Execute(word))
{
Microsoft.Office.Interop.Word.Range tmpRange = wordDocument.Range(range.Start, range.End);
tmpRange.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow;
tmpRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdYellow;
matchCount++;
}
Microsoft.Office.Interop.Word.Range
tmpRange1 = wordDocument.Range(0, 0);
if (matchCount > 0)
{
tmpRange1.Text ="Match Count : "+ matchCount +"\n\n";
tmpRange1.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBlue;
tmpRange1.Font.Size = 12;
tmpRange1.Font.Bold = 1;
tmpRange1.InsertParagraphBefore();
}
wordDocument.ExportAsFixedFormat(dummyFile +".pdf",WdExportFormat.wdExportFormatPDF);
var bytes = System.IO.File.ReadAllBytes(dummyFile.ToLower().Replace(".doc","").Replace("x","") +""+".pdf");
Context.Response.ContentType ="application/pdf";
Context.Response.AddHeader("Content-disposition","inline");
Context.Response.BinaryWrite(bytes.ToArray());
The above code is working as expected, Finding the keyword occurrences count and inserting the text in 0<sup>th</sup> position of word document. Then converting
the word to PDF using WdExportFormat.wdExportFormatPDF.
The problem here to be solved is, this code shows me the PDF only if a administrator logged in the server. After log off it shows the below exception.
System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 8000401a
The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A). at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) at
System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj) at System.RuntimeTypeHandle.CreateInstance(RuntimeType
type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&
stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type
type
Even, I have created a local user and configured DCOM given the credentials. Still it is not working.
Any help in this would be highly appreciable.
Selvakumar Rathinam