我正在使用 COM 将动态创建的 word docx 转换为 PDF。一切都运行良好,但是我们的 c:\windows\temp\ 目录变得非常大(并且我们的 C 驱动器上的磁盘空间有限)。下面是我用来生成 PDF 的代码。有没有办法在文件关闭后删除添加到系统临时目录的临时文件?另外,word doc转换成pdf后,我们就不再需要它了(所以删除tmp文件是否会损坏word doc也没关系)。
/Word Doc to PDF using Com
ini_set("com.allow_dcom","true");
try{
$word = new com('word.application');
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Visible = 0; //don't open word gui on server
$word->DisplayAlerts = 0; //don't allow any alerts to open
//open doc
try{
$doc = $word->Documents->Open(DOC_LOCATION . "temp_doc/" . $filename . ".docx");
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
try{
$doc->ExportAsFixedFormat(DOC_LOCATION . "temp_pdf/" . $filename . ".pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Quit();
$word = null;