1 2 Previous Next 18 Replies Latest reply on Jan 10, 2017 11:43 AM by JackRodges

    need script to autosave and name .pdf reports

    EricaJackson

      Title

      need script to autosave and name .pdf reports

      Post

           Hi

           I can’t seem to master the script writing task. I need a script that would

           1) take me from the main layout to the report,

           2) save the current record as a .pdf to a desktop filefolder  (name to match the date of visit)

           would it be possible to only save the pages of the report that contain data in the body of the report? I have several sliding text fields so the format is 8 pages long but usually need only 4 condensed pages to actually print)

           3) automatically name the pdf with the client’s name and date of the visit

           I have the parent table as the Client table and then have a one to many with the Visit Table

           Thanks for this help and all of the help on previous posts!

           Erica

            

        • 1. Re: need script to autosave and name .pdf reports
          philmodjunk

               To start, see this thread: Found Sets to PDF with unique file names

               This covers the basics on how to use the save as PDF script step.

               

                    would it be possible to only save the pages of the report that contain data in the body of the report?

               That would depend on the design of your layout and the table or tables that contain the data displayed on that layout. You can certainly limit the found set to only a specific set of records and then save As PDF (sliding works the same for PDFs as it does printing and preview), but whether that will do what you need is not a question I can answer at this point as I don't know the needed details.

               Please Note that Filemaker Scripts alone cannot create new Folders on your computer. That requires creating a system script such as AppleScript or a BatchFile or you have to acquire a plug in that can create folders for you should this be something that you need.

          • 2. Re: need script to autosave and name .pdf reports
            EricaJackson

                  

                             would it be possible to only save the pages of the report that contain data in the body of the report?

                  That would depend on the design of your layout

                 The layout is very basic, just a header, body and footer.  No sub summaries or anything else.

            and the table or tables that contain the data displayed on that layout.

                 See the screen shot, I have the current layout based on the Visits table

            You can certainly limit the found set to only a specific set of records and then save As PDF

                 I want each Visit Record for the particular client saved individually. So the one record I am dealing with at that moment when I complete that visit. I don’t think I need a “found set” but maybe I’m not understanding

                 Do I call this the “current record being browsed?” I’m not sure how to translate this into FM language.

            (sliding works the same for PDFs as it does printing and preview), but whether that will do what you need is not a question I can answer at this point as I don't know the needed details.

                 How do I format the .pdf to slide? I know how to get the fields to slide, I tried to highlight the Body and the footer labels to make them slide but didn’t figure it out…

            Please Note that Filemaker Scripts alone cannot create new Folders on your computer. That requires creating a system script such as AppleScript or a BatchFile or you have to acquire a plug in that can create folders for you should this be something that you need.

                 I have a folder on the desktop for this…named “saved Pdfs”  I don’t think I want to tackle system scripts, this other stuff is intimidating enough, lol.

                 Ok so here goes….

                 I copied this from the thread you sent: 

            The way I have done it is to define a variable  $filename  using the field you want to make the filename for the calculation.  i.e.  filenamefile & ".pdf" 

                 I created text calc field on the VISITS table that includes the Last name of the client and the visit date  and named it  NameDate  So translating that would look like this?

                 $NameDate

                 NameDate & “.pdf”  and these are the things entered into the “set variable” options?

                  

             The have the script do the save file, print to pdf or export as pdf using your variable for the file name.   You will also have to give it a file path to put the file into, which can be another variable that you define as well or a set path if they will always go into the same folder.

                 I’m pretty sure that I don’t have the correct file path…  Is file/win referring to windows and would it look like this?: 

                 C:\Users\EJackson\Desktop\Saved pdfs

                 I am getting “invalid error messages with the  “set variable”  so I’m not sure if I’m on the right track or not.

            • 3. Re: need script to autosave and name .pdf reports
              EricaJackson
              /files/ff5dfbbee0/Capture_1_ej.PNG 889x466
              • 4. Re: need script to autosave and name .pdf reports
                EricaJackson
                /files/323b4320a1/Capture_2_ej.PNG 1280x421
                • 5. Re: need script to autosave and name .pdf reports
                  philmodjunk

                       Quoting from the thread I recommended, you need these script steps:

                       Set Variable [ $Path ; Value:  "file:" & Get ( DesktopPath ) & YourTable::FileNameField & ".PDF"]
                       Save Records as PDF [Restore; no dialog ; "$Path" ; //specify the other options you need for your script here]

                       Modifying it to fit what you describe produces:

                       Set Variable [ $Path ; Value:  "file:" & Get ( DesktopPath ) & “/saved Pdfs/” & Visit::NameDate & ".PDF"]
                       Save Records as PDF [Restore; no dialog ; "$Path" ; //specify the other options you need for your script here]

                       This assumes that NameDate produces text that makes for a valid file name. you can't have "/" be a character in a file's name so you may need to do something such as: Substitute ( NameDate ; "/" ; "_" ) in order to get only valid filename characters.

                       WIth regards to Sliding, I suggest you look up this term in FileMaker help. You can select object on a layout and set them to slide--a change only visible when printing, saving as PDF or previewing and you cannot set a layout part such as a header or body to "slide".

                       I can't really suggest much more in this part of your question without seeing the layout from which you are saving your PDF.

                  • 6. Re: need script to autosave and name .pdf reports
                    schamblee

                         Here is a sample app.  This sample requires a folder on the desktop called pdf. This sample uses the same suggestions as Phil made above. 

                         The sample doesn't address the sliding.

                    https://www.sugarsync.com/pf/D9559058_790_726417096

                          

                    • 7. Re: need script to autosave and name .pdf reports
                      EricaJackson

                           Phil, you have the patience of a Saint! Thank you so much. I did need to make another field with the substitution for the date and it works fine fro the report(s) . You are always thinking ahead.

                           I did look in FM help regarding the sliding features, at first glance it reads that the body part of the layout will slide but I think they mean only that the fields within the body part will slide.  So that's ok. the only problem is that when the .pdf is saved, all 8 pages are saved even the blank ones and when I do go to print them I will need to be mindful of the actual number of pages of each one. Kind of a bother. Is there any way The script could be written so that FM could "preview" the document, count or calculate the number of pages with information (fields that have slid up) within the body of the document and only save those pages?

                           Also, I need to add to the script so that it will save the format of the report layout when clicking the button from  standard layout when I am done with the data entry I tried to add to the "go to layout" and it does go there but it doesn't complete the remainder of the script and save to pdf.

                           Thanks Again!

                           Erica

                      • 8. Re: need script to autosave and name .pdf reports
                        EricaJackson

                             @ S Chamblee Thank you, I think your additional steps will address the first part of my question posted to Phil.  The examples you send are so very helpful!

                        • 9. Re: need script to autosave and name .pdf reports
                          philmodjunk

                               To repeat, I really can't offer any help on the issue of your blank pages without seeing what your layout looks like. You can capture a screen shot of the layout and upload it her using the controls below Post A Answer.

                               I need to know why you have "blank pages" in the first place and what that means in terms of your layout design.

                          • 10. Re: need script to autosave and name .pdf reports
                            EricaJackson

                                 @ S chamblee I can't get your added script steps to work in my DB, I did change the table and filed names etc, would it have anything to do with your example only having one table?

                            • 11. Re: need script to autosave and name .pdf reports
                              schamblee

                                   No, that shouldn't have anything to do with it. All the script does is freeze the screen then goes to the report layout and save to a pdf in the pdf folder on the desktop.  Pretty much straight forward script.   The sample will not create a PDF folder.  You have to have the folder already created. 

                                   Save as Pdf is about the same as printing.     

                                    

                                    Are you getting any errors ?

                                    

                              • 12. Re: need script to autosave and name .pdf reports
                                EricaJackson

                                     @ PhilModJunk:  The report has 3 parts Header body and footer. The body contains text calculation fields (you helped with those in an differnet post) all are set to slide and do slide. But because I never know which of the fields will require more or less text, the layout is created with very long text fields, I can't use a scroll bar when printing. In order to make sure that none of the text was cut off I had to extend the text fields and the layout is very long. All of the fields slide up appropriately, but the body does not shrink and then creates the blank pages blank pages at the end of the pdf. The pages do have the header/footer information, the body is blank.... I hope this makes more sense.

                                     In filemaker help : 

                                                                                                 
                                                    
                                               
                                                    
                                You can set layout parts to shrink when the fields in them slide up. Headers, footers, title headers, and title footers never shrink or slide up. Don't set a part to shrink on a layout that requires fixed vertical spacing, like labels.
                                               

                                     I thought that since they didn't include "body" that there should be a way to make it shrink when the fields within it shrink... but it did not give an example of how to accomplish this. Sorry for being so unclear.

                                     Thanks!

                                     Erica

                                      

                                • 13. Re: need script to autosave and name .pdf reports
                                  EricaJackson

                                       @ S Chamblee .. I started over and added your steps to a copy of the working script of Phil's and got it to work without errors. I'm sure I forgot to check or enable something. Your help is greatly appreciated.

                                       Erica

                                  • 14. Re: need script to autosave and name .pdf reports
                                    philmodjunk

                                         When you set your fields to slide/resize, also set the label text to slide up and resize.

                                         Key facts about sliding layout objects:

                                           
                                    1.           It's only visible in preview mode and when you print/save as PDF...
                                    2.      
                                    3.           Sliding fields will shrink but not expand.
                                    4.      
                                    5.           All layout objects below and in the same layout part as the slide/resize field need to also be set to slide up and resize.
                                    6.      
                                    7.           Objects in headers and footers will not slide.
                                    8.      
                                    9.           Portals will shrink/slide to fit the number of rows of records, but fields within the portal row will not shrink/slide.
                                    10.      
                                    11.           Fields will slide up only if Top, alignment is specified for it and will slide left only if left alignment is specified.
                                    12.      
                                    13.           Consistent side borders are difficult to achieve with sliding fields.
                                    1 2 Previous Next