C# Word Interop - Open a .pdf without the conversion prompt

痞子三分冷 提交于 2021-01-27 20:59:30

问题


I am using the Word Interop and wish to open a .pdf file and let word automatically do the conversion.

I have the following properties set.

var wordApp = new Word.Application();
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
wordApp.Options.DoNotPromptForConvert = true;
wordApp.Options.ConfirmConversions = false;
var doc = wordApp.Documents.OpenNoRepairDialog(ExternalFilePath, false, true);

However when it does the Open I still get the following prompt:

Word version 2016.

Does anyone know how to by-pass this? If I click OK the rest of the program executes as I'd expect successfully.

I am aware of and do not wish to use any other third-party tools.


Thanks to BugFinder for the suggestion of using the Format parameter, but still no luck with this.

Here are the additions to the code:

Word.FileConverters converters = wordApp.FileConverters;
var wordPdfConverter = converters.OfType<Word.FileConverter>().Where(c => c.CanOpen == true && c.Extensions == "pdf").First();
var doc = wordApp.Documents.OpenNoRepairDialog(ExternalFilePath, false, true, false, Format: wordPdfConverter.OpenFormat, NoEncodingDialog: true);

This gets a converter but still displays the prompt. :(


Further edit thanks to Cidney's comments. It appear this prompt is a user registry setting as that to bypass it in the interop is impossible. Seems a like a flaw with the Interop to me. The Open XML SDK does not support saving as XPS so this is unavailable too. Appears I will have to manipulate the users registry first to achieve this (brings write permission concerns) or check if Word is waiting for user input and send keys.

来源:https://stackoverflow.com/questions/58435301/c-sharp-word-interop-open-a-pdf-without-the-conversion-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!