PHP code example of yowfung / officetopdf

1. Go to this page and download the library: Download yowfung/officetopdf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yowfung / officetopdf example snippets



use YowFung\OfficeToPdf\OfficeToPdf;

class Controller
{
  	public function Example() 
    {
  		$outdir  = __DIR__.'/../resource/pdfs/';	 //输出文件夹
  		$filedir = __DIR__.'/../resource/docs/';
  		$filenames = scandir($filedir);			 //待转换文件
  	
  		$office = new OfficeToPdf($filenames, $outdir, true);
  		$success_row = $office->convertToPdf();		 //执行转换操作
  	
  		echo '成功转换'.$success_row.'个文件。';
    }
}

$office = new OfficeToPdf();
$office->setOutputDir('directory path...');

$office = new OfficeToPdf();

//重置源文件路径列表
$office->setFileArray(
	'filename1',
  	'filename2',
  	'...'
);

//向原有文件路径列表中添加单个文件
$office->addFile('filename');

//向原有文件路径列表中添加多个文件
$offcie->addToFileArray(
	'filename1',
  	'filename2',
  	'...'
);

$office = new OfficeToPdf();
$filename = 'xxxx.doc';
if(!$office->checkFormat($filename))
  	echo 'File format is not be supported';