Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MBS FileMaker Plugin Example Databases

OCR with DynaPDF

All examples are included with download of MBS FileMaker Plugin.

OCR with DynaPDF.fmp12

Overview
Tables1
Relationships0
Layouts1
Scripts6
Value Lists0
Custom Functions0
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
OCR
4 fields defined, 2 records
OCR

Fields

Table Name: OCR - 4 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
ImageNormal, BinaryAuto-Enter:
  • Allow editing
Validation:
  • Only during data entry
Storage:
  • Repetitions: 1
      ResultNormal, TextAuto-Enter:
      • Allow editing
      Validation:
      • Only during data entry
      Storage:
      • Repetitions: 1
      • Indexing: None
      • Automatically create indexes as needed
      • Index Language: German
          TextNormal, TextAuto-Enter:
          • Allow editing
          Validation:
          • Only during data entry
          Storage:
          • Repetitions: 1
          • Indexing: None
          • Automatically create indexes as needed
          • Index Language: German
              PDFNormal, BinaryAuto-Enter:
              • Allow editing
              Validation:
              • Only during data entry
              Storage:
              • Repetitions: 1

                  Layout Objects: OCR

                  Regular Fields

                  Field Name: OCR::Image
                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                  • Top: 24 pt
                  • Left: 138 pt
                  • Bottom: 149 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: OCR::Result
                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                  • Top: 150 pt
                  • Left: 138 pt
                  • Bottom: 170 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
                  Yes

                  Field Name: OCR::Text
                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                  • Top: 175 pt
                  • Left: 138 pt
                  • Bottom: 255 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
                  Yes

                  Field Name: OCR::PDF
                  Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                  • Top: 24 pt
                  • Left: 600 pt
                  • Bottom: 251 pt
                  • Right: 937 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

                  Buttons

                  Button PropertiesCoordinatesScript/Script Step
                    Type:
                  • Text: Make PDF
                  • Top: 46 pt
                  • Left: 402 pt
                  • Bottom: 71 pt
                  • Right: 572 pt
                  • Anchoring: Left, Top
                  Perform Script [ “Run”; Parameter: 0 ]

                  Scripts:


                  Button PropertiesCoordinatesScript/Script Step
                    Type:
                  • Text: Make PDF with visible text
                  • Top: 82 pt
                  • Left: 402 pt
                  • Bottom: 107 pt
                  • Right: 572 pt
                  • Anchoring: Left, Top
                  Perform Script [ “Run”; Parameter: 1 ]

                  Scripts:


                  Script Hierarchy

                  Run
                  Trace
                  InitDynaPDF
                  Load Tesseract 4
                  Run Tesseract 4
                  Show Version

                  Next Script: [Trace]
                  Script NameRun
                  Run script with full access privilegesOff
                  Include In MenuYes
                  Layouts that use this script
                  Scripts that use this script
                    Script Definition
                    Script Steps
                    • If [ MBS("OCR.IsLoaded") ]
                    • #use newer version if initialized
                    • Perform Script [ “Run Tesseract 4” ]
                    • Exit Script [ Result: Get(ScriptResult) ]
                    • End If
                    • #Initialize DynaPDF if needed
                    • If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
                    • Perform Script [ “InitDynaPDF” ]
                    • End If
                    • #data folder in examples folder
                    • 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" ]
                    • Set Variable [ $path; Value:Substitute ( $databasePath ; $databaseName ; "" ) ]
                    • #Init OCR
                    • Set Variable [ $r; Value:MBS( "OCR.Initialize"; $path; "eng") ]
                    • Set Field [ OCR::Result; $r ]
                    • If [ MBS("isError") ≠ 0 ]
                    • Exit Script [ Result: $r ]
                    • End If
                    • Set Variable [ $rr; Value:MBS( "OCR.SetPageSegMode"; "Auto") ]
                    • #Process Image
                    • Set Variable [ $img; Value:MBS("GMImage.NewFromContainer"; OCR::Image) ]
                    • Set Variable [ $r; Value:MBS( "OCR.SetImage"; $img) ]
                    • Set Field [ OCR::Text; MBS("OCR.GetText") ]
                    • #Clear current PDF document
                    • Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
                    • #Add page
                    • Set Variable [ $r; Value:MBS("DynaPDF.AppendPage"; $pdf) ]
                    • #Add Image
                    • Set Variable [ $r; Value:MBS("DynaPDF.ReadImageResolution"; $pdf; OCR::Image) ]
                    • Set Variable [ $resX; Value:GetAsNumber (LeftValues ( $r ; 1 )) ]
                    • Set Variable [ $resY; Value:GetAsNumber (MiddleValues ( $r ; 2; 1 )) ]
                    • If [ $resX <= 0 ]
                    • Set Variable [ $resX; Value:72 ]
                    • End If
                    • If [ $resY <= 0 ]
                    • Set Variable [ $resY; Value:72 ]
                    • End If
                    • Set Variable [ $r; Value:MBS("DynaPDF.ReadImageFormat"; $pdf; OCR::Image) ]
                    • Set Variable [ $ImageWidth; Value:GetAsNumber (LeftValues ( $r ; 1 )) ]
                    • Set Variable [ $imageHeight; Value:GetAsNumber (MiddleValues ( $r ; 2; 1 )) ]
                    • Set Variable [ $BitsPerPixel; Value:GetAsNumber (MiddleValues ( $r ;3; 1 )) ]
                    • #no recompression!
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetSaveNewImageFormat"; $pdf; 0) ]
                    • Set Variable [ $x; Value:0 ]
                    • Set Variable [ $y; Value:0 ]
                    • Set Variable [ $w; Value:$ImageWidth * 72 / $ResX ]
                    • Set Variable [ $h; Value:$ImageHeight * 72 / $ResY ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetPageHeight"; $pdf; $h) ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetPageWidth"; $pdf; $w) ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.InsertImage"; $pdf; OCR::Image; $x; $y; $w; $h) ]
                    • #Hide Text...
                    • If [ Get(ScriptParameter) = 0 ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetAlpha"; $pdf; 0; 0) ]
                    • End If
                    • #Add Text
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetFillColor"; $pdf; 1; 0; 0) ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]
                    • Set Variable [ $r; Value:MBS("OCR.WriteToPDF"; $pdf; $x; $y; $w; $h) ]
                    • #Show Text...
                    • If [ Get(ScriptParameter) = 0 ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetAlpha"; $pdf; 0; 0) ]
                    • End If
                    • #End page
                    • Set Variable [ $r; Value:MBS("DynaPDF.EndPage"; $pdf) ]
                    • #Set title
                    • Set Variable [ $r; Value:MBS("DynaPDF.SetDocInfo"; $pdf; "Title"; "Test PDF") ]
                    • #Render one page as Picture
                    • Set Variable [ $PDFData; Value:MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]
                    • Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]
                    • #Put in Container
                    • Set Field [ OCR::PDF; $PDFData ]
                    • #Cleanup
                    • Set Variable [ $r; Value:MBS( "OCR.CleanUp") ]
                    • Set Variable [ $r; Value:MBS( "GMImage.Destroy"; $img) ]
                    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: [Run]Next Script: [InitDynaPDF]
                          Script NameTrace
                          Run script with full access privilegesOff
                          Include In MenuYes
                          Layouts that use this script
                            Scripts that use this script
                              Script Definition
                              Script Steps
                              • Set Variable [ $Trace; Value:MBS("Trace") ]
                              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: [Trace]Next Script: [Load Tesseract 4]
                                            Script NameInitDynaPDF
                                            Run script with full access privilegesOff
                                            Include In MenuNo
                                            Layouts that use this script
                                              Scripts that use this script
                                              Script Definition
                                              Script Steps
                                              • #Locate DynaPDF library
                                              • #you can have libraries in container and export at runtime to folder of your choice.
                                              • #Or install library somewhere and pass path.
                                              • #If library is in same folder as plugin, you can only pass only file name.
                                              • If [ MBS("IsServer") ]
                                              • #Put the path you use for your server here:
                                              • If [ Get(SystemPlatform) = -2 ]
                                              • #Server on Windows
                                              • Set Variable [ $path; Value:"C:\Programs\FileMaker Server\dynapdf64.dll" ]
                                              • Else If [ MBS("IsLinux") ]
                                              • #Server on Linux for FileMaker Cloud
                                              • Set Variable [ $path; Value:"/opt/FileMaker/FileMaker Server/dynapdf.linux.so" ]
                                              • Else
                                              • #Server on Mac
                                              • Set Variable [ $path; Value: "/Library/FileMaker Server/dynapdf.dylib" ]
                                              • End If
                                              • Else
                                              • #For desktop and our examples we look in same folder as database:
                                              • Set Variable [ $databasePath; Value:Get(FilePath) ]
                                              • Set Variable [ $databasePath; Value:MBS("Path.FilemakerPathToNativePath"; $databasePath) ]
                                              • Set Variable [ $databasePath; Value:Substitute ( $databasePath ; ".fp7" ; ".fmp12") ]
                                              • Set Variable [ $databasePath; Value:Substitute ( $databasePath ; "/OCR/" ; "/DynaPDF/") ]
                                              • Set Variable [ $databasePath; Value:Substitute ( $databasePath ; "\OCR\\" ; "\DynaPDF\\") ]
                                              • Set Variable [ $databaseName; Value:Get(FileName) & ".fmp12" ]
                                              • If [ Get(SystemPlatform) = -2 ]
                                              • Set Variable [ $path; Value:Substitute ( $databasePath ; $databaseName ; "dynapdf.dll" ) ]
                                              • #plugin will look for dynapdf.dll and if not found also for dynapdf64.dll (64-bit) and dynapdf32.dll (32-bit).
                                              • Else
                                              • Set Variable [ $path; Value:Substitute ( $databasePath ; $databaseName ; "dynapdf.dylib" ) ]
                                              • #Mac dylib is usually 32 and 64 bit together.
                                              • End If
                                              • End If
                                              • #You can test for free.
                                              • #If you like to get a dynapdf license, please follow links on our pricing page:
                                              • #https://www.monkeybreadsoftware.de/filemaker/pricing.shtml
                                              • Set Variable [ $LicenseKey; Value:"" // put your key here or leave empty for demo. ]
                                              • Set Variable [ $r; Value:MBS( "DynaPDF.Initialize"; $path; $LicenseKey) ]
                                              • If [ $r ≠ "OK" ]
                                              • Show Custom Dialog [ Title: "Error"; Message: $r; Default Button: “OK”, Commit: “No”; Button 2: “Cancel”, Commit: “No” ]
                                              • Halt Script
                                              • 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: [Run Tesseract 4]
                                                            Script NameLoad Tesseract 4
                                                            Run script with full access privilegesOff
                                                            Include In MenuYes
                                                            Layouts that use this script
                                                              Scripts that use this script
                                                                Script Definition
                                                                Script Steps
                                                                • If [ MBS( "OCR.IsLoaded" ) = 0 ]
                                                                • If [ MBS("isMacOS") ]
                                                                • If [ MBS("Files.FileExists"; "/usr/local/lib/libtesseract.dylib") ]
                                                                • #load from homebrew
                                                                • Set Variable [ $r; Value:MBS( "OCR.Load"; "/usr/local/lib/liblept.5.dylib" ) ]
                                                                • Set Variable [ $r; Value:MBS( "OCR.Load"; "/usr/local/lib/libtesseract.dylib" ) ]
                                                                • Else
                                                                • #load the copy from MBS website
                                                                • Set Variable [ $r; Value:MBS( "OCR.Load"; "/Users/cs/Tesseract/tesseract4/tesseract.dylib" ) ]
                                                                • End If
                                                                • Else If [ MBS("isWindows") ]
                                                                • Set Variable [ $r; Value:MBS("Process.SetCurrentDirectory"; "C:\Program Files\Tesseract-OCR") & MBS( "OCR.Load"; "liblept-5.dll" ) & MBS( "OCR.Load"; "libtesseract-4.dll" ) ]
                                                                • Else If [ MBS("isLinux") ]
                                                                • Set Variable [ $r; Value:MBS( "OCR.Load"; "liblept.so.5" ) & MBS( "OCR.Load"; "libtesseract.so.4" ) ]
                                                                • End If
                                                                • Show Custom Dialog [ Title: "OCR Loaded"; Message: $r; Default Button: “OK”, Commit: “Yes” ]
                                                                • 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: [Load Tesseract 4]Next Script: [Show Version]
                                                                              Script NameRun Tesseract 4
                                                                              Run script with full access privilegesOff
                                                                              Include In MenuYes
                                                                              Layouts that use this script
                                                                                Scripts that use this script
                                                                                Script Definition
                                                                                Script Steps
                                                                                • #Initialize DynaPDF if needed
                                                                                • If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
                                                                                • Perform Script [ “InitDynaPDF” ]
                                                                                • End If
                                                                                • #where is data folder?
                                                                                • If [ MBS("isMacOS") ]
                                                                                • If [ MBS("Files.FileExists"; "/usr/local/lib/libtesseract.dylib") ]
                                                                                • #get tessdata from homebrew
                                                                                • Set Variable [ $path; Value:"/usr/local/Cellar/tesseract/4.1.1/share/tessdata" ]
                                                                                • #for non eng, use this path:
                                                                                • // Set Variable [ $path; Value:"/usr/local/Cellar/tesseract-lang/4.1.0/share/tessdata" ]
                                                                                • Else
                                                                                • #or manual downloaded copy
                                                                                • Set Variable [ $path; Value:"/Users/cs/Tesseract/tesseract4/tessdata" ]
                                                                                • End If
                                                                                • Else If [ MBS("isWindows") ]
                                                                                • Set Variable [ $path; Value:"C:\Program Files\Tesseract-OCR\tessdata" ]
                                                                                • Else If [ MBS("isLinux") ]
                                                                                • #use default from installation
                                                                                • Set Variable [ $path; Value:"" ]
                                                                                • Else
                                                                                • Exit Script [ Result: "new platform?" ]
                                                                                • End If
                                                                                • #Init OCR
                                                                                • Set Variable [ $r; Value:MBS( "OCR.Initialize"; $path; "eng") ]
                                                                                • Set Field [ OCR::Result; $r ]
                                                                                • If [ MBS("isError") ≠ 0 ]
                                                                                • Exit Script [ Result: $r ]
                                                                                • End If
                                                                                • Set Variable [ $rr; Value:MBS( "OCR.SetPageSegMode"; "Auto") ]
                                                                                • #Process Image
                                                                                • Set Variable [ $img; Value:MBS("GMImage.NewFromContainer"; OCR::Image) ]
                                                                                • Set Variable [ $r; Value:MBS( "OCR.SetImage"; $img) ]
                                                                                • Set Field [ OCR::Text; MBS("OCR.GetText") ]
                                                                                • #Clear current PDF document
                                                                                • Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
                                                                                • #Add page
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.AppendPage"; $pdf) ]
                                                                                • #Add Image
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.ReadImageResolution"; $pdf; OCR::Image) ]
                                                                                • Set Variable [ $resX; Value:GetAsNumber (LeftValues ( $r ; 1 )) ]
                                                                                • Set Variable [ $resY; Value:GetAsNumber (MiddleValues ( $r ; 2; 1 )) ]
                                                                                • If [ $resX <= 0 ]
                                                                                • Set Variable [ $resX; Value:72 ]
                                                                                • End If
                                                                                • If [ $resY <= 0 ]
                                                                                • Set Variable [ $resY; Value:72 ]
                                                                                • End If
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.ReadImageFormat"; $pdf; OCR::Image) ]
                                                                                • Set Variable [ $ImageWidth; Value:GetAsNumber (LeftValues ( $r ; 1 )) ]
                                                                                • Set Variable [ $imageHeight; Value:GetAsNumber (MiddleValues ( $r ; 2; 1 )) ]
                                                                                • Set Variable [ $BitsPerPixel; Value:GetAsNumber (MiddleValues ( $r ;3; 1 )) ]
                                                                                • #no recompression!
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetSaveNewImageFormat"; $pdf; 0) ]
                                                                                • Set Variable [ $x; Value:0 ]
                                                                                • Set Variable [ $y; Value:0 ]
                                                                                • Set Variable [ $w; Value:$ImageWidth * 72 / $ResX ]
                                                                                • Set Variable [ $h; Value:$ImageHeight * 72 / $ResY ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetPageHeight"; $pdf; $h) ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetPageWidth"; $pdf; $w) ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.InsertImage"; $pdf; OCR::Image; $x; $y; $w; $h) ]
                                                                                • #Hide Text...
                                                                                • If [ Get(ScriptParameter) = 0 ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetAlpha"; $pdf; 0; 0) ]
                                                                                • End If
                                                                                • #Add Text
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetFillColor"; $pdf; 1; 0; 0) ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetFont"; $pdf; "Helvetica"; 0; 12) ]
                                                                                • Set Variable [ $r; Value:MBS("OCR.WriteToPDF"; $pdf; $x; $y; $w; $h) ]
                                                                                • #Show Text...
                                                                                • If [ Get(ScriptParameter) = 0 ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetAlpha"; $pdf; 0; 0) ]
                                                                                • End If
                                                                                • #End page
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.EndPage"; $pdf) ]
                                                                                • #Set title
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.SetDocInfo"; $pdf; "Title"; "Test PDF") ]
                                                                                • #Render one page as Picture
                                                                                • Set Variable [ $PDFData; Value:MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]
                                                                                • Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]
                                                                                • #Put in Container
                                                                                • Set Field [ OCR::PDF; $PDFData ]
                                                                                • #Cleanup
                                                                                • Set Variable [ $r; Value:MBS( "OCR.CleanUp") ]
                                                                                • Set Variable [ $r; Value:MBS( "GMImage.Destroy"; $img) ]
                                                                                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: [Run Tesseract 4]
                                                                                      Script NameShow Version
                                                                                      Run script with full access privilegesOff
                                                                                      Include In MenuYes
                                                                                      Layouts that use this script
                                                                                        Scripts that use this script
                                                                                          Script Definition
                                                                                          Script Steps
                                                                                          • Show Custom Dialog [ Title: "Version"; Message: MBS("OCR.Version"); Default Button: “OK”, Commit: “Yes” ]
                                                                                          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

                                                                                                        Download example: OCR with DynaPDF

                                                                                                        Used functions: