locked
How can i convert word to pdf on asp.net server RRS feed

  • Question

  • User615971635 posted

    I am getting the following error while using the Interop word dll for converting the Word to PDF.

    Hide   Copy Code
    Error Converting DOC To PDF12066_Parameter.docx Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).


    Please suggest solutions ASAP.

    What I have tried:

    string strFileName = "";
    strFileName = fuSrc.PostedFile.FileName.ToString();
    Application appWord = new Application();
    Document wordDocument = appWord.Documents.Open(strFileName);
    txtDst.Text = strFileName.Replace(".docx", ".pdf").Replace(".doc", ".pdf");
    try
    {
    wordDocument.ExportAsFixedFormat(txtDst.Text, WdExportFormat.wdExportFormatPDF);
    lblErr.Text="Converted Successfully";
    }
    catch (Exception ex)
    {
    lblErr.Text=ex.Message.ToString();
    }

    Wednesday, June 1, 2016 2:25 PM

Answers

  • User-821857111 posted

    You probably need to provide permission to the user account to invoke DCOM components on the server: http://stackoverflow.com/questions/3477086/accessing-office-word-object-model-through-asp-net-results-in-failed-due-to-the. This means having access to the Component Services management tool on the server, which is only really possible if you have control over the server, or control over someone else who does...

    Note: The use of Word/Office Interop in an ASP.NET application is not supported and indeed, advised against by Microsoft. If you don't have access to the server (e.g. because you have a shared hosting package) you will have to find an alternative means to generate your PDF files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 3:54 PM

All replies

  • User-821857111 posted

    You probably need to provide permission to the user account to invoke DCOM components on the server: http://stackoverflow.com/questions/3477086/accessing-office-word-object-model-through-asp-net-results-in-failed-due-to-the. This means having access to the Component Services management tool on the server, which is only really possible if you have control over the server, or control over someone else who does...

    Note: The use of Word/Office Interop in an ASP.NET application is not supported and indeed, advised against by Microsoft. If you don't have access to the server (e.g. because you have a shared hosting package) you will have to find an alternative means to generate your PDF files.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 3:54 PM
  • User1708713926 posted

    As mike suggested, Office interop is not a good option for server. Generally, Microsoft will suggest to use Open XML, but conversion is not a part of Open XML SDK. I would suggest you to find other alternative ways(third-party libraries). e.g. http://freeword.codeplex.com It do not require to install MS Office, but this free version has some limitations.

    Friday, June 3, 2016 5:43 AM