These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Setting flashVars in a pdf for use by embedded swf & swf server calls

pauloharaaaa
Registered: Sep 28 2009
Posts: 3

Hi all,

First off apologies for posting this as I am of the belief this has being asked before, but after 3 days of attempts and searches I cannot find any answers, hence I am making this post.

In summary, I am attempting to embed a swf into a pdf. The swf is a chart that is created using data retrieved from a database. The swf requires to have some flashVars passed to it upon creation. In addition, during the lifecycle of the swf uses the values of the passed in flashVars to make calls to a server to retrieve the required data and update the displayed charts.

The areas I am struggling are, first setting the flashVars. Or better put finding an example of how the flashVars can be set. Currently I am using Adobe Acrobat 9 Pro extended. When I drag the swf into the pdf I am presented with a dialog that has a 'flash' tab. I select this and enter what I would normally pass to the swf (note at the moment I'm hardcoding the ID and url of the flashVars as my goal is not a proof of concept that the swf can be embedded and function). I then save and open the pdf expecting the swf to execute and display the charts but nothing happens. I presume either, it can't make the server calls and is failing or I am not passing the flashVars correctliy (i.e. using the wrong syntax). Can anyone advise on if the syntax is correct or not? (I couldn't find any examples online).

caseID=10001&url=case_home

Plus, I can not find out if it is even possible for the embedded swf in the pdf can make server calls? Can someone answer this, just to let myself know if it is possible or not.

Any help is much appreciated.
Paul.

My Product Information:
Acrobat Pro Extended 9.0, Windows
pauloharaaaa
Registered: Sep 28 2009
Posts: 3
Hi all,

I've made some progress, so thought I would provide an update in the hope that some may be able to help with the latest issue I’ve ran into.

In summary, through the use of placing many alert.show() statements into my swf I've managed to confirm that I am correctly passing the flashVars to the swf through the pdf.

I've also manage to identify that the swf is not correctly connecting to the server and retrieving the data required by the swf to render the chart. That is, the tag is failing, as when the below is called, the ‘processServerFault(event)’ is executed (I placed an alert.show() in here to confirm). It is not entering the processOverviewAndPrioritiesData(). Plus, I also placed breakpoints in the relevant server code and these are never hit.In an attempt to get this working I hardcoded the url set in the HTTPService to be:
overviewServerData.url =http://localhost:9080/Curam/servlet/FileDownload?pageID=GraphOverviewDetails&caseID=10001. As mentioned above though this still did not work.Hence, is anyone aware of (or have a suggestion) a step I am missing here? Is there something I need to know to get the swf in the pdf to call out to a server?

Should I be passing the url through ExternalInterface to some JavaScript function in the PDF that will make a call to the server? I’ll be honest, the last part is very much guess work as I’ve no idea where to start to do that (on the embedding the javascript to the pdf and making a server call), but I would welcome all other suggestions.

Thanks for any help.
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
You're using FlashVars correctly, and the embedded SWF can indeed connect using Flex's HTTPService object to an external domain, but if you're running the PDF anywhere else (including on your local drive) it connects only if that domain has a crossdomain.xml file.

See http://www.adobe.com/devnet/flex/quickstart/httpservice/ for a bit more info and a sample app - if you're sneaky you can save a copy of the sample SWF from that page (look at the source for the URL) and in Acrobat Pro Extended you can use "create...PDF from file" to bring it in - you'll find after all the trust manager messages, the picture streams appear on the PDF just as they do on the website.

You don't want to go near Javascript proxies, as Javascript cannot access the Web in the same way Flash can. Do all your networking in the SWF, and use Javascript only if you need to access local files (but passing data across the sandbox fence is not a silent process, for obvious reasons) or converse with other objects on the PDF document.
ginko-dave
Registered: Oct 2 2009
Posts: 4
I followed this thread with high interest since I am trying to do a very similar thing, except I am not using Flex, I am using ActionScript 3 for my coding. Also, my SWF currently runs in a browser and I am trying to move it into the PDF.

I have a SWF with a AS3 program that loads XML and other content from a web server. I am trying to insert this SWF into the PDF so that the content can display when the PDF is viewed.

One main difference between my document and pauloharaaaa's is that I don't know which content I am going to display until view-time, not when the PDF is created. IE the SWF finds out which content from a dynamic parameter I attach to the SWF when it is loaded, the SWF specified in the HTML snippet looks like:

UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
ginko-dave: Currently the only place you can set FlashVars is in the resources tab for a rich media annotation, and there's no JS function to change them, so in your case I'd rewrite the AS3 to expose an initializing function using ExternalInterface.addCallBack, that you can call from the PDF using document-level Javascript and the rich media annotation's .callAS method. Send your ID code in via that function call, then your SWF can load the dynamic content - and the Javascript can collect the ID from wherever it needs to, either hard-coded into the PDF, collected from a forms file, or extracted from the URL with a bit of pattern matching.
ginko-dave
Registered: Oct 2 2009
Posts: 4
Ahh. I did have a previous iteration of the SWF that had the callback using ExternalInterface -- connecting to JS in the HTML wrapper -- so I am familiar with how to do that. Good idea.

I had not thought about having the embedded SWF get the ID via JS, because I didn't think JS was anywhere in the picture. I thought the PDF was a standalone entity.... and PDF does not have a JS component, does it? Help me understand where the JS sits, and I can run with it from there.

My use case:

a) I send the PDF file via email attachment. In email I state, please open the PDF for more information.
b) User clicks on PDF, it launches into Acrobat Reader -- and opens
c) The PDF 'displays' the SWF -- the first thing the SWF needs is the ID of some custom content
d) Here's where I am fuzzy: The SWF has registered the ExternalInterface -- but where is the JS to interface with it?

Thank you a ton for responding. I really appreciate your insight.
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
There's a Javascript engine inside Acrobat and Reader (actually two, but you only care about one) - so as far as the SWF is concerned, the destination of EI calls is that document-level Javascript runtime and not the world outside the PDF. You can define code to run at doc level using Acrobat: menu, advanced, document processing, document JS. Give the script any random name, press ADD, then delete the template function and stick in whatever you want - it'll run when the PDF opens, assuming the user hasn't disabled JS (so your SWF needs to be able to cope if that's the case).

If the PDF's going by email, then you can't look at the URL or anything about the email message to pass variables into Reader (JS in Reader can converse with a web browser when the PDF is embedded in HTML, but not with an email application when it's an attachment). So you'd have to hardwire the ID into the doc-level JS for each copy of the PDF, however there is a way to automate insertion of doc-level code into many PDFs using the same Acrobat JS runtime, but reading a batch processing "sequence" (a JS file in all but name).

If for example you wanted doc-level JS to call the exposed "ping" function within the first SWF on the first page of your document, you'd need to add this to your PDF:

var returnVal = this.getAnnotsRichMedia(0)[0].callAS("ping", pass,whatever,variables,you,want);


To add that to a range of files you can use batch sequences (menu..advanced..doc processing..batch) and the "addScript" method, which just sets the script name and contents as you'd do via the UI:

this.addScript("BatchCode","this.getAnnotsRichMedia(0)[0].callAS('ping', pass,whatever,variables,you,want);");

(careful about the quotes!)

You can of course write sequences so the code written to the PDF is different each time, to add your set of ID numbers. There's loads of stuff about batch processing in the help files and a video from Tim Plumer [url=http://www.acrobatusers.com/tutorials/2008/06/a9video_using_batch_processing_for_tasks]at this link[/url].
ginko-dave
Registered: Oct 2 2009
Posts: 4
You have provided alot of great information and I really appreciate it. I will get this implemented.

I have to fly out of town in a few hours on business -- and won't be back until Thursday. I am telling you so that you don't think this fell off the table. Unfortunately, I need to travel.

I will be able to try some of this while gone, but will be scheduled fairly heavily and am not sure if I can get the entire test program built. Regardless, I will let you know through this thread how it turns out.

Again, thank you. Your assistance is fantastic.