libreofficeChajian.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * 用libreoffice相关linux和win都可以用
  4. */
  5. class libreofficeChajian extends Chajian{
  6. /**
  7. * 转pdf
  8. */
  9. public function filetopdf($fileid)
  10. {
  11. $path = getconfig('libreoffice_path');
  12. if(isempt($path))return returnerror('未配置libreoffice的路径');
  13. $frs = m('file')->getone($fileid);
  14. if(!$frs)return returnerror('文件不存在');
  15. $filepath = $frs['filepath'];
  16. $pdfpath = $frs['pdfpath'];
  17. if(!isempt($pdfpath) && file_exists($pdfpath))return returnerror('已经转化过了');;
  18. $fpath = ''.ROOT_PATH.'/'.$filepath.'';
  19. $outdir = substr($fpath,0, strripos($fpath,'/'));
  20. if(contain(PHP_OS,'WIN')){
  21. $cmd = '"'.str_ireplace('LibreOffice','libreoffice',$path).'\program\soffice.exe"';
  22. $fpath = str_replace('/','\\', $fpath);
  23. $outdir = str_replace('/','\\', $outdir);
  24. }else{
  25. $cmd = $path;
  26. }
  27. $cmd .=' --headless --invisible --convert-to pdf:writer_pdf_Export "'.$fpath.'" --outdir "'.$outdir.'"';
  28. return c('rockqueue')->pushcmd($cmd);
  29. }
  30. }
粤ICP备19079148号