加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AIR调用外部程序代码

发布时间:2020-12-15 20:09:36 所属栏目:百科 来源:网络整理
导读:原文链接:http://www.zhixing123.cn/ziyuan/14796.html ? 希望能在AIR应用 程序 中调用外部的可执行 程序 ,完成一些其它功能。比如在AIR应用中调用PDF Password Remover移除加密PDF的密码,如调用PDFTK将指定文档进行合并。 解决思路: 1 AIR调用外程序方

原文链接:http://www.zhixing123.cn/ziyuan/14796.html

?

希望能在AIR应用程序中调用外部的可执行程序,完成一些其它功能。比如在AIR应用中调用PDF Password Remover移除加密PDF的密码,如调用PDFTK将指定文档进行合并。
解决思路:
1 AIR调用外程序方法
使用的是AIR2中提供的NativeProcess来调用外部程序,具体的资料可参考Oreilly的《Flex 4 Cookbook》第18章19,20节。在此只列出关键点。
1.1为使程序能支持外部调用,先要修改配置文件xxx-app.xml,在<application>内,比如<id>节点之后添加:
<supportedProfiles>extendedDesktop desktop </supportedProfiles>
其中extendedDesktop desktop顺序不能变换,extendedDesktop需在前。

2 代码示例:
2.1先声明应用程序变量:private var process:NativeProcess;
2.2可通过NativeProcess.isSupported来判断是否支持外部调用如:
if(NativeProcess.isSupported) {
callButton.enabled = true;
} else {
textReceived.text = "NativeProcess not supported.";
}
2.3调用的代码如:
private function callNativeApp():void {
var file:File = File.applicationDirectory;
file = file.resolvePath("NativeApps");
file = file.resolvePath("pdfdecrypt.exe");//外部程序名
var nativeProcessStartupInfo:NativeProcessStartupInfo =new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var v:Vector.<String> = new Vector.<String>();//外部应用程序需要的参数
v.push("-i");
v.push(txtSplit.text+"*.pdf"); //例:pdfdecrypt.exe -i C:NLCDownload*.pdf
nativeProcessStartupInfo.arguments = v;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA,onStandardOutputData);//处理外部程序输出的内容
process.start(nativeProcessStartupInfo);
process.closeInput();
}
private function onStandardOutputData(event:ProgressEvent):void {
textReceived.text = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable );
}

3、外部程序要放在应用程序文件夹的NativeApps文件下,在执行时会自动拷贝到debug下,或是在发布时,也会自动打包到AIR安装包中(使用FLEX)。

附:
1、pdf password remover去除密码命令行参数:(参考:http://www.verypdf.com/pwdremover/document/help.htm)
dfdecrypt -i C:sample.pdf
-i [pdf file name] : decrypt PDF filename or directory.
-o [pdf file name] : PDF file will be generated.
If you not specify the -o parameter,the default output file will overwrite the input PDF file.
2、pdftk合并文档命令行参数:(参考:http://www.pdflabs.com/docs/pdftk-cli-examples/)
pdftk c:NLCDownload*.pdf output combined.pdf

在AIR中调用,如: file = file.resolvePath("NOTEPAD.EXE"); var nativeProcessStartupInfo:NativeProcessStartupInfo=new NativeProcessStartupInfo(); nativeProcessStartupInfo.executable = file; var v:Vector.<String> = new Vector.<String>(); //pdftk *.pdf output all.pdf v.push(txtSplit.text+"*.pdf"); v.push("output"); v.push(txtSplit.text+"all.pdf"); nativeProcessStartupInfo.arguments = v; process = new NativeProcess(); process.start(nativeProcessStartupInfo);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读