4 hours ago4 hr Convert Office Files in FileMakerWe have a few customers who use document databases to store Word, Excel, PowerPoint, and other documents in a FileMaker database. To preview these documents in a container field, we need to generate a preview image for each document. JPEG, PNG, and a few other image formats can be displayed directly. However, Office documents need to be converted into images, and this requires an application that can correctly handle document layouts, page breaks, and other formatting.That is where we use LibreOffice. It allows us to convert all the given file types:We run in a problem when trying to use LibreOffice on macOS within a script running in FileMaker Server. The application crashed as it tried to initialize the GUI. I reported this asBug 169711: Crash on macOS when running LibreOffice headless via Terminal without GUIThis bug is fixed for the 26.8.0 version.If you have that version copied to your macOS server, you can simply invoke LibreOffice with the Shell functions. Pass the --convert-to parameter with the desired type of pdf. We need the --headless parameter to avoid the GUI to initialize. e.g. you would use a call like this:MBS( "Shell.Execute"; $shell; $appPath; "--convert-to"; "pdf"; "--headless"; "--outdir"; $OutputFolder; $InputFile )The $appPath would be "/Applications/LibreOffice.app/Contents/MacOS/soffice" on macOS, "C:\Program Files\LibreOffice\program\soffice.exe" on Windows and "/usr/bin/soffice" on Linux.You find the example script in the PDFKit Print Documents.fmp12 file.There are a few special things in our example script. First we create a temp folder for both input and output using an UUID for each. This way we never have trouble with duplicate file names in those folders. And whatever file appears later in output file is our result. The use of UUIDs allow this to run in multiple scripts in parallel if needed. We use Container.WriteFile function to write the file into the input folder.The Shell.Execute call passes each parameter as a parameter to the plugin, so the quoting is done right internally. Then the whole thing runs in the background and we wait up to 10 seconds with Shell.Wait function. On return we read any error messages and then look for the PDF file in the output folder.Finally we have to do some cleanup with deleting temp files. In case the process would crash, you may just not get the PDF.Please try the sample file and the sample script to convert your office files to PDF. And do not hesitate to contact us if you have questions.
Create an account or sign in to comment