I would like to display PDF file content within my AIR desktop application.
Usually I used 2 ways to do it: 1) Use the mx:HTML component and set the source path with the url or uri of the PDF file 2) Use an invocation to native process, by example, open Acrobat Reader executable file and pass as parameter the native path of the PD File
<mx:HTML location="files/myfile.pdf" width="100%" height="100%"/>
or
var file:File = File.desktopDirectory.resolvePath("myfile.pdf");
if(HTMLLoader.isSupported && (HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK) && file.exists) {
var url:String = file.url; pdf.load(new URLRequest(url));.
}
else {
trace("handle errors in user friendly way");
}
Another way is like this function
function loadPDF(pdfTitle:String):void {
var request:URLRequest = new URLRequest("myfile.pdf");
var pdf:HTMLLoader = new HTMLLoader();
//set the dimensions
pdf.height = 640;
pdf.width = 900;
//call the load method
pdf.load(request);
//add the HTMLLoader object to the display list to make it visible
addChild(pdf);
}
Note: HTML component is only available in Adobe AIR
The Native way, is through an executable, by example Acrobat Reader executable
private var process:NativeProcess;
private function callNativeApp ( ): void {
var file:File = File. applicationDirectory;
file = file. resolvePath ( "NativeApps" );
if ( Capabilities. os. toLowerCase ( ). indexOf ( "win" ) > - 1 ) {
file = file. resolvePath ( "Windows/acrobat_executable.exe" );
}
else if ( Capabilities. os. toLowerCase ( ). indexOf ( "mac" ) > - 1 ) {
file = file. resolvePath ( "Mac/ acrobat_executable " );
}
else if ( Capabilities. os. toLowerCase ( ). indexOf ( "linux" ) > - 1 ) {
file = file. resolvePath ( "Linux/ acrobat_executable " );
}
//In this example i used the Windows executable parameters
var nativeProcessStartupInfo:NativeProcessStartupInfo =
new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var args:Vector.<String> = new Vector.<String>();
//args.push("path/AcroRd32.exe");
args.push("/p");
args.push("/h");
args.push("%1");
args.push("mypdf.pdf");
nativeProcessStartupInfo.arguments = args;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
process.start(nativeProcessStartupInfo);
process.closeInput();
}
private function onStandardOutputData(event:ProgressEvent):void{
trace(process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
+