none
DOCX to PDF Coverter programmatically RRS feed

  • Question

  • I need to know what options I have to convert .docx to .pdf programmatically.  The catch is that it must work from a build (InvokeProcess from WorkFlow 4.0) and I do not have SharePoint 2010.  I have tried many other's suggestion to Open the file, then Save it as .pdf using ExportAsFixedFormat.  That does not work on the build machine for whatever reason, there is a null reference exception.  It does however, work on a local machine etc fine.  Is there a possiblity of using the

    Open XML Format API?


    Frederick Von Stubenstein
    Monday, January 23, 2012 9:44 PM

All replies

  • Hi Frederick,

    As far as I know, you can use OpenXML SDK and word automation services to do the conversion, for more details, please refer to this blog article and msdn article:

    http://blogs.msdn.com/b/acoat/archive/2011/04/06/document-creation-and-conversion-with-the-openxml-sdk-and-sharepoint-2010-word-automation-services-part-2.aspx

    http://msdn.microsoft.com/en-us/library/ff181518.aspx

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 24, 2012 7:16 AM
  • Hi Frederick,

    As far as I know, you can use OpenXML SDK and word automation services to do the conversion, for more details, please refer to this blog article and msdn article:

    http://blogs.msdn.com/b/acoat/archive/2011/04/06/document-creation-and-conversion-with-the-openxml-sdk-and-sharepoint-2010-word-automation-services-part-2.aspx

    http://msdn.microsoft.com/en-us/library/ff181518.aspx

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    As I said, I do not have SharePoint 2010!

    Frederick Von Stubenstein
    Tuesday, January 24, 2012 1:13 PM
  • hi Frederick,

    I'm using the saveAsFixedFormat (with .NET 4 and Office 2007/2010) without a problem...

    this is my code:

     

     _wordDocument.ExportAsFixedFormat(documentFile, WdExportFormat.wdExportFormatPDF);
    

     

     

    With the openXml SDK you will only be able to modify your docx file but you will NOT be able to convert docx to any other format like PDF.

    You always need word installed or have to use the sharepoint server automation services.

     

    Tobias

    Tuesday, January 24, 2012 1:15 PM
  • Tobias are you using the saveAsFixedFormat in conjunction with a build process though?  It works fine on when i run it locally or manually from command line, but pukes only when part of the build...
    Frederick Von Stubenstein
    Tuesday, January 24, 2012 1:32 PM
  • I'm using a local VSTO plugin.

    What exactly do you mean with "build process"?

    Tuesday, January 24, 2012 1:45 PM
  • I have this program (The .docx to .pdf converter console app i made) in an InvokeProcess activity in WorkFlow 4.0  ie:

    In other words, when a Build is requested, the InvokeProcess calls my Convert Word to PDF program and supplies an argument for what folder to look in.  Whatever files in that folder that end in .docx SHOULD! then be converted into .PDF.  But I get a SystemNullRefreence instead.  Running the same program via command line on the Build machine and supplying the same argument results in the PDFs being created as expected


    Frederick Von Stubenstein

    Tuesday, January 24, 2012 1:56 PM
  • sorry I don't know WorkFlow 4.0. 

    Tuesday, January 24, 2012 2:41 PM
  • some of your description hints that code is executed under account that does not have its profile loaded. Verify (for example using task manager) under what account is your code running when invoked as InvokeProcess.

    Tuesday, January 24, 2012 3:44 PM
  • Account shows tfsservice when invoked under InvokeProcess (the same as I run it manually, which is an administrator)
    Frederick Von Stubenstein
    Tuesday, January 24, 2012 6:14 PM
  • Hi Frederick,

    I found your problem is the same with this one which you asked:

    http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/94f2da6a-1ffd-44d8-9f07-852a4ec14ec8

    Because I am not familiar with Work Flow, I found it difficult to reproduce the scenario as yours on my side, so I will help you involve other experts to help you. Please wait to see whether they can give you some suggestions or hints. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, January 25, 2012 6:27 AM
  • Hi Frederick,

    I found your problem is the same with this one which you asked:

    http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/94f2da6a-1ffd-44d8-9f07-852a4ec14ec8

    Because I am not familiar with Work Flow, I found it difficult to reproduce the scenario as yours on my side, so I will help you involve other experts to help you. Please wait to see whether they can give you some suggestions or hints. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Thanks Bruce i look  forward to a solution!

    Frederick Von Stubenstein
    Wednesday, January 25, 2012 3:50 PM
  • Hello Frederick,

    Do you know where in the program does  it raise the NullReferenceException? You may need to use try…catch blocks to identify where this happens.

    If  your ultimate objective  is to provide your converter to a client who intends  to have the process run in a workflow then your design is not recommended nor supported by Microsoft.  Please reference the Microsoft Knowledge Base article

    257757  Considerations for server-side Automation of Office
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757

    Regards,
    Chris Jensen
    Senior Technical Support Lead


    Chris Jensen
    Wednesday, January 25, 2012 10:55 PM
    Moderator
  • Hi Frederick,

    I found your problem is the same with this one which you asked:

    http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/94f2da6a-1ffd-44d8-9f07-852a4ec14ec8

    Because I am not familiar with Work Flow, I found it difficult to reproduce the scenario as yours on my side, so I will help you involve other experts to help you. Please wait to see whether they can give you some suggestions or hints. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Still no solutions for this?  Bruce?

    Frederick Von Stubenstein
    Monday, February 6, 2012 3:43 PM
  •  

    Hello Frederick,

     

    Do you know where in the program does  it raise the NullReferenceException? You may need to use try…catch blocks to identify where this happens.

    If  your ultimate objective  is to provide your converter to a client who intends  to have the process run in a workflow then your design is not recommended nor supported by Microsoft.  Please reference the Microsoft Knowledge Base article

    257757  Considerations for server-side Automation of Office
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757

    Regards,
    Chris Jensen
    Senior Technical Support Lead

     


    Chris Jensen

    I understand the KB, but I am seeking an alternative solution.  Seems nobody on here can supply with me one at all, I just get responses saying either do it like I am currently or that it can't be done wihotut 3rd party software,

    Frederick Von Stubenstein
    Monday, February 6, 2012 3:54 PM
  • Thanks but I can't really use a trial version and I can't spend $250 just to do this.  The trial sticks "Converted by blah blah blah Trial Version" right into the beginning of the PDF.  That's not what I'm looking for.  I also suspect it just uses the methods I'm already having problems with, since Word is run behind the scenes with your sample code.
    Frederick Von Stubenstein
    Monday, February 6, 2012 4:29 PM