【问题标题】:Word to PDf converted PDF is having error -access denied errorWord 到 PDf 转换的 PDF 出现错误 - 访问被拒绝错误
【发布时间】:2013-07-19 10:28:10
【问题描述】:

将 MS Word 文档转换为 PDF 后。如果我将转换后的单词的相同路径发送到 pdf。即 PDF 。在文件提取时,我会在服务器中发布网站时收到拒绝访问的错误。它在本地机器上工作。我在代码中留下了什么或者我需要安装什么。

 public string WordtoPdf_Input(string wordFileName_input)
    {

        try
        {

            Microsoft.Office.Interop.Word.Application appWord_input = new Microsoft.Office.Interop.Word.Application();
            object _MissingValue_ip = System.Reflection.Missing.Value;
            //filename_doc = System.IO.Path.GetFileName(LblFleip.Text);
            //wordFileName = LblFleip.Text;
            string pdfFileName = string.Empty;
            appWord_input.Visible = false;
            appWord_input.ScreenUpdating = false;

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

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

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

            //All is well until here, Save thinks the excelfile is readonly
            object tmpName = Path.GetTempFileName();

            File.Delete(tmpName.ToString());

            // Save document into PDF Format
            doc.SaveAs(ref tmpName,
             ref fileFormat, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip,
             ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);

            // 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_ip, ref _MissingValue_ip);
            doc = null;

            // word has to be cast to type _Application so that it will find
            // the correct Quit method.
            ((_Application)appWord_input).Quit(ref _MissingValue_ip, ref _MissingValue_ip, ref _MissingValue_ip);
            appWord_input = null;


            File.Delete(InputFilename.ToString());

            File.Move(tmpName.ToString(), InputFilename.ToString());
            //File.Move(tmpName,InputFilename.ToString())
            filePath_input = InputFilename.ToString();


            GC.Collect();
            GC.WaitForPendingFinalizers();

        }


        catch (Exception ex)
        {

        }
        finally
        {
            GC.Collect();  // force final cleanup!
            GC.WaitForPendingFinalizers();
        }
        return filePath_input;
    }

Public void PDFnumofPagecount()
{
 LblFleip.Text = filePath_input;





                PdfReader readerPages_ip = new PdfReader(LblFleip.Text);
  NumberofPages_ip = readerPages_ip.NumberOfPages;
                txtbNumberofPages_ip.Text = NumberofPages_ip.ToString();
                readerPages_ip.Close();

}

i have used itextsharp for reading pages and extraction of PDF

【问题讨论】:

  • 你能贴出异常的stacktrace吗?

标签: c# pdf ms-word itextsharp


【解决方案1】:

您是否在出错的机器上检查了用户的权限(以确保他们具有所需的读/写权限)?

【讨论】:

  • 我不明白为什么这个答案被否决了。我赞成它,因为它是一个很好的反问题(但也许它应该作为评论添加)。我很确定“拒绝访问”警告与权限有关。文件被锁定,或者网络服务器以无权访问文件的用户身份运行。
  • 谢谢布鲁诺。 :) 我想发表评论,但由于没有足够的声誉而无法发表评论!所以,不得不这样做作为一个答案......
  • 我已经更改了服务器。具有相同权限现在它工作正常。另一台服务器上的相同权限不起作用。
猜你喜欢
  • 2014-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 2012-12-21
  • 2010-12-23
  • 2017-06-25
相关资源
最近更新 更多