This is a public Forum  publicRSS

Forum post

    Snozzle's
    Open pdf's within a container fields within a script...Answered
    Forum post posted November 4, 2009 by Snozzle's, last edited February 9, 2012 
    2380 Views, 17 Comments
    Title:
    Open pdf's within a container fields within a script calling 'perform applescript'
    Post:

    Hi,

     

    I'm using Filemaker Developer 9, on Mac OS X 10.6. 

     

    I can open a .pdf document in my archive file on my desktop from Filemaker calling applescript within a particular Filemaker script with no problem ... 

     

    "tell application \"Preview\" to open \"Snozzle's HD:Users:thomastheriault:desktop:archive:" & SoHo Notes Category to Line Item Category::Archive pdf Path & "\"¶

    tell application \"Preview\" to activate" 

     

    ... however, this .pdf document needs to be secure, that is why I've inserted the .pdf document within a container field within Filemaker that is password protected leaving the 'Save Only Reference to File' unchecked (An Applescript will delete this file once it has been inserted )  We want the whole .pdf document saved within the Filemaker database. And I'm assuming that the container filed has the ability to store the complete file - Yes/No??

     

    If Yes - How do I call the .pdf document from within the container field within Filemaker from within a Filemaker script calling a 'Perform Applescript' like above.

     

    Please help or, if you know the exact page(s) in a good FileMaker Reference Book I will research myself.  Again, however, reading 900 million, billion pages, and googling and clicking into and trough a million, billion web links and their associated pages have yet to resolve my trouble :-(

     

    Any good, valid, uncluttered assistance would be extremely grateful at this moment!  Is there a better way??? Maybe, yes, no?

     

    Thank you!

     

    Snozzle's :-) 

    Best Answer

    Fenton Jones

    Actually, I just remembered a shorter way, which will work cross-platform (does not require AppleScript). There is an Automatically open option in the Export Field Contents script step. There is another trick to this step. Which is that if you specify an existing file's path (which you would have, since you just used it to export the field), and export again, but do not check the Specify Field option, then the existing file will be deleted, much the same as the Unix "rm" command.

     

    Allow User Abort [Off] 

    Set Variable [ $filepath; Case ( Abs ( Get ( SystemPlatform )) = 1; "filemac:"; "filewin:" ) & Get ( TemporaryPath ) & "fm_file.pdf" ]

    Export Field Contents [ container field; $filepath; Automatically open ]

    Pause/resume Script [ Duration (seconds); 1 ] 

    Export Field Contents [ $filepath ]

     

    If I do not Pause the script, Preview (or whatever your default PDF app is) does not open the file. Apparently the file is deleted before it can get it. On my machine a 1 second pause allows a 13 MB PDF to export and open. I believe that will work on older machines also, since FileMaker will not run the second export until the first is completed, and the app only needs a second to start loading the file. If it not enough, you could easily multiply the pause times the MB of the file. You can get the bytes via the Length (container field) for embedded files.

    Answer

    • TSGal

      Snozzle's:

       

      Thank you for your post.

       

      Yes, FileMaker Pro will store the complete PDF file if you uncheck "Save only as a reference".  However, how you insert it depends how (or if) it is displayed.

       

      If you insert the PDF file as an image, then the first page of the PDF file will be viewable in the Container field.  If you insert the PDF file as a file, then you will only see the icon of the PDF file.  To view the entire contents, you will need to right-click/control-click the icon and export to a file.  The resulting external file can then be launched to see the contents of the PDF file.

       

      Please let me know if you need clarification.

       

      TSGal;

      FileMaker, Inc. 

    • Snozzle's

      Thank you.

       

      However, these pdf's are secure documents; meaning, your eyes only.

       

      All I want to do is open the file from the container field, where the file resides.  Not the desktop.

       

      Exporting to the desktop, then opening the file, defeats the whole purpose of having a secure data file.

       

      All I want is to call Applescript or a FileMaker function to open these documents when I click on a button next to the record.

       

      The following script works great, however I have been unsuccessful in calling the file that sits within the container field; only because I am unsuccessful in writing the path correctly.  We have been temporarily calling the file that's been save to the folder ':archive' on the desktop, however this is NOT DESIRABLE.

       

      "tell application \"Preview\" to open \"Snozzle's HD:Users:thomastheriault:desktop:archive:" & SoHo Notes Category to Line Item Category::Archive pdf Path & "\"¶

      tell application \"Preview\" to activate"  

       

      All I need is the Applescript steps or the FileMaker function which I'm researching now to call the file within the container field and open it directly within the application I choose; like 'Preview' or Adobe Acrobat Professional, not the default application.  And again, I have NO DESIRE TO HAVE A COPY ON THE DESKTOP that's for sure :-)

       

      However, I am unable to locate a basic foundational written string that can apply to any path whether Filemaker or Applescript. A basic script guide to call a file within a container field within filemaker so I can see how the path is written and then hopefully substitute with my information within the path that I can reference and write.

       

      Any guidance in this area would be extremely grateful.

       

      Thank you.

       

      Tom :-)

       

      Snozzle's Car Washes 

       

       

       

       

       

       

    • Fenton Jones

      It seems you are thinking that the file embedded in the container field is still a "document" which can be opened directly; it is not really a document, nor really a file either, as it has no place outside of the container field. It is binary data in a container field. FileMaker cannot open it, it can only store it, nor can any other application open it; until it is exported to a file. 

       

      So your only choice to see it is to Export Field Contents. You could export it to a temporary path, of which the (normal) user has no idea. You could open it with an application, then immediately delete the document file, as it is already in RAM by then, and no longer requires the file, at least for viewing. 

       

      For example, while reading the file in Preview, this AppleScript will completely delete the Dumb.pdf file on my Desktop, with no warning, after overwriting its data (3 times), so it can no longer be read on the disk by a recovery application. It does not put it in the Trash. That seems pretty secure to me. Though, I am still able to use Save As to create a new file from what is open; I cannot see any way to stop a user from doing that, other than setting that internally within the PDF.

       

      do shell script "rm -fP ~/Desktop/Dumb.pdf" 

       

      Be darn sure you have the path correct. A Unix path, properly quoted. Because rm can take out much of your computer in a flash if badly written; you have been warned. On the other hand, you could just rely on the Temporary folder's contents being gone after a Restart.

       

      You could use FileMaker's Get (TemporaryPath) as the folder path. You would have to convert that to a Unix path (no drive name) if you were going to delete the file. These could be text calculations within FileMaker and/or conversions within AppleScript. It is useful to practice converting paths from one syntax to the other.

    • Snozzle's

      Thank you, thank you, thank you :-)

       

      The documents are private and on a private laptop, and we are just wanting to make sure that there is only one place for the source file.

       

      I like the delete option, that will work.  Nothing is secure for ever, we are not a crazy secret organization, all that will be require is to secure the source file as best and as reasonably possible and your explanation was extremely grateful.

       

      Thank you again. 

       

      I will heed your warning as well :-) 

       

       

       

    • Fenton Jones

      Actually, I just remembered a shorter way, which will work cross-platform (does not require AppleScript). There is an Automatically open option in the Export Field Contents script step. There is another trick to this step. Which is that if you specify an existing file's path (which you would have, since you just used it to export the field), and export again, but do not check the Specify Field option, then the existing file will be deleted, much the same as the Unix "rm" command.

       

      Allow User Abort [Off] 

      Set Variable [ $filepath; Case ( Abs ( Get ( SystemPlatform )) = 1; "filemac:"; "filewin:" ) & Get ( TemporaryPath ) & "fm_file.pdf" ]

      Export Field Contents [ container field; $filepath; Automatically open ]

      Pause/resume Script [ Duration (seconds); 1 ] 

      Export Field Contents [ $filepath ]

       

      If I do not Pause the script, Preview (or whatever your default PDF app is) does not open the file. Apparently the file is deleted before it can get it. On my machine a 1 second pause allows a 13 MB PDF to export and open. I believe that will work on older machines also, since FileMaker will not run the second export until the first is completed, and the app only needs a second to start loading the file. If it not enough, you could easily multiply the pause times the MB of the file. You can get the bytes via the Length (container field) for embedded files.

    • PhilModJunk

      Clever script Fenton, but when I tried it on a sample file, the second export field step doesn't seem to delete the temporary file on my XP system.

    • Snozzle's

      I went ahead and put the script in and I would like to say; very nice :-)

       

      Thank you.

       

      Snozzle's 

    • acrobat

      Fenton,

       

      Thanks for the great script!  It really works well but I'd like to be able to have the pdf open in a web viewer of Filemaker.  I know it can view pdf files but I'm unsure how to load the external file address into a web viewer on the page of interest.  Have you tried to do this yourself?  Solutions? I am now to the Web Viewer and am not sure whether I can simply set the URL to "file://$pdfpath", also I'm unsure about the exact syntax to get the result into the web window on any particular page.

       

      Thanks for any help! 

    • Fenton Jones

      This can fairly easily be done. You just have to pay some attention to the differences in the path syntax between a FileMaker syntax file path and a Web Viewer syntax file path (which is not really a "FileMaker" path, as it also works with a web browser). 

       

      An absolute (as opposed to relative) FileMaker syntax path begins with: "filemac:/" or "filewin:/". It has only 1 slash; which is included in Get (TemporaryPath), so you don't really notice it in the calculation.

       

      A URL path has just "file://", no "mac" or "win", and 2 slashes. otherwise the paths are the same. So you'd need to change the calculation for the web viewer to have that instead. 

       

      P.S. The Web Viewer will also work if you cause the file in the Temporary Folder to be deleted immediately (after a pause). But it is more touchy than a separate PDF application (which loads it into RAM). If you leave the layout and return, the Web Viewer will redraw, and will be blank.

    • acrobat

      Thanks again Fenton,

       

      To build on your previous example, here is my current code.

       

      Allow User Abort [Off] 

      Set Variable [ $filepath; Case ( Abs ( Get ( SystemPlatform )) = 1; "filemac:"; "filewin:" ) & Get ( TemporaryPath ) & "fm_file.pdf" ]

      Export Field Contents [ container field; "$filepath"]

      Set Web Viewer [Object name: "d1"; URL: "file://" & $filepath] 

      Pause/resume Script [Indefinitely] 

      Export Field Contents ["$filepath"]

       

      Note that my version of Filemaker (9) puts quotes around "$filepath".  I'm not sure if this makes a difference or how to get Filemaker not to put the quotes.  Also, I am a bit fuzzy about the use of Set Web Viewer; specifically what the "d1" designation refers to.  In my layout, I have assigned the Web Viewer display to display: "file://" & $filepath

       

      I like the fact that the web viewer will only hold things temporarily.  This is one of its main strengths.

       

      Thanks again for your insights!

       

      -Rob