setIsRemoteEnabled(true); $options->set('defaultFont', 'Helvetica'); $options->set("isPhpEnabled", true); $options->set('enable_html5_parser',true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper($format, $orientation); $dompdf->render(); $content = $dompdf->output(); if ($pdfA) { $tmp = self::getTMPName(); file_put_contents($tmp,$content); unset($content); if (file_exists($tmp)) { $content = self::convertPDFtoPDFA($tmp); unlink($tmp); } } if (!empty($content)) { return $content; } return false; } public static function getPDFWithTCPDF($html,$format="A4",$orientation="portrait",$pdfA=true,$footer = false) { switch($orientation) { case "landscape": $orientation = "L"; break; default: $orientation = "P"; } if ($footer) { $class= "TCPDFwFooter"; } else { $class= "TCPDF"; } $pdf = new $class($orientation, PDF_UNIT, $format, true, 'UTF-8', false, true); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetFont('helvetica', '', 8, '', true); if ($footer) { $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); } $pdf->AddPage(); $pdf->WriteHTML(utf8_encode($html)); $pdf->lastPage(); $tmp = self::getTMPName(); $pdf->Output($tmp,"F"); if (file_exists($tmp)) { if ($pdfA) { $content = self::convertPDFtoPDFA($tmp); } else { $content = file_get_contents($tmp); } unlink($tmp); if (!empty($content)) { return $content; } return false; } } public static function getPDFWithWKHTML($html,$format="A4",$orientation="portrait",$pdfA=true) { return self::getPDFWithDOMPDF($html,$format,$orientation,$pdfA); $html = self::cleanHTML($html); $tmp = self::getTMPName(); file_put_contents($tmp.".html",$html); if (file_exists($tmp.".html")) { $cmd = "wkhtmltopdf -s {$format} -O ".ucfirst($orientation)." {$tmp}.html {$tmp}.pdf"; exec($cmd); unlink($tmp.".html"); if (file_exists($tmp.".pdf")) { if($pdfA) { $content = self::convertPDFtoPDFA($tmp.".pdf"); } else { $content = file_get_contents($tmp.".pdf"); } unlink($tmp.".pdf"); if (!empty($content)) { return $content; } } } return false; } public static function getPHPOfficeInstance($html) { $html = self::cleanHTML($html); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $internalErrors = libxml_use_internal_errors(true); $dom->loadHTML($html,LIBXML_NOERROR); libxml_use_internal_errors($internalErrors); $dom->formatOutput = true; $html = $dom->saveXML($dom->documentElement); $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html); return $phpWord; } public static function generateWord($html,$fileName = "export") { $phpWord = static::getPHPOfficeInstance($html); header("Content-Description: File Transfer"); header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); header('Content-Disposition: attachment;filename="'.$fileName.'.docx"'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('php://output'); return true; } public static function generateODT($html,$fileName = "export") { $phpWord = static::getPHPOfficeInstance($html); header("Content-Description: File Transfer"); header("Content-Type: application/vnd.oasis.opendocument.text"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); header('Content-Disposition: attachment;filename="'.$fileName.'.odt"'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText'); $objWriter->save('php://output'); return true; } } ?>