Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Opening a file from a layout in its native App. (Opening a .pdf)

Featured Replies

Hi All,

I have a container field holding a pdf  and would like to run a script upon a button click that opens it in its native program or app. in this case Adobe Reader.

Can anyone help with writing a script for this? I am lost and very new to FMPro.

Cheers

Simon

Simple way is to export to temporary path.

Here's one I use to take a letter sent to a customer, saved in a container, for viewing or printing.  These are the basic steps:
 

Set Variable [$path; Value: Get(TemporaryPath) & "Letter_" & Customers::Name_last & ".pdf"]
Export Field Contents [Customer_contact::Letter; "$path.pdf"; Automatically open]

edit:  corrected typo

Edited by Steve Martino
corrected typo in script

  • Author

Here is the script that I created using your example.

 

Set Variable [ $path; Value:Get(TemporaryPath) & "Order_" & GeneralAccounts::GeneralAccName & ".pdf" ]
Export Field Contents [ PSWorkflow::PSWF_OrderPDF; “file:File[$path].pdf”; Automatically open ]

Unfortunateley the script will only let me place “file:File[$path].pdf” in double speech marks and not just the one at the start of it as your script indicates. I think therefore my script will only name the file File[$path].pdf and not "Order_" & GeneralAccounts::GeneralAccName & ".pdf" .

Any thoughts?

There was a typo in my original.  Should be:

"$path.pdf"

Export Field Contents [ PSWorkflow::PSWF_OrderPDF; “$path.pdf”; Automatically open ]

I don't think so. 

Should be:

Export Field Contents [ PSWorkflow::PSWF_OrderPDF; $path ; Automatically open ]

I copied that line from the script (has the quotes).  But when I look in  Specify Output File dialog, it looks like this:

file:$path.pdf

PS  I cant get your "like this" button to open, throws an error.

 

pdfSS.png

Edited by Steve Martino

Your $path variable should already have the .pdf on the end, and then you can just use $path

I don't believe you can mix variables and text for the Output file.

Agree with webko.

Set Error Capture [ On ]
Set Variable [ $filename; Value:ExportPDF::BaseFileName & ".pdf" ]
Set Variable [ $path; Value:Get( DesktopPath) & $filename ]
Export Field Contents [ ExportPDF::PDFContainer; “$path”; Automatically open ]
Set Variable [ $error; Value:Get( LastError) ]
Set Field [ ExportPDF::ExportResult; $error ]
Commit Records/Requests 

script.png

ExportPDF.fmp12

And if earlier suggestions DID work, you would end up with a file name myFileName.pdf.pdf

On 19 February, 2016 at 0:50 AM, MutantST said:

I have a container field holding a pdf  and would like to run a script upon a button click that opens it in its native program or app. in this case Adobe Reader.

FYI: I would use FireFox or Chromium as PDF-viewer

Edited by ggt667

  • Author

Cheers, for your input everyone. the BruceR script returned this error:

“remote:Print.pdf” could not be created on this disk.  Use a different name, make more room on the disk, unlock it or use a different disk.

and result 800?

Where does the text "remote:Print" come from? Is that the contents of the field you're taking the file name from? That's not going to work: a file name cannot contain a colon or a slash.

Post your file; or print your script to PDF and copy the entire content of the script and post it.

  • Author

Actually, the files path is showing

remote:SmithOrderForm.pdf
FILE:OrderForms/SmithOrderForm.pdf

Would this be because the FMPro File is stored in a dropbox folder?

My guess is because it is an external stored Container field.

  • Author
55 minutes ago, comment said:

You are using the same container field being exported to name the exported file. See: http://www.filemaker.com/help/14/fmp/en/html/func_ref1.32.239.html#1075526

Yeah, that is what I am going for.

1 hour ago, webko said:

My guess is because it is an external stored Container field.

So it looks like I have to have the file stored internally to remove the remote part. Oh well, suppose
I can put up with that.

Will this script work if I use a different file type? say a word doc?

Well, no you don't need to store it internally - you can use the function referenced above to get the values, and then manipulate the data to remove the "remote:" before creating the path...

  • Author
43 minutes ago, webko said:

manipulate the data to remove the "remote:" before creating the path...

Not sure how to do this :/

 

I am just curious: what happens if you double-click the container field?

  • Author

Nothing, sorry. I know, how cool would that of been. I did try it first off but for some reason it does not work.

Do this google search 

site:fmforums.com Extracting Filename from Container link

The file "Extracting Filename from Container link” was  posted in Feb 2010 and is very helpful for see the file paths, In addition, there were several other hits that many also come in handy.

Lee

"Not sure how to do this :/"

Then - for test purposes anyway - just create a new, plain text field and enter text into it and use THAT for your export/open script.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.