Res*_*ent 5 php windows pdf odt
我目前正在尝试从 PHP 中静默使用 OO 将 ODT 转换为 PDF。这是代码:
function MakePropertyValue($name, $value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function odt2pdf($doc_url, $output_url){
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
$args = array(MakePropertyValue("Hidden",true,$osm));
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
$aFilterData = array();
$aFilterData [0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$aFilterData [0]->Name = "SelectPdfVersion";
$aFilterData [0]->Value = 1;
$obj = $osm->Bridge_GetValueObject();
$obj->set("[]com.sun.star.beans.PropertyValue",$aFilterData );
$storePDF = array();
$storePDF[0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[0]->Name = "FilterName";
$storePDF[0]->Value = "writer_pdf_Export";
$storePDF[1] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[1]->Name = "FilterData";
$storePDF[1]->Value = $obj;
$oWriterDoc->storeToURL($output_url,$storePDF);
$oWriterDoc->close(true);
}
$output_dir = "C:/wamp/www/cert/pdf/";
$doc_file = "C:/wamp/www/cert/output2.odt";
$pdf_file = "output2.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
odt2pdf($doc_file,$output_file);
Run Code Online (Sandbox Code Playgroud)
正如所见,我已经设法将其转换为 PDF/A-1a,但是它仍然没有保留正在使用的字体。如果我从 Open Office 的 GUI 中转换它,则保留字体。怎么了?
更新:我决定停止转换为 PDF 并使用 PHP 中的 exec() 使用 Open Office 将 odt 静默打印到打印机。
作为附加说明,确保在打印机驱动程序上关闭字体替换,以防止在打印到 PostScript 打印机时出现任何字体替换。
首先尝试使用此库将 ODT 转换为 HTML(以保持格式)
https://gist.github.com/1918801
然后使用这个FPDF库将 html 转换为 pdf
我猜FPDF不会那么容易地支持从 html 转换,所以有一个 FPDF 插件
这是插件的链接
| 归档时间: |
|
| 查看次数: |
4560 次 |
| 最近记录: |