is_available() ) { throw new \RuntimeException( 'Dompdf 3.1.6 is unavailable; HTML PDF rendering cannot proceed.' ); } $options = new \Dompdf\Options(); $options->set( 'isRemoteEnabled', false ); $options->set( 'isPhpEnabled', false ); $options->set( 'isJavascriptEnabled', false ); $options->set( 'defaultFont', 'DejaVu Sans' ); $options->set( 'allowedProtocols', array( 'data://' => array( 'rules' => array() ), 'file://' => array( 'rules' => array() ), ) ); $roots = array(); foreach ( array( defined( 'LMCC_PLUGIN_DIR' ) ? LMCC_PLUGIN_DIR : null ) as $root ) { if ( is_string( $root ) && '' !== $root && is_dir( $root ) ) { $real_root = realpath( $root ); $roots[] = false !== $real_root ? $real_root : $root; } } if ( array() !== $roots ) { $options->setChroot( $roots ); } $dompdf = new \Dompdf\Dompdf( $options ); $dompdf->loadHtml( $html, 'UTF-8' ); $dompdf->setPaper( 'A4', 'portrait' ); $dompdf->render(); $pdf = $dompdf->output(); if ( ! is_string( $pdf ) || strlen( $pdf ) < 8 || '%PDF-' !== substr( $pdf, 0, 5 ) ) { throw new \RuntimeException( 'Dompdf did not produce a valid PDF payload.' ); } return $pdf; } }