Skip to content


Adobe Air: PDF Cross-Scripting

It would be great if I could send data directly to a PDF within the Air environment.This would help with data presentation and offer a much needed print method.
The problem:

The only cross-scripting solution I could find is this. However it uses flex and it’s simply not very informative.

The solution:

The code posted below isn’t meant to be a guide. Simply showing that code used isn’t elaborate or complicated. Your best bet is to download the example and pick it apart.

The files:

Demo AIR Package.

Demo SOURCE Files.

notes:

  1. This project was created with Aptana.
  2. You’ll need Acrobat Reader 9.1 or 8.1.3 due to this Acrobat bug.

The Adobe Air function:

function init(postData) 

{ 

pdfObject = document.getElementById("PDFObj"); 

try { 

pdfObject.postMessage(["testMsg", postData]); 

} 

catch (e) 

{ 

alert( "Error: \n name = " + e.name + "\n message = " + e.message ); 

} 

}

The document level javascript code:

this.disclosed = true;

var testName = "";

if(this.hostContainer){

  try{

    this.hostContainer.messageHandler={

myDoc:this,

onDisclose:function(){return true;},

onMessage:function(stringArray){

var cmd=stringArray[0];

try{

if(cmd=="testMsg"){

var name = this.myDoc.getField("test");

name.value = stringArray[1];

}

}catch(e){

this.hostContainer.postMessage(

["error thrown in onMessage:",e.message]);

}

},

onError:function(e){

this.hostContainer.postMessage(["onError: ",e.message]);

}

    }

  }catch(e){

    this.hostContainer.postMessage(["Error thrown in setup:",e.message]);

  }

}else{

    app.alert("unable to set up hostContainer: this.hostContainer="

        +this.hostContainer+" this.external="+this.external);

}
5 Total TweetBacks: (Tweet this post)
  • en: Well, which should I worry about most? Being fat or aving a low sperm count? Don't matter because my fat prevent me gettin l**d anyway! 07/14/09 06:48pm
  • en: National Health downgraded on price: FFO, or funds from operations, is a key gauge of performance by real estate.. http://digg.com/u18NGq 07/14/09 06:48pm
  • en: I wish I have enough time to reply everybody's mails and messages. I'm so sorry for being so slow. I promise I'll find time or MAKE time! :s 07/14/09 06:48pm
  • en: tuaw WWDC Demo (and sneak peek): SciFly 2, a dogfight app for your iPhone or iPod touch: Filed under: Gaming.. http://tinyurl.com/lxfhtn 07/14/09 06:48pm
  • en: @jilliBABY depends on what you're quitting whether ill let you or not. 07/14/09 06:48pm

Posted in Adobe Air, PDF Scripting.

Tagged with , , .


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. KrisBelucci says

    Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  2. AndrewBoldman says

    Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

Continuing the Discussion

  1. PDF Cross-Scripting using Adobe AIR | Adobe AIR Tutorials linked to this post on April 15, 2009

    [...] on PDF Cross-Scripting using Adobe AIR at [...]