示例#1
0
 /**
  * Save PhpWord to file.
  *
  * @param string $filename Name of the file to save as
  * @return void
  */
 public function save($filename = null)
 {
     $fileHandle = parent::prepareForSave($filename);
     //  PDF settings
     $paperSize = strtoupper('A4');
     $orientation = strtoupper('portrait');
     //  Create PDF
     $pdf = new \mpdf();
     $pdf->_setPageSize($paperSize, $orientation);
     $pdf->addPage($orientation);
     // Write document properties
     $phpWord = $this->getPhpWord();
     $docProps = $phpWord->getDocInfo();
     $pdf->setTitle($docProps->getTitle());
     $pdf->setAuthor($docProps->getCreator());
     $pdf->setSubject($docProps->getSubject());
     $pdf->setKeywords($docProps->getKeywords());
     $pdf->setCreator($docProps->getCreator());
     $pdf->writeHTML($this->getContent());
     //  Write to file
     fwrite($fileHandle, $pdf->output($filename, 'S'));
     parent::restoreStateAfterSave($fileHandle);
 }