Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP/OO将ODT转换为PDF_Php_Windows_Pdf_Odt - Fatal编程技术网

使用PHP/OO将ODT转换为PDF

使用PHP/OO将ODT转换为PDF,php,windows,pdf,odt,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; }

我目前正在尝试从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);
如图所示,我已经设法将其转换为PDF/A-1a,但是它仍然没有保留所使用的字体。如果我在OpenOffice的GUI中转换它,那么字体将保留。怎么了

更新:我决定停止转换为PDF格式,使用PHP中的exec()将odt无声打印到带有Open Office的打印机上


另请注意,请确保关闭打印机驱动程序上的字体替换,以防止在打印到PostScript打印机时出现任何字体替换。

请先使用此库将ODT转换为HTML(以保持格式)

然后使用此库将html转换为pdf

我想我不支持这么容易从html转换,所以有一个FPDF插件

这里是插件的链接


当提到OO时,如果您是指开放式办公室,请参考开放式办公室。因为我认为在处理面向对象的编程语言时,很容易认为您的意思是“面向对象”。运行open/libre-office cmd工具怎么样?libreoffice--headless--invisible--nologo--nofirststartwizard--convert to pdf--outdir testx old_file.odt