13 Replies Latest reply on Feb 23, 2012 8:04 AM by dickiedyce

    Converting stored Word docs to PDF

    dickiedyce

      Here's an odd one for you. I have a document management system for building proposals. Proposals consist of filemaker data (quotes), word documents, merged documents (printed FileMaker layouts), and imported pdfs. The aim is to be able to produce a single stipped together PDF at the end for emailing. I have everything working ... except conversion of stored Word docs to PDF. It's an XP/Win7 environment and I need to be able to convert the stored Word Docs (and possibly Excel docs?) into PDFs via a script. The documents do need to be stored in Word - it's a client requirement that they can be edited as such (and I'm already handling the versioning in FMPRo.)

       

      What is the simplest way of doing this in Windows from FileMaker? Ideally some sort of system call, without the need to install non-oss third party apps. Any ideas?

        • 1. Re: Converting stored Word docs to PDF
          LSNOVER

          Dickie:

           

          As far as I know, there is no mechanism to convert a Word document to a PDF in the scope of just Filemaker.  I'd suggesting having a look at an Open Source PDF "printer", called "Bullzip", which will allow you to print and save your Word documents as PDF documents.  You will probably have to write some OS level macros in VBScript to get it all working, but it can be done.  There may be a way of bulk processing multiple documents, but I haven't explored that as of yet.

           

          Regards,

          Lee

          • 2. Re: Converting stored Word docs to PDF
            dickiedyce

            Lee,

             

            Yes thanks for that. I had a few thoughts in that direction, and had made some progress, although not via printing: MS actually make an update for office ('SaveAsPDFandXPS.exe') that let's you save to PDF (rather than have to select a print driver). I have a VBScript that does work, but the procedure is rather convoluted: ensure that the extension is installed on each user's machine, then each time export the VBscript to the user's temp folder, export the word doc, run the vbscript, and then import the pdf.

             

            [ I know it's been said before, but it really is easier/simpler/cheaper on Mac ;-) ]

            • 3. Re: Converting stored Word docs to PDF
              LSNOVER

              Dickie:

               

              Right you are.  It's a PITA.  lol.  Mac are Macs and Window is Windows, we just have to deal.  ;-)   No magic solution I'm afraid.  I didn't know Microsoft had a plug in.  Is that a free tool?

               

              Regards,

              Lee

              • 4. Re: Converting stored Word docs to PDF
                dickiedyce

                Yup, free as in beer.

                 

                http://www.microsoft.com/download/en/details.aspx?id=7

                 

                should you want to have a look.

                 

                I'll paste the calc for doing the VBS once I'm happy...

                • 5. Re: Converting stored Word docs to PDF
                  jrenfrew

                  What about using AutoIt to automate the process

                  Its a Win scripting tool which creates an exe which can be run with passed parameters

                  http://www.autoitscript.com/site/autoit/

                  Not simple, but relatively easy to pick up, and very powerful.

                   

                  In FM

                  Export the docX to a known location with a known name

                  Pause script

                   

                  Previously create an AutoIt script with:

                  Open it ( passing filename and newname)

                  Do the SaveAsPDFandXPS menu commands, writing in new name to the save dialog box

                  Pause till ready

                  Switch focus back to FM

                  Select contine button to resume script

                   

                  Then carry on

                   

                  You now know what it is and where it is so then use Scriptmaster and iText to concatenate the PDF file to the one you savedAs earlier

                  If you are really clever you can put the Word PDF into the middle of the original document.

                  • 6. Re: Converting stored Word docs to PDF
                    dickiedyce

                    Not that clever - I may have mentioned that I have everything else working ;-) Indeed, I have had a Scripatmaster/iText-based system for assembling short-term teaching contracts in place at two other clients for a couple of years now (on XP and OSX). They use pre-existing PDFs (stored in container fields, not SuperContainer but same principle) that are selected based on teaching position, location, class size etc.

                     

                    No, what would be 'really clever' would be getting Word to quit cleanly post-process.

                     

                    I have a solution working (toy version attached), which does work, but not repeatably: occasionally (15-20% of the time) fails to quit cleanly so that the next time the process occurs I get a "can't find convert" error from Word. At the moment the processing is manually driven, but I would like it to be automated so I need that 100% reliability. (The idea is that the existing SuperContainer-based versioning system also updates the processed PDF every time that a new version of the document is added to the db. Right now, the client 'edits' an existing document component (word or excel doc), SuperContainer downloads it to the temp folder, launches it via URL and the client then edits in the appropriate office app. They then close and save the document, and on return to FileMaker choose to update or discard the changes to the doc. If they accept, we update the rev, upload the document. At this point I want to run the VB script to get word to re-open and PDF the document using the SaveAsPDForXPS tool installed in office, and then store the PDF alongside the versions of the doc via SuperContainer: this makes concatenating them a simpler task than having to create PDFs on the fly for the contcatenating process, and storage is not an issue.)

                     

                    AutoIT sounds intriguing! From the way you describe it, it sounds more like a macro tool, which although may not appear as seamless to the client as a VB Script, but may be more robust. I shall give it a go. Thanks.

                    • 7. Re: Converting stored Word docs to PDF
                      dickiedyce

                      It's just struck me - that perhaps I'm looking at it from the wrong end. I'm now investigating whether it's possible to add an OnSave macro to Word/Excel to check (based on name) if the document needs to be PDF'd as well as saved. That way I can avoid the timing issues - FileMaker can 'assume' that a PDF exists if the client clicks the Update button. At least that's the theory ;-)

                      • 8. Re: Converting stored Word docs to PDF
                        dickiedyce

                        OK, I seem to have it working. Granted this is not directly FMPro related, but may be of use to someone later on. The advantage for doing it this way is that FileMaker can assume that the PDF exists (although, yeah, should probably test for it ;-) ) during the version update script.

                         

                        Here's a the VBA macro for Word which saves the PDF when the filename contains _fmpro_temp:

                         

                         

                        Sub FileSave()
                        '
                        ' FileSave Macro
                        '
                            
                            ActiveDocument.Save
                                    
                            Dim StrFile As String
                            Dim StrPath As String
                            Dim StrName As String
                            Dim StrPDFName As String
                            
                            StrPath = ActiveDocument.Path 'Get document path
                            StrFile = ActiveDocument.Name 'Get document name
                                
                            If InStr(StrFile, "_fmpro_temp") Then
                        
                                If InStr(StrFile, ".") Then
                                    StrName = Left(StrFile, (InStr(StrFile, ".") - 1))
                                Else
                                    StrName = StrFile
                                End If
                            
                                StrPDFName = StrPath + "\" + StrName + ".pdf"
                        
                                ActiveDocument.ExportAsFixedFormat OutputFileName:=StrPDFName, _
                                    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
                                    OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
                                    Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
                                    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
                                    BitmapMissingFonts:=True, UseISO19005_1:=False
                                
                                MsgBox "'" + StrName + "' has been saved. " & vbNewLine & vbNewLine & _
                                    "If you're finished, please close the file," & vbNewLine & _
                                    "and return to FileMaker to accept or discard this version.", _
                                    vbInformation, "FileMaker Pro Versioning"
                            
                            End If
                            
                        End Sub
                        

                         

                        End Sub

                        • 9. Re: Converting stored Word docs to PDF
                          dickiedyce

                          For completeness, attached the solution file including .dotm addin thingy ;-)

                          • 10. Re: Converting stored Word docs to PDF
                            LSNOVER

                            Glad you found a way around the issue.  Thanks for posting the VBScript and info. on the EXE creator.

                            • 11. Re: Converting stored Word docs to PDF
                              sporobolus

                              on 2012-02-13 04:56 dickiedyce wrote

                              Here's an odd one for you. I have a document management system for building proposals. Proposals consist of filemaker data (quotes), word documents, merged documents (printed FileMaker layouts), and imported pdfs. The aim is to be able to produce a single stipped together PDF at the end for emailing. I have everything working ... except conversion of stored Word docs to PDF. It's an XP/Win7 environment and I need to be able to convert the stored Word Docs (and possibly Excel docs?) into PDFs via a script. The documents do need to be stored in Word - it's a client requirement that they can be edited as such (and I'm already handling the versioning in FMPRo.)

                               

                              What is the simplest way of doing this in Windows from FileMaker? Ideally some sort of system call, without the need to install non-oss third party apps. Any ideas?

                               

                              i have not done it, but i understand one can use XSL to convert Word (at least

                              .docx) to PDF; this suggest that the conversion could be done without having to

                              launch Word, and it might even be possible to rig a FileMaker XML export to do

                              the transform ...

                               

                              a search on terms such as >XSL convert Word to PDF< should give you a good start

                              • 12. Re: Converting stored Word docs to PDF
                                jrenfrew

                                There is a way with Scriptmaster and the jodconvertor library

                                You need to have Open Office installed but it works well with .doc and docx files

                                Have tested on Windows, but shoudl therefore work just as well on Mac

                                 

                                http://code.google.com/jodconvertor

                                 

                                 

                                // DocxToPDF ( fm_fileIn ; fm_fileOut ; officeHome )

                                // 12_02_22 JR

                                // v1.0

                                //

                                // http://code.google.com/p/jodconverter/

                                // requires all jar files from download to be loaded

                                 

                                import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration

                                import org.artofsolving.jodconverter.OfficeDocumentConverter

                                 

                                officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome(officeHome).buildOfficeManager()

                                officeManager.start()

                                converter = new OfficeDocumentConverter(officeManager)

                                try{

                                converter.convert(new File(fm_fileIn), new File(fm_fileOut))

                                result = ''

                                } catch (e){result = e.getMessage()}

                                officeManager.stop()

                                if(result) {

                                return result

                                } else {

                                return true

                                }

                                1 of 1 people found this helpful
                                • 13. Re: Converting stored Word docs to PDF
                                  dickiedyce

                                  Yeah, I looked at that method too - although I was trying to use http://www.dancrintea.ro/doc-to-pdf/  - but the client won't wear installing open office on their PCs. Religious issue, as it turns out!

                                   

                                  However, it may be possible to persuade them to run a single copy on the server, and use it as a service. I guess this is what (http://www.docmosis.com) is doing ;-)

                                   

                                  There is also a Davisor (http://www.davisor.com/offisor/) which claims to have a Java clibrary for converting doc and xls (not docx and xlsx) to XML, and then on to PDF. I'm investigating that now.