我正在使用ajax调用一个php脚本,它将使用PHP的PHP类(在WAMP堆栈上)将DOCX文件转换为PDF。 这里有一个小问题,php做的工作,它转换 定期对文件进行打印并使用下载URL打印json,但是直到Word.Application不会关闭,似乎ajax请求无法管理响应。
所以,有两个问题:
1- Ajax无法管理响应,直到PHP打开的Word.Application完全关闭,即使脚本到达终点
2-Word.Application需要很长时间(有时10-20秒,有时3-4分钟)才能完全关闭
PHP脚本在Windows Server 2003上运行,MS Office在2010上运行,PHP为5.4。 如果我强制关闭WINWORD.exe(Word.Application),则ajax脚本开始管理响应。
ajax电话:
$.ajax({
url: HTTP_ADDRESS+'/url-to-conversion-server/',
type: 'post',
data: postVars,
dataType: 'json',
success: function(response) {
console.log(response);
}
},
error: function(response) {
console.log(response);
},
});
PHP脚本:
$word = new COM('word.application');
$word->Visible = 1;
$word->DisplayAlerts = 0;
$doc = $word->Documents->Open('C:\\path\\to\\file.docx');
$doc->ExportAsFixedFormat('C:\\path\\to\\save\\file.pdf', 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
$word->ActiveDocument->Close(false);
$word->Quit();
unset($word);
exit(json_encode(array('url' => ADDRESS."/path/to/save/file.pdf")));
感谢您的帮助!