web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Convert Word document to PDF file

(0) ShareShare
ReportReport
Posted on by 4,075

I need a way to convert a word document into a PDF file, in AX.

And I found this bit of code that works when i run it on the client, but fails when run on server.

private void Word2Pdf(Filename _fileName, fileName _newFile)

{
    COM     wordApplication;
    COM     wordDocuments;
    COM     wordDocument;
    COM     wordRange;

    try
    {
        new InteropPermission(InteropKind::ComInterop).assert();
        wordApplication = new COM("word.application");
        wordApplication.visible(TRUE);
        wordDocuments = wordApplication.Documents();
        wordDocument = wordDocuments.add(_fileName);

        wordDocument.saveas(_newFile,17);
        wordDocument.saved(true);
        wordDocument.close();
        wordApplication.quit();
    }
    catch
    {
        throw error("Unknown ClrError");
    }
}


I get this error when this code runs on server:

Method 'add' in COM object of class 'Documents' returned error code 0x800A13E9 (<unknown>) which means: Error found in word.

Does anyone know how to fix this, or perhaps someone has another way to convert word to pdf.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    This would require Word installed on server and it's not recommender nor supported by Microsoft.

    There are several third-party libraries that you could use for this purpose (without installing Word). I don't have experience with any of them.

  • Rudi Hansen Profile Picture
    4,075 on at

    Does anyone have a rekommandation to with library to use?

  • Community Member Profile Picture
    on at

    Did you find a solution to your problem? I am facing the same issue. It works fine on Devbox. However, on production server it is giving an error.

    I used XMLworddocument class to solve the com object problem. But couldn't find a way to convert it to PDF. Even tried using Microsoft.office.interop.word reference but with no success. Any help would be highly appreciated. 

  • Rudi Hansen Profile Picture
    4,075 on at

    No sorry newer got this one solved, seemed that there was always a problem with running the code on the server.

  • Suggested answer
    Sumeet Kaushal Profile Picture
    40 on at

    Hi,

    I have achieved this by using XMLWordCocument class present in D365 instead of using COM and By creating DLL(You can buy or look for a free one) Which converts Word to PDF and It works even if word is not installed.

     

    Regards,

    Sumeet

  • Rudi Hansen Profile Picture
    4,075 on at

    Did you move the XMLWordCocument class to AX2012?

    And witch DLL did you use?

  • Verified answer
    Sumeet Kaushal Profile Picture
    40 on at

    It was XMLWordDocument (Typo). No I have not moved it to AX 2012. It was meant for D365 only i guess.

    Related to DLL it was spire.Doc.(One is free and one is paid) you can check in the class libraries.

  • Rudi Hansen Profile Picture
    4,075 on at

    Ok well the biggest problem I had was finding a DLL that could do the conversion without word installed, so this might solve that problem, so thanks.

  • Imthiyaz Mohammed Profile Picture
    50 on at

    Hi Mr. Sumeet,

       Is it possible for you share the code on how used XMLWordDocument class in D365 to save the word document to pdf. I am working on similar requirement.

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    XMLWordDocument utilizes Open XML SDK (see WordprocessingDocument class). I don't see any PDF-related logic in XMLWordDocument; that's for Sumeet to answer. I'm also not aware of Open XML SDK having such a capability, although it may be just a lack of knowledge on my side.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans