MBS FileMaker Plugin Example Databases

Shrink PDF pages

All examples are included with download of MBS FileMaker Plugin.

Shrink PDF pages.fmp12

Overview
Tables1
Relationships0
Layouts1
Scripts4
Value Lists0
Custom Functions1
Custom Menus33
File Options
Default custom menu set[Standard FileMaker Menus]
When opening file
Minimum allowed version12.0
Login usingAccount Name; Account= Admin
Allow user to save passwordOff
Require iOS passcodeOff
Switch to layoutOff
Hide all toolbarsOff
Script triggers
OnFirstWindowOpenOff
OnLastWindowCloseOff
OnWindowOpenOff
OnWindowCloseOff
OnFileAVPlayerChangeOff
Thumbnail Settings
Generate ThumbnailsOn; Temporary

 

Tables

Table Name
Statistics
Occurrences in Relationship Graph
PDF
5 fields defined, 1 record
PDF

Fields

Table Name: PDF - 5 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
Input PDFNormal, BinaryAuto-Enter:
  • Allow editing
Validation:
  • Only during data entry
Storage:
  • Repetitions: 1
      Output PDFNormal, BinaryAuto-Enter:
      • Allow editing
      Validation:
      • Only during data entry
      Storage:
      • Global
      • Repetitions: 1
          DynaPDF License KeyNormal, TextAuto-Enter:
          • Allow editing
          Validation:
          • Only during data entry
          Storage:
          • Global
          • Repetitions: 1
          • Index Language: German
              StartPageOffsetNormal, NumberAuto-Enter:
              • Allow editing
              Validation:
              • Only during data entry
              Storage:
              • Global
              • Repetitions: 1
              • Index Language: German
                  RestoredNormal, BinaryAuto-Enter:
                  • Allow editing
                  Validation:
                  • Only during data entry
                  Storage:
                  • Global
                  • Repetitions: 1

                      Layout Objects: PDF

                      Regular Fields

                      Field Name: PDF::Input PDF
                      Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                      • Top: 198 pt
                      • Left: 289 pt
                      • Bottom: 323 pt
                      • Right: 542 pt
                      • Anchoring: Left, Top
                      Field Format:
                      • Edit Box
                      Field Behavior:
                      • Allow field to be entered: In Find mode, In Browse mode
                      • Touch keyboard type: System Default
                      • Go to next field using: Tab key
                      No

                      Field Name: PDF::Output PDF
                      Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                      • Top: 18 pt
                      • Left: 289 pt
                      • Bottom: 143 pt
                      • Right: 542 pt
                      • Anchoring: Left, Top
                      Field Format:
                      • Edit Box
                      Field Behavior:
                      • Allow field to be entered: In Find mode, In Browse mode
                      • Touch keyboard type: System Default
                      • Go to next field using: Tab key
                      No

                      Field Name: PDF::DynaPDF License Key
                      Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                      • Top: 344 pt
                      • Left: 138 pt
                      • Bottom: 358 pt
                      • Right: 391 pt
                      • Anchoring: Left, Top
                      Field Format:
                      • Edit Box
                      Field Behavior:
                      • Allow field to be entered: In Find mode, In Browse mode
                      • Touch keyboard type: System Default
                      • Go to next field using: Tab key
                      No

                      Field Name: PDF::StartPageOffset
                      Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                      • Top: 143 pt
                      • Left: 88 pt
                      • Bottom: 157 pt
                      • Right: 167 pt
                      • Anchoring: Left, Top
                      Field Format:
                      • Edit Box
                      Field Behavior:
                      • Allow field to be entered: In Find mode, In Browse mode
                      • Touch keyboard type: Default for Data Type
                      • Go to next field using: Tab key
                      No

                      Field Name: PDF::Restored
                      Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                      • Top: 18 pt
                      • Left: 627 pt
                      • Bottom: 143 pt
                      • Right: 880 pt
                      • Anchoring: Left, Top
                      Field Format:
                      • Edit Box
                      Field Behavior:
                      • Allow field to be entered: In Find mode, In Browse mode
                      • Touch keyboard type: Default for Data Type
                      • Go to next field using: Tab key
                      No

                      Group Buttons

                      Button PropertiesCoordinatesScript/Script Step
                        Type:
                      • Text: Process PDF
                        Additional Properties:
                      • Change to hand cursor over button
                      • Rectangular
                      • Top: 21 pt
                      • Left: 15 pt
                      • Bottom: 52 pt
                      • Right: 148 pt
                      • Anchoring: Left, Top
                      Perform Script [ “Shrink” ]

                      Scripts:


                      Script Hierarchy

                      InitDynaPDF
                      Shrink
                      Reverse
                      Extract

                      Next Script: [Shrink]
                      Script NameInitDynaPDF
                      Run script with full access privilegesOff
                      Include In MenuYes
                      Layouts that use this script
                        Scripts that use this script
                        Script Definition
                        Script Steps
                        • #Locate DynaPDF library
                        • Set Variable [ $databasePath; Value:Get(FilePath) ]
                        • Set Variable [ $databasePath; Value:MBS("Path.FilemakerPathToNativePath"; $databasePath) ]
                        • Set Variable [ $databasePath; Value:Substitute ( $databasePath ; ".fp7" ; ".fmp12") ]
                        • Set Variable [ $databaseName; Value:Get(FileName) & ".fmp12" ]
                        • If [ Get(SystemPlatform) = -2 ]
                        • Set Variable [ $path; Value:Substitute ( $databasePath ; $databaseName ; "dynapdf.dll" ) ]
                        • Else
                        • Set Variable [ $path; Value:Substitute ( $databasePath ; $databaseName ; "dynapdf.dylib" ) ]
                        • End If
                        • #Initialize DynaPDF
                        • Set Variable [ $r; Value:MBS( "DynaPDF.Initialize"; $path; PDF::DynaPDF License Key) ]
                        • Set Variable [ $$DynaPDFInited; Value:1 ]
                        • If [ $r ≠ "OK" ]
                        • Show Custom Dialog [ Title: "DynaPDF failed to initialize"; Message: $r; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                        • End If
                        Fields used in this script
                        Scripts used in this script
                          Layouts used in this script
                            Tables used in this script
                            Table occurrences used by this script
                            Custom Functions used by this script
                              Custom menu set used by this script

                                Previous Script: [InitDynaPDF]Next Script: [Reverse]
                                Script NameShrink
                                Run script with full access privilegesOff
                                Include In MenuYes
                                Layouts that use this script
                                Scripts that use this script
                                  Script Definition
                                  Script Steps
                                  • #Imports PDF and shrinks all pages, so we can print additional content like timestamp on the side.
                                  • #We store the original page content size in art box.
                                  • #And we store original files in PDF as attachment, so we can extract them later.
                                  • #Parameters
                                  • #margin for space around page
                                  • Set Variable [ $marginTop; Value:50 ]
                                  • Set Variable [ $marginLeft; Value:50 ]
                                  • Set Variable [ $marginRight; Value:50 ]
                                  • Set Variable [ $marginBottom; Value:50 ]
                                  • #margin for text around page edges
                                  • Set Variable [ $marginTextLeft; Value:10 ]
                                  • Set Variable [ $marginTextRight; Value:10 ]
                                  • Set Variable [ $marginTextBottom; Value:10 ]
                                  • Set Variable [ $marginTextTop; Value:10 ]
                                  • #Draw border 1 = yes, 0 = no
                                  • Set Variable [ $drawBorder; Value:1 ]
                                  • #Various texts to place with optional Tags
                                  • Set Variable [ $TopCenterText; Value:"CONFIDENTIAL" ]
                                  • Set Variable [ $BottomCenterText; Value:Get(CurrentTimestamp) ]
                                  • Set Variable [ $TopLeftText; Value:"12345678TL" ]
                                  • Set Variable [ $BottomLeftText; Value:"12345678BL" ]
                                  • Set Variable [ $BottomRightText; Value:"12345678BR" ]
                                  • Set Variable [ $TopRightText; Value:"Page <PAGE> of <PAGESTOTAL>" ]
                                  • #Font setting
                                  • Set Variable [ $fontname; Value:"Helvetica" ]
                                  • Set Variable [ $fontsize; Value:14 ]
                                  • Set Variable [ $fontstyle; Value:0 ]
                                  • #page offset for numbering
                                  • Set Variable [ $pagesOffset; Value:PDF::StartPageOffset ]
                                  • #Include original files 1 = yes, 0 = no
                                  • Set Variable [ $EmbedOriginals; Value:1 ]
                                  • #Initialize DynaPDF if needed
                                  • If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
                                  • Perform Script [ “InitDynaPDF” ]
                                  • End If
                                  • #Start PDF session
                                  • Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
                                  • Set Variable [ $documentIndex; Value:1 ]
                                  • # Check how many pages we have
                                  • Set Variable [ $pagesTotal; Value:$pagesOffset ]
                                  • Go to Record/Request/Page [ First ]
                                  • Loop
                                  • Set Variable [ $r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; PDF::Input PDF) ]
                                  • If [ MBS("IsError") = 0 ]
                                  • Set Variable [ $pageCount; Value:MBS("DynaPDF.GetImportPageCount"; $pdf) ]
                                  • Set Variable [ $pagesTotal; Value:$pagesTotal + $pageCount ]
                                  • End If
                                  • Go to Record/Request/Page [ Next; Exit after last ]
                                  • End Loop
                                  • # now put content on top
                                  • Go to Record/Request/Page [ First ]
                                  • Loop
                                  • Set Variable [ $r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; PDF::Input PDF) ]
                                  • If [ MBS("IsError") = 0 ]
                                  • Set Variable [ $pageCount; Value:MBS("DynaPDF.GetImportPageCount"; $pdf) ]
                                  • Set Variable [ $pageIndex; Value:1 ]
                                  • Loop
                                  • # add a page with background
                                  • Set Variable [ $template; Value:MBS("DynaPDF.ImportPageAsTemplate"; $pdf; $pageIndex) ]
                                  • If [ MBS("IsError") = 0 ]
                                  • #Calculate page size
                                  • Set Variable [ $PageHeight; Value:MBS( "DynaPDF.GetTemplHeight"; $pdf; $template ) ]
                                  • Set Variable [ $PageWidth; Value:MBS( "DynaPDF.GetTemplWidth"; $pdf; $template ) ]
                                  • Set Variable [ $NewPageHeight; Value:$PageHeight + $MarginTop + $MarginBottom ]
                                  • Set Variable [ $NewPageWidth; Value:$PageWidth + $MarginLeft + $MarginRight ]
                                  • #Add page and place template
                                  • Set Variable [ $r; Value:MBS("DynaPDF.AppendPage"; $pdf) ]
                                  • Set Variable [ $w; Value:MBS("DynaPDF.SetPageWidth"; $pdf; $NewPageWidth) ]
                                  • Set Variable [ $w; Value:MBS("DynaPDF.SetPageHeight"; $pdf; $NewPageHeight) ]
                                  • Set Variable [ $r; Value:MBS("DynaPDF.PlaceTemplateEx"; $pdf; $template; $marginLeft; $MarginBottom; $PageWidth; $PageHeight) ]
                                  • #black RGB
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetColorSpace"; $pdf; "DeviceRGB" ) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetLineWidth"; $pdf; ,5 ) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetStrokeColor"; $pdf; 0; 0; 0 ) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetFillColor"; $pdf; 0; 0; 0 ) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetFont"; $pdf; $fontName; $fontstyle; $fontsize) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetPageCoords"; $PDF; "TopDown" ) ]
                                  • #draw border
                                  • If [ $drawBorder ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.Rectangle"; $pdf; $MarginLeft-1; $MarginBottom-1; $PageWidth+2; $PageHeight+2; "Stroke" ) ]
                                  • End If
                                  • If [ Length($TopCenterText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($TopCenterText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; $marginleft; $MarginTextTop; $pagewidth; -1; "center"; $t ) ]
                                  • End If
                                  • If [ Length($TopLeftText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($topLeftText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; $marginTextLeft; $MarginTextTop; $newpagewidth - $MarginTextRight - $MarginTextLeft; -1; "left"; $t ) ]
                                  • End If
                                  • If [ Length($TopRightText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($topRightText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; $marginTextLeft; $MarginTextTop; $newpagewidth - $MarginTextRight - $MarginTextLeft; -1; "right"; $t ) ]
                                  • End If
                                  • Set Variable [ $y; Value:$marginTextBottom + $pageheight + $marginTop ]
                                  • If [ Length($BottomLeftText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($BottomLeftText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; $marginTextLeft; $y; $newpagewidth - $MarginTextRight - $MarginTextLeft; -1; "left"; $t ) ]
                                  • End If
                                  • If [ Length($BottomRightText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($BottomRightText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; $marginTextLeft; $y; $newpagewidth - $MarginTextRight - $MarginTextLeft; -1; "right"; $t ) ]
                                  • End If
                                  • If [ Length($BottomCenterText) > 0 ]
                                  • Set Variable [ $t; Value:ReplaceTags($BottomCenterText) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.WriteFTextEx"; $pdf; 0; $y; $newpagewidth; -1; "center"; $t ) ]
                                  • End If
                                  • #Page done
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.SetBBox"; $pdf; "art"; $marginLeft; $marginBottom; $marginLeft + $pageWidth; $marginBottom + $pageHeight ) ]
                                  • Set Variable [ $r; Value:MBS("DynaPDF.EndPage"; $pdf) ]
                                  • End If
                                  • # next
                                  • Set Variable [ $pageIndex; Value:$pageIndex +1 ]
                                  • Exit Loop If [ $pageIndex > $pageCount ]
                                  • End Loop
                                  • Set Variable [ $pagesOffset; Value:$pagesOffset + $pageCount ]
                                  • If [ $EmbedOriginals ]
                                  • Set Variable [ $name; Value:GetAsText ( PDF::Input PDF ) ]
                                  • Set Variable [ $name; Value:MBS( "Path.LastPathComponent"; $name ) ]
                                  • Set Variable [ $r; Value:MBS( "DynaPDF.AttachFileContainer"; $pdf; PDF::Input PDF; $name; "Original PDF"; 1) ]
                                  • Set Variable [ $documentIndex; Value:$documentIndex+1 ]
                                  • End If
                                  • End If
                                  • Go to Record/Request/Page [ Next; Exit after last ]
                                  • End Loop
                                  • Set Field [ PDF::Output PDF; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ]
                                  • #Write to Desktop & open
                                  • Set Variable [ $path; Value:MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "shrunken.pdf" ) ]
                                  • Set Variable [ $r; Value:MBS("Files.WriteFile"; PDF::Output PDF; $path) ]
                                  • Set Variable [ $r; Value:MBS("Files.LaunchFile"; $path) ]
                                  • #Cleanup
                                  • Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]
                                  Fields used in this script
                                  Scripts used in this script
                                  Layouts used in this script
                                    Tables used in this script
                                    Table occurrences used by this script
                                    Custom Functions used by this script
                                    Custom menu set used by this script

                                      Previous Script: [Shrink]Next Script: [Extract]
                                      Script NameReverse
                                      Run script with full access privilegesOff
                                      Include In MenuYes
                                      Layouts that use this script
                                        Scripts that use this script
                                          Script Definition
                                          Script Steps
                                          • #Imports PDF and unshrink all pages
                                          • #Hide the outer content by using art box as crop box.
                                          • #Initialize DynaPDF if needed
                                          • If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
                                          • Perform Script [ “InitDynaPDF” ]
                                          • End If
                                          • #Start PDF session
                                          • Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
                                          • # Check how many pages we have
                                          • Set Variable [ $r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; PDF::Output PDF) ]
                                          • Set Variable [ $pageCount; Value:MBS("DynaPDF.GetImportPageCount"; $pdf) ]
                                          • Set Variable [ $r; Value:MBS("DynaPDF.ImportPDFFile"; $pdf) ]
                                          • # now put content on top
                                          • Set Variable [ $pageIndex; Value:1 ]
                                          • Loop
                                          • Set Variable [ $r; Value:MBS("DynaPDF.EditPage"; $pdf; $pageIndex) ]
                                          • #Move art to crop box
                                          • Set Variable [ $l; Value:MBS( "DynaPDF.GetBBox"; $pdf; "Art"; "left" ) ]
                                          • Set Variable [ $r; Value:MBS( "DynaPDF.GetBBox"; $pdf; "Art"; "right" ) ]
                                          • Set Variable [ $t; Value:MBS( "DynaPDF.GetBBox"; $pdf; "Art"; "top" ) ]
                                          • Set Variable [ $b; Value:MBS( "DynaPDF.GetBBox"; $pdf; "Art"; "bottom" ) ]
                                          • If [ MBS("IsError") = 0 ]
                                          • Set Variable [ $r; Value:MBS( "DynaPDF.SetBBox"; $pdf; "crop"; $l; $t; $r; $b ) ]
                                          • End If
                                          • Set Variable [ $r; Value:MBS("DynaPDF.EndPage"; $pdf) ]
                                          • Set Variable [ $pageIndex; Value:$pageIndex + 1 ]
                                          • Exit Loop If [ $pageIndex > $pageCount ]
                                          • End Loop
                                          • Set Field [ PDF::Restored; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ]
                                          • #Write to Desktop & open
                                          • Set Variable [ $path; Value:MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "restored.pdf" ) ]
                                          • Set Variable [ $r; Value:MBS("Files.WriteFile"; PDF::Restored; $path) ]
                                          • Set Variable [ $r; Value:MBS("Files.LaunchFile"; $path) ]
                                          • #Cleanup
                                          • Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]
                                          Fields used in this script
                                          Scripts used in this script
                                          Layouts used in this script
                                            Tables used in this script
                                            Table occurrences used by this script
                                            Custom Functions used by this script
                                              Custom menu set used by this script

                                                Previous Script: [Reverse]
                                                Script NameExtract
                                                Run script with full access privilegesOff
                                                Include In MenuYes
                                                Layouts that use this script
                                                  Scripts that use this script
                                                    Script Definition
                                                    Script Steps
                                                    • #Extract embedded files in a PDF
                                                    • #Initialize DynaPDF if needed
                                                    • If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
                                                    • Perform Script [ “InitDynaPDF” ]
                                                    • End If
                                                    • #Start PDF session
                                                    • Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
                                                    • # Check how many pages we have
                                                    • Set Variable [ $r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; PDF::Output PDF) ]
                                                    • Set Variable [ $r; Value:MBS("DynaPDF.ImportPDFFile"; $pdf) ]
                                                    • Set Variable [ $fileCount; Value:MBS("DynaPDF.GetEmbeddedFileCount"; $pdf) ]
                                                    • # now put content on top
                                                    • Set Variable [ $fileIndex; Value:0 ]
                                                    • Loop
                                                    • Set Variable [ $container; Value:MBS( "DynaPDF.GetEmbeddedFileAsContainer"; $pdf; $fileIndex ) ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • New Record/Request
                                                    • Set Field [ PDF::Input PDF; $container ]
                                                    • Commit Records/Requests [ No dialog ]
                                                    • End If
                                                    • Set Variable [ $fileIndex; Value:$fileIndex + 1 ]
                                                    • Exit Loop If [ $fileIndex > $fileCount ]
                                                    • End Loop
                                                    • #Cleanup
                                                    • Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]
                                                    Fields used in this script
                                                    Scripts used in this script
                                                    Layouts used in this script
                                                      Tables used in this script
                                                      Table occurrences used by this script
                                                      Custom Functions used by this script
                                                        Custom menu set used by this script

                                                          Custom Functions

                                                          Function NameParametersAvailabilityDefinitionIn Field DefinitionsIn Scripts
                                                          ReplaceTagstextAll accountsLet ([ text = Substitute ( text ; "<PAGESTOTAL>" ; $pagesTotal ); text = Substitute ( text ; "<PAGE>" ; $pageIndex+ $pagesOffset) ];text )

                                                            Custom Menu Sets

                                                            Menu SetsMenusIn ScriptsIn LayoutsComments
                                                            [Standard FileMaker Menus]
                                                            • All Standard Menus
                                                            Custom Menu Set 1

                                                            Download example: Shrink PDF pages

                                                            Used functions:




                                                            Links
                                                            MBS FileMaker Plugins