1 2 Previous Next 15 Replies Latest reply on Mar 27, 2017 12:08 PM by philmodjunk

    print multipage PDF's from Container fields in a batch sequence

    AnthonyTesoriero

      Title

      print multipage PDF's from Container fields in a batch sequence

      Post

           We need a script that will print a multipage PDF within a printing sequence from filemaker pro.
            
           We use a filemaker PRO database that is rough around the edges but general works for our processes. We are trying to automate some workflows but continue to run into gaping glitches that have stumped us and held back our productivity with this application. 
            
           It appears that filemaker is unable to print multipage PDF's that are stored in it's container fields. Further complicating the mater filemaker pro for mac has a frequent problem crashing on larger files when using Adobe as the default web plugin to view PDF files, thereby making it necessary to default to using "preview" for mac as the default reader. 
            
           The problem with using preview though is that when certain documents were created originally using acrobat such as forms or PDFs with embedded pics, Preview will fail to recognize the data on the forms or the embedded pics thereby rendering a blank page, making its necessary to use Acrobat only to print the documents...
            
           Our solution requires us to batch print large amounts of documents from found sets within our database.
            
           Each record has a series of layouts that must be printed in a specific order and a collection of attachments (container fields) that must also be printed.
            
           Currently we are able to batch print all the filemaker layout documents in the proper sequential order for a batch, (Average 20 records per batch, each record having 10 pages = 200 Pages (without corresponding attachments) 
            
            Because of filemaker's limitations however we must then manually go into each record, open each relevant attachment, right click to "open as" Adobe PDF, execute a print command, manually close the adobe window, manually close the filemaker container window and repeat for each relevant attachment per record.... As you can imagine this becomes very time consuming. 
            
           To make matters more complicated we then have to hand collate the documents to insert the separately printed container PDF's and associate them with the other printed docs...
            
           We are trying to create scripting that will enable us to print the entire file in the proper sequential order so that it is pre collated.  (i.e. Print 5 layouts, print container 1, print 3 layouts, print container 2, print 2 layouts, print containers 3 and 4) move to next record repeat...
            
           I believe one way to solve this is to export the PDF from the container field to a watch folder that would have an applescript attached to it and automatically print.. However I have been unsuccessful in figuring out how to script a hot folder to print using the adobe engine.
            
           I have made hot folders that print using the default preview engine however this results in a blank document. These documents only seem to print correctly when printed from the print dialog of adobe reader or acrobat alone.
            
           I am open to any suggestions at this point...
            

        • 1. Re: print multipage PDF's from Container fields in a batch sequence
          philmodjunk
               

                    It appears that filemaker is unable to print multipage PDF's that are stored in it's container fields

               That is correct. It may be possible to do so via a system script (such as AppleScript) performed by FileMaker, however.

               

                    making it necessary to default to using "preview" for mac as the default reader.

               This is a known issue:

               For More Information see:     Records with a PDF file linked to an active container field cause FMP 12 to crash in OS 10.9

               This is one of many acknowledged bugs that can be found in the Known Bug List thread here in the Report an Issue section of the forum.

               It can also be downloaded as a database file from:    https://www.dropbox.com/s/jt09b82i0xijbu3/FMP%20Bugs.zip

               I'm not a Mac user and thus am unable to help you with an Applescript.

          • 2. Re: print multipage PDF's from Container fields in a batch sequence
            philmodjunk

                 One question: Are you using FileMaker 12 or some other version of FileMaker?

            • 4. Re: print multipage PDF's from Container fields in a batch sequence
              philmodjunk

                   Can you confirm that you still have to use Preview in FileMaker 13?

                   My bug report database logged the issue when FileMaker 12 was the current version and I would like to update the report to include FileMaker 13 if this issue still occurs.

              • 5. Re: print multipage PDF's from Container fields in a batch sequence
                AnthonyTesoriero

                     Yes, sadly it is still occurs in Filemaker Pro Advanced 13..

                • 6. Re: print multipage PDF's from Container fields in a batch sequence
                  AnthonyTesoriero

                       Phil,

                       Just a thought... Would it be possible to export all the documents associated with a record to a single multipage PDF using the append PDF command in a script then loop through each of the records in the found set until complete? Thereby effectively creating 10 large multipage PDFs with all of the layouts collated correctly with the multipage PDFs exported from the container fields.....

                       Then those PDF's could be moved to a hot folder which would print them using the ADOBE Engine?

                       Does it sound like it will work?

                       Do you have any suggestions on how to write that?

                        

                  • 7. Re: print multipage PDF's from Container fields in a batch sequence
                    philmodjunk

                         Thanks for the confirmation. I'll update the Known Bugs List accordingly. (Appeal to all who are reading this thread, I welcome community participation in checking old bug reports to see if they still occur in the latest versions. As I get confirmation that a bug has been fixed in the latest release, I can then "close" the report in this database and post a message on this in the relevant forum threads.)

                         Are you generating the PDF's from FileMaker layouts? If so, then yes Save As PDF with the append option can append the pages generated from the current save to an existing PDF. So this limits you to only one portion of your PDF that can come from other sources than FileMaker. Each appended PDF will start on a new page.

                         I really can't post much for a script as it will vary with the design of your database and the criteria you need to use to find and sort records for each layout.

                         The script becomes a series of a) go to layout, b) pull up records c) sort them d) save as PDF, this could be a linear series of script steps or possibly in a loop in some cases.

                    • 8. Re: print multipage PDF's from Container fields in a batch sequence
                      AnthonyTesoriero

                           Well I was able to cull together info from this and some other boards to create an applescript that will print the PDFs using Acrobat from a folder.

                           I have already created a script that finds the Related attachments and exports them to the desktop.

                           What I'm having trouble with is merging the two.

                           I need to export the PDF to a folder or temporary place and trigger the apple script to initiate the printing...

                            

                           My FM Scripting is attached in an image:

                            

                           This is my apple script: 

                            

                      setmyFolderto (path todesktop folderastext) & "Print:"

                            

                      set myfiles to list folder myFolder without invisibles

                            

                      repeatwithmyfileinmyfiles

                            

                      setmycurrentfileto ((myFolderasstring) & (myfileasstring)) asstring

                           batchprint(mycurrentfile)

                            

                      endrepeat

                            

                      on batchprint(mycurrentfile)

                            

                      tellapplication "Adobe Acrobat Pro"

                      activate -- bring up acrobat

                      open alias mycurrentfile -- acrobat opens that new file    

                      tellapplication "System Events"

                      tellprocess "Acrobat"

                      clickmenu item "Print..." ofmenu 1 ofmenu bar item "File" ofmenu bar 1

                      clickbutton "Print" ofwindow "Print"

                      tellapplication "System Events"

                      tellprocess "Acrobat"

                      click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1

                      endtell

                      endtell

                      endtell

                      endtell

                      endtell

                            

                      tell application "Finder" -- to move the printed file out 

                      setxto ((path todesktop folderastext) & "Printed PDFs:")

                      ifaliasxexiststhen

                      beep

                      else

                      makenewfolderatthedesktopwith properties {name:"Printed PDFs"}

                      endif

                      movealiasmycurrentfiletofolder "Printed PDFs"

                      endtell

                      end batchprint

                           I read this suggestion on another board but can't figure out how to implement...

                             
                      •           Calculate the location to export by appending the filename to Get( TemporaryPath ).
                      •      
                      •           Export the container field contents to FileMaker to that path.
                      •      
                      •           Save the path to a global field in FileMaker
                      •      
                      •           Use an embedded AppleScript to access the global field path
                      •      
                      •           Use AppleScript to open the file in Preview and print it

                            

                      • 10. Re: print multipage PDF's from Container fields in a batch sequence
                        ssgiles

                        In case you or anyone else is still interested in this topic, I needed to find a better way to streamline and loop the concatenation of PDFs (totaling hundreds of pages) exported from multiple containers. I found that OS X has a Python script installed by default (in /System/Library/Automator), which simplifies the AppleScript and makes Acrobat unnecessary. The AppleScript is simple, and the only difficulty is wrapping your head around writing a shell command (Python) with the parameters of AppleScript, and that all from the perspective of FileMaker. Unlike other solutions, this makes possible the concatenation of PDFs from any number/combination of PDFs in any order! Here's my AppleScript:

                        global outputFile
                        set outputFile to (path to desktop) & "NameOfFinalFile.pdf" as string
                        set fileOne to (path to desktop) & "WhateverYouDefinedIn$$DesktopPath.pdf" as string
                        set fileTwo to (path to desktop) & "WhateverYouDefinedIn$$DesktopPath2.pdf" as string

                        global TempFolderPath
                        tell application "Finder"
                            make new folder at (path to desktop) with properties {name:"FileMakerTemp"}
                            set TempFolderPath to (path to desktop as string) & "FileMakerTemp:"
                            move file fileOne to TempFolderPath
                            move file fileTwo to TempFolderPath
                        end tell

                        set inputOne to TempFolderPath & "WhateverYouDefinedIn$$DesktopPath.pdf" as string
                        set inputTwo to TempFolderPath & "WhateverYouDefinedIn$$DesktopPath2.pdf" as string

                        do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of outputFile & " " & quoted form of POSIX path of inputOne & " " & quoted form of POSIX path of inputTwo

                        tell application "Finder"
                             delete folder TempFolderPath
                        end tell

                        This is actually the first topic in a FileMaker blog I just started on my website, in case you want a more detailed explanation as well as text of the FileMaker script I used: http://samuel.giles.global/export-multi-page-pdf-from-container-and-combine-pdf-with-records-printed-to-pdf-with-applescript/ 

                        • 11. Re: print multipage PDF's from Container fields in a batch sequence
                          AnthonyTesoriero

                          Wow... Thank you for taking the time to provide this answer and your work... I've been wrestling with this for a long time... I'm excited to try out the script and will follow your blog..

                          Cheers..

                          • 12. Re: print multipage PDF's from Container fields in a batch sequence
                            AnthonyTesoriero

                            Samuel

                            Thank you for posting this code and contributing to the filemaker community in the forums. I made the original post in the forum and have been looking to solve this for a long time. Would you be willing to create a small FMP test file using your code example and post/send.

                            I’m having a difficult time implementing your solution as is, but hoping if I can follow a working example it will be easier to implement.

                            Best regards,

                            Anthony

                            • 13. Re: print multipage PDF's from Container fields in a batch sequence
                              ssgiles

                              Hi, no problem. Just replied to your question on my blog post. For anyone else following and having a problem, tripple-check file names. That's really the only place you can go wrong. The AppleScript can otherwise be copy/pasted. Also, the FileMaker script must run with full access privileges. Let me know if you're still having trouble. 

                              • 14. Re: print multipage PDF's from Container fields in a batch sequence
                                sampozzanick

                                Hi, checking in here in year 2017 with Filemaker Advanced 14 (I could go to 15 if necessary.)

                                 

                                Is all of the above scripting, etc. still the only, or best, way to handle printing out multi-page PDFs (sourced from different PDF files outside filemaker)?

                                 

                                Or have new features & functionality superseded this in some way?

                                 

                                I appreciate your work and your follow-up!

                                1 2 Previous Next