none
application hangs while converting word to pdf, even its not saving for one word file. RRS feed

  • General discussion

  • I am trying to convert word file into pdf using Interop. 

    using Word = Microsoft.Office.Interop.Word;
    void convertword()		
    {
    	Word.Application word = new Word.Application();
    	word.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
    	word.Options.WarnBeforeSavingPrintingSendingMarkup = false;
    	word.Visible = false;
    	word.ScreenUpdating = false;
    	FileInfo[] wordFiles = dirInfo.GetFiles("filepath");
    	foreach (FileInfo wordFile in wordFiles)
    	{
    		string filename = wordFile.FullName;
    		Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
    		try
    		{
    			doc = word.Documents.Open(filename);	\\ line 1
    			doc.DoNotEmbedSystemFonts = true;		\\ line 2
    			doc.EmbedSmartTags = false;				\\ line 3
    			doc.EmbedTrueTypeFonts = false;			\\ line 4
    			doc.Activate();							\\ line 5
    			filename = filename.Replace(".doc", ".pdf");	\\ line 6
    			doc.Save();   					\\ line 7
    			doc.ExportAsFixedFormat(filename, Word.WdExportFormat.wdExportFormatPDF);	\\ line 8
    			((Word._Document)doc).Close();			\\ line 9
    		}	
    		finally
    		{
    			((Word._Application)word).Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
    			doc = null; 
    		}		              
    	}
    }

    although its working fine , but suddenly for one word document program is stuck in between line number 2 to line no. 7

    i ma not able to figure it out why this is happening.

    can someone help it.



    • Edited by DBT_MS Friday, October 4, 2019 10:21 AM
    • Changed type DBT_MS Monday, October 7, 2019 7:29 AM
    Friday, October 4, 2019 10:20 AM