Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 打开PDFand类型不匹配时出错。(HRESULT的异常:0x80020005(显示类型不匹配))_C#_.net_Visual Studio_Ms Word - Fatal编程技术网

C# 打开PDFand类型不匹配时出错。(HRESULT的异常:0x80020005(显示类型不匹配))

C# 打开PDFand类型不匹配时出错。(HRESULT的异常:0x80020005(显示类型不匹配)),c#,.net,visual-studio,ms-word,C#,.net,Visual Studio,Ms Word,在我将代码从word转换为PDf后,如果我输入相同的word文档转换为PDf,则PDf文件已损坏。你能告诉我这个错误是因为多次输入同一个单词PDf还是其他错误 Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application(); object _MissingValue = System.Reflection.Missing.Value;

在我将代码从word转换为PDf后,如果我输入相同的word文档转换为PDf,则PDf文件已损坏。你能告诉我这个错误是因为多次输入同一个单词PDf还是其他错误

 Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            object _MissingValue = System.Reflection.Missing.Value;

              public void WordtoPdf_Input()
 {
string filename_doc=System.IO.Path.GetFileName(LblFleip.Text);
string wordFileName = LblFleip.Text;
      string pdfFileName=string.Empty;
     appWord.Visible = false;
     appWord.ScreenUpdating = false;

  // Cast as Object for word Open method
  object filename = (object)wordFileName;

  // Use the dummy value as a placeholder for optional arguments
  Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(ref filename, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);
  doc.Activate();

   InputFilename = pdfFileName = Path.ChangeExtension(wordFileName, "pdf");
  object fileFormat = WdSaveFormat.wdFormatPDF;

  // Save document into PDF Format
  doc.SaveAs(ref outputFileName,
   ref fileFormat, ref _MissingValue, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
   ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);

  // Close the Word document, but leave the Word application open.
  // doc has to be cast to type _Document so that it will find the
  // correct Close method.    
  object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
  ((_Document)doc).Close(ref saveChanges, ref _MissingValue, ref _MissingValue);
  doc = null;

  // word has to be cast to type _Application so that it will find
  // the correct Quit method.
  ((_Application)appWord).Quit(ref _MissingValue, ref _MissingValue, ref _MissingValue);
  appWord = null;
    }
我犯了一个错误。这就是我使用itextsharp将word转换为pdf并阅读页面的方式。

尝试以下代码:

        string tEmpName= Path.GetTempFileName();
        File.Delete(tmpName.ToString()); 
        File.Delete(Filename);
        File.Move(tEmpName, Filename);