4 Replies Latest reply on Oct 15, 2012 10:13 AM by philmodjunk

    Save Records as PDF

    pdoak_1

      Title

      Save Records as PDF

      Post

            

           Info: OS X v 10.8.2
                   FM 12.0v2
                   Intermediate user
            
           I have a script which extracts records from a table and I am trying to use the Save Records As PDF in the script but the document it saves to disk is not readable and is only a few Kb in size.  I can stop the script just before this command and then save the layout to PDF which works.  
            
           I have another script in the same database using a different layout which uses save records as PDF files and that works so would there be somehting about this layout which is preventing the PDF from correctly being saved to disk? 

        • 1. Re: Save Records as PDF
          philmodjunk
               

                    but the document it saves to disk is not readable and is only a few Kb in size.

               That's a very unusual result. I can see issues with the layout producing a different PDF than expected, but I wouldn't expect it to produce an unreadable PDF.

               You may want to compare your script to the one in this thread: Found Sets to PDF with unique file names

               It may be helpful to show us the script that you are using. To post a script to the forum:

                 
          1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
          2.      
          3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
          4.      
          5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
          6.      
          7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)
          • 2. Re: Save Records as PDF
            pdoak_1

                 Here is the script:

                  

                  

            Client Reports: Stock Transfer

            #Create folder on desktop if it does not already exist

            Perform Script [ “FolderCheck and creation” ] #Find set of client account nos

            Go to Layout [ “ClientAccounts” (contactManagement_CLIENTACCOUNTS) ] Enter Find Mode [ ]
            Set Field [ contactManagement_CLIENTACCOUNTS::Name; "Master" ]
            If [ IsEmpty ( GlobalVariables::PerfFeeAccounts) ]

            Else
                                Show Custom Dialog
            [ Message: "Performance fees are only going to be updated for " &GlobalVariables::PerfFeeAccounts & " account. If you wish to continue with just this account then select OK, otherwise select REMOVE."; Default

            Button: “OK”, Commit: “No”; Button 2: “REMOVE”, Commit: “No” ] If [ Get(LastMessageChoice)=2 ]

            Set Field [ GlobalVariables::PerfFeeAccounts; "" ] End If

            End If

            Set Field [ contactManagement_CLIENTACCOUNTS::_kf_SaxoID; GlobalVariables::PerfFeeAccounts ]

            Perform Find [ ]

            Go to Record/Request/Page

            [ First ]

            #Build pdf reports

            Loop

            #

            Set Variable [ $SaxoID; Value:contactManagement_CLIENTACCOUNTS::_kf_SaxoID ] Set Variable [ $ReportDate; Value:GlobalVariables::PnLRefDate ]
            Set Variable [ $ReportDateName; Value:GlobalVariables::TaxationToDate ]

            Set Variable [ $filename; Value:Let ( [

            tempName = "ClientReport " & Contact Management::__kp_ID_Contact & " " & Contact Management::NameInitials & " "& $SaxoID & " " & GetAsText ( $ReportDate) ; year = Right(GetAsText ( $ReportDate);2);
                                month=Middle(GetAsText ( $ReportDate);4;2);
                                day=Left(GetAsText ( $ReportDate);2);

            cleanName = Substitute ( tempName ; [" "; "_"] ; ["/"; "_"] )
                                ];
                                "file:" &Get (DesktopPath) & "Client Reports "&year&month&day&"/" & cleanName & ".pdf") ]

            // Show Custom Dialog [ Title: "test"; Message: $filename; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

            // Set Variable [ $filename; Value:Let ([ tempName = "ClientReport " & Contact Management::__kp_ID_Contact & " " & Contact Management::NameInitials & " "& $SaxoID & " " & GetAsText ( $ReportDate) ; year = Right(GetAsText
                                ( $ReportDate);2);month=Middle(GetAsText ( $ReportDate);4;2);day=Left(GetAsText ( $ReportDate);2);cleanName = Substitute ( tempName ; [" "; "_"] ; ["/"; "_"] ) ]; "file:" & Get (DesktopPath) & "Client Reports "&year&month&day&"/" & "untitled.pdf") ]

            Go to Layout [ “Stock transfer” (trancapital_allocationdata_instrumentcosttable_PORTWGT) ]
            Enter Find Mode [ ]
            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_SaxoID; $SaxoID ]
            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::pnlRefDate; GlobalVariables::PnLRefDate ] Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::Tran Type ID; "1" ]

            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID; " G*" ] Set Error Capture [ On ]
            Perform Find [ ]

            Sort Records [ Keep records in sorted order; Specified Sort Order: trancapital_allocationdata_instrumentcosttable_PORTWGT::Tran Type ID; ascending trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_ClientID; ascending
                                trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_SaxoID; ascending
                                trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID; descending; reorder based on summary field: trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ] [ Restore; No dialog ]

            Refresh Window

            [ Flush cached join results ]

            Go to Record/Request/Page

            [ First ]

            Loop

            page1image25864page1image26024page1image26184page1image26344page1image26504page1image26664page1image26824page1image26984page1image27144page1image27304page1image27464page1image27624page1image27784

            15 October 2012 17:42:45

            Contact Management v4.21.fmp12 - Stock Transfer -1-

            Client Reports: Stock Transfer

            Exit Loop If [ GetSummary ( trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ; trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID ) = 0 ]

            Go to Record/Request/Page

            [ Next; Exit after last ]

            End Loop
                                If
            [ GetSummary ( trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ; trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID )=0 ]

            Omit Multiple Records [ Get ( FoundCount ) ] [ No dialog ]

            End If
                                Print Setup
            [ Orientation: Landscape; Paper size: 8.27" x 11.69"; Scaling: 80% ]

            [ Restore; No dialog ]

            Save Records as PDF [ File Name: “$filename”; Records being browsed ]
                                [
            Document - Compatibility: Acrobat 7 and later ]
                                [
            Pages - Number Pages From: 1; Include: All pages ]
                                [
            Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ]

            [ Restore; No dialog ]

            Save Records as Excel [ File Name: “$filename”; Records being browsed; Use field names as column names ] [ Restore; No dialog ]

            #

            Go to Layout [ “ClientAccounts” (contactManagement_CLIENTACCOUNTS) ] Go to Record/Request/Page

            [ Next; Exit after last ]
            Exit Loop If [ contactManagement_CLIENTACCOUNTS::Name "Master" ]

            End Loop 

                                 

                  

            • 3. Re: Save Records as PDF
              pdoak_1

                   I solved it. I was inadvertantly overwriting the pdf with the "save records as excel" in the subsequent line of the script.

                   The layout consists of summary fields with the zero fields removed.  The "save records as excel" does not show any data in the file.  Is there a way to get the summary non zero fields to print to excel?

              • 4. Re: Save Records as PDF
                philmodjunk

                     I used Script Pretty in the Known Bugs List Database to make your script easier to read. Note the variable names in Red.

                     #Create folder on desktop if it does not already exist
                     Perform Script [ “FolderCheck and creation” ]
                     #Find set of client account nos
                     Go to Layout [ “ClientAccounts” (contactManagement_CLIENTACCOUNTS) ]
                     Enter Find Mode [ ]
                     Set Field [ contactManagement_CLIENTACCOUNTS::Name; "Master" ]
                     If [ IsEmpty ( GlobalVariables::PerfFeeAccounts) ]
                     Else
                            Show Custom Dialog [ Message: "Performance fees are only going to be updated for " &GlobalVariables::PerfFeeAccounts & " account.
                                 If you wish to continue with just this account then select OK, otherwise select REMOVE.";
                                 Default Button: “OK”, Commit: “No”; Button 2: “REMOVE”, Commit: “No” ]
                            If [ Get(LastMessageChoice)=2 ]
                                 Set Field [ GlobalVariables::PerfFeeAccounts; "" ]
                            End If
                     End If
                     Set Field [ contactManagement_CLIENTACCOUNTS::_kf_SaxoID; GlobalVariables::PerfFeeAccounts ]
                     Perform Find [ ]
                     Go to Record/Request/Page [ First ]
                     #Build pdf reports
                     Loop
                            #
                            Set Variable [ $SaxoID; Value:contactManagement_CLIENTACCOUNTS::_kf_SaxoID ]
                            Set Variable [ $ReportDate; Value:GlobalVariables::PnLRefDate ]
                            Set Variable [ $ReportDateName; Value:GlobalVariables::TaxationToDate ]
                            Set Variable [ $filename; Value:
                                  Let ( [tempName = "ClientReport " & Contact Management::__kp_ID_Contact & " " & Contact Management::NameInitials & " "& $SaxoID & " "
                                                               & GetAsText ( $ReportDate) ; year = Right(GetAsText ( $ReportDate);2);
                                           month=Middle(GetAsText ( $ReportDate);4;2);
                                           day=Left(GetAsText ( $ReportDate);2);
                                           cleanName = Substitute ( tempName ; [" "; "_"] ; ["/"; "_"] )
                                          ];
                                    "file:" &Get (DesktopPath) & "Client Reports "&year&month&day&"/" & cleanName & ".pdf") ]
                            Go to Layout [ “Stock transfer” (trancapital_allocationdata_instrumentcosttable_PORTWGT) ]
                            Enter Find Mode [ ]
                            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_SaxoID; $SaxoID ]
                            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::pnlRefDate; GlobalVariables::PnLRefDate ]
                            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::Tran Type ID; "1" ]
                            Set Field [ trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID; " G*" ]
                            Set Error Capture [ On ]
                            Perform Find [ ]
                            Sort Records [ Keep records in sorted order;
                                     Specified Sort Order: trancapital_allocationdata_instrumentcosttable_PORTWGT::Tran Type ID; ascending
                                                                    trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_ClientID; ascending
                                                                    trancapital_allocationdata_instrumentcosttable_PORTWGT::_kf_SaxoID; ascending
                                                                    trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID; descending;
                                                                    reorder based on summary field: trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ]
                                    [ Restore; No dialog ]
                            Refresh Window [ Flush cached join results ]
                            Go to Record/Request/Page [ First ]
                            Loop
                                    Exit Loop If [ GetSummary ( trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ;
                                                        trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID ) = 0 ]
                                    Go to Record/Request/Page [ Next; Exit after last ]
                            End Loop
                            If [ GetSummary ( trancapital_allocationdata_instrumentcosttable_PORTWGT::qty Sum ;
                                                       trancapital_allocationdata_instrumentcosttable_PORTWGT::strategyID )=0 ]
                                 Omit Multiple Records [ Get ( FoundCount ) ] [ No dialog ]
                            End If
                            Print Setup [ Orientation: Landscape; Paper size: 8.27" x 11.69"; Scaling: 80% ][ Restore; No dialog ]
                            Save Records as PDF [ File Name: “$filename”; Records being browsed ]
                               [ Document - Compatibility: Acrobat 7 and later ]
                               [ Pages - Number Pages From: 1; Include: All pages ]
                               [ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ]
                               [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ]
                               [ Restore; No dialog ]
                            Save Records as Excel [ File Name: “$filename”; Records being browsed; Use field names as column names ] [ Restore; No dialog ]
                            #
                            Go to Layout [ “ClientAccounts” (contactManagement_CLIENTACCOUNTS) ]
                            Go to Record/Request/Page [ Next; Exit after last ]
                            Exit Loop If [ contactManagement_CLIENTACCOUNTS::Name ≠ "Master" ]
                     End Loop

                     The file being saved as a PDF is being overwritten by the save records as Excel step as both are saving to exactly the same location and file name. Both also appear to be lacking the code to append the appropriate file extension (& ".PDF" and & ".xlsx" )

                     Also, the code in Blue does not work. You cannot modify the contents of a global field while in Find mode. (FileMaker thinks are you are then trying to enter find criteria and blocks the action due to the fact that entering find criteria into a global field won't work.)