7 Replies Latest reply on Feb 17, 2016 7:06 PM by LadyBear

    Automating PDF generation

    mkenglen

      I'm trying to create a script that will automate the generation of a pdf certificate. The print layout contains a sub-summary of classes attended for each employee. If it was just one class per employee I could figure out a simple looping script. I don't know how to generate a pdf for EACH employee's classes in a found set without capturing all the employees in the pdf (134 pages). How can I generate a pdf PER employee in the found set? I'm stuck. Thanks for your help! mke

        • 1. Re: Automating PDF generation
          erolst

          If you have a list of EmployeeIDs for those employees you want to print, you can indeed “employ” (sorry …) a looping script:

           

          Go to the summary layout, find the individual employees one by one by working through the ID list, sort, go to Preview Mode, print the PDF with unique name, repeat until the list is finished.

          • 2. Re: Automating PDF generation
            mkenglen

            Sorry, still stuck. So . . . I'm assuming I start the script with a complete found set of all employees who attended that day. If can sort by the employee ID. Is there a way I can print/save-as-pdf one page at a time? In the PDF Options box I wasn't sure if there was a calculation that would send me to print the next page (because it's a sub-summary, so there are multiple records per page). Otherwise, it seems like I have to "find the NEXT SET of records" and just find the next employee's records only. Don't know how to craft that within the script.

             

            mke

            • 3. Re: Automating PDF generation
              erolst

              "I'm assuming I start the script with a complete found set of all employees who attended that day.". You do, but not for display, but to identify the employees and find their IDs. Here's an example:

               

              First find all Classes records you want to include. Say that for a given date (or time period?), you find 30 classes which were attended by 20 employees in total. (Don't know the actual numbers, but it doesn't really matter). This means you want to print 20 PDFs.

               

              What you need now is a list of those 20 employee IDs to find each one's respective classes. To get that list, you need a relationship from the TO of your Classes layout back to Employee via EmployeeID; this in effect says "Show me all 20 Employee records who match this found set of Classes". If you have this TO, you can Set Variable [ $myEmployeeList ; List ( ClassesToEmployee::EmployeeID ) ].

               

              Now start a loop which reads the values from $myEmployeeList one by one and uses each ID plus other required data (date/range?) as search criteria. Sort the found set to make the sub-summarys work, print as PDF (I'm sure 1 page will do now), and repeat until you've worked your way through the 20 values in ID list and can exit the loop.

               

              Hope this will get you started.

              • 4. Re: Automating PDF generation
                Stephen Huston

                To get a unique PDF for each name, you need to run the Save to PDF step without dialog and specify a filepath and file name to be used for each. This has to be set via a $variable which needs to be reset to something unique for each Name as part of the loop.

                 

                The loop needs to contain both of these:

                     Set Variable $file (define the filepath and filename dynamically fron each record as you hit it.

                     Save PDF (file = $file, no dialog, current record only)

                and go to next record...

                end loop Exit after last

                • 5. Re: Automating PDF generation
                  erolst

                  Stephen -

                   

                  good you're adding the tips for calculating the PDF path and name, but I hope we're not confusing mke. The suggested loop is based on my understanding that for 20 employees, as in my example, there would be 20 certificates to print (each one stating one or more classes taken, summing up to 30).

                   

                  If this is so, then the loop would be controlled with a counter vs the number of values in the list of EmployeeIDs; the PDF would be the preview of the summary of the respective classes found for each employee in the loop, and its name can be calculated from looking into the Employee table. As the whole process would be based on going through a list of values, rather than records, there would no Go to Next or Exit after Last. (How I learned to love using the conjunctive …)

                   

                  Regards,

                  Oliver

                  • 6. Re: Automating PDF generation
                    LadyBear

                    What if an employee has multiple classes?  Does this change things?

                    • 7. Re: Automating PDF generation
                      LadyBear

                      If you use current record only then the sub-summary is wasted because only one records is printed.  I have a similar situation so I am looking at other posts to try and find a similar solution as the person who posted this.  I need to group my records subjects for each Student (rather than classes for each employee).  But the principles are the same.