Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Convert Word document to PDF file

Posted on by 3,987

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

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: Convert Word document to PDF file

    Hi all,

    Can anybody share the code related to xmlworddocument classin d365. i'm having a similar requirement converting word to pdf.

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Convert Word document to PDF file

    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.

  • RE: Convert Word document to PDF file

    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.

  • Rudi Hansen Profile Picture
    Rudi Hansen 3,987 on at
    RE: Convert Word document to PDF file

    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.

  • Verified answer
    Sumeet Kaushal Profile Picture
    Sumeet Kaushal 40 on at
    RE: Convert Word document to PDF file

    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
    Rudi Hansen 3,987 on at
    RE: Convert Word document to PDF file

    Did you move the XMLWordCocument class to AX2012?

    And witch DLL did you use?

  • Suggested answer
    Sumeet Kaushal Profile Picture
    Sumeet Kaushal 40 on at
    RE: Convert Word document to PDF file

    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
    Rudi Hansen 3,987 on at
    RE: Convert Word document to PDF file

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Convert Word document to PDF file

    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
    Rudi Hansen 3,987 on at
    RE: Convert Word document to PDF file

    Does anyone have a rekommandation to with library to use?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans