$value ) { fwrite( $handle, "InfoBegin\nInfoKey: $key\nInfoValue: $value\n" ); } fclose( $handle ); // cpdf stamp --> pdftk update_info --> qpdf linearize if ( self::pdftk_check( $pdftmp ) ) { $tmp = tempnam( '/dev/shm', '' ); // get domain via scandir includes/stamp/ $directory = 'includes/stamp'; $domain = strtolower( self::getTitle() ); in_array( $domain .'.pdf', array_diff( scandir( $directory ), array( '..', '.', 'stamp.sh' ) ) ) ? ( $stamp = $domain ) : ( $stamp = 'datasheet.directory' ); /** * cpdf stamp pdf 1st. page; FIXME: pdftk no Info dictionary found * * https://www.php.net/manual/en/function.set-time-limit.php * FIXME: set_time_limit() no work on system() * https://stackoverflow.com/questions/9954794/execute-a-shell-function-with-timeout * timeout 60s * 10 */ system( "timeout 600s cpdf -creator 'Datasheet.Directory' -stamp-on includes/stamp/". $stamp .".pdf $pdftmp 1 -o $tmp &>/dev/null", $status ); if ( !$status ) { // exchange list( $pdftmp, $tmp ) = array( $tmp, $pdftmp ); } /** * pdftk update_info pdf * timeout 60s * 10 */ system( "timeout 600s pdftk $pdftmp update_info $pdfinfo output $tmp &>/dev/null", $status ); if ( !$status ) { // exchange list( $pdftmp, $tmp ) = array( $tmp, $pdftmp ); } unlink( $pdfinfo ); /** * linearized pdf * timeout 60s * 10 */ system( "timeout 600s qpdf --linearize $pdftmp $pdfcache &>/dev/null", $status ); if ( $status ) { // cp -f pdf system( "cp -f $pdftmp $pdfcache &>/dev/null", $status ); } unlink( $tmp ); } else { // cp -f pdf unlink( $pdfinfo ); system( "cp -f $pdftmp $pdfcache &>/dev/null", $status ); } // pdf output by browser header self::browser_header( $pdfcache ); } // throw error throw new Exception( "PHP Warning: \$pdftmp is no exists." ); } // update html to htmlcache static function update_html_output( $basename, $doc, $htmltmp, $htmlcache ) { // create head via doc $head = self::createHead( $doc ); // create html doc $html = ''; $html .= ''. $head['Title'] .''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= file_get_contents( $htmltmp ); $html .= '
'; // add download pdf icon by Chrome: Developer Tools $html .= '
'; // datasheet quote for no bot if ( !self::bot_detection() ) { // @product: insert HTMLForm.php via /mnt/iiic/product include_once( '/mnt/iiic/product/includes/htmlform/HTMLForm.php' ); $html .= get_contact_modal(); //IMP: zoom body $html .= ''; // product: plugin.min.js $html .= ''; $html .= ''; } // end html $html .= ''; file_put_contents( $htmlcache, $html ); // FIXME: PHP Warning: unlink No such file @unlink( $htmltmp ); // file output by html header self::html_header( $htmlcache ); } // pdfmd5 = (32)0: create_pdf_output static function create_pdf_output( $doc ) { // https://mpdf.github.io/fonts-languages/choosing-a-configuration-v7-x.html // to use core fonts only, use 'c' for the mode configuration key: $mpdf = new \Mpdf\Mpdf( [ 'mode' => 'c', 'default_font_size' => 15, 'tempDir' => '/dev/shm' ] ); // 4th | %PDF1.5 | 6.x $mpdf->pdf_version = '1.5'; // doc.details $model = $doc['model']; $manufacturer = $doc['manufacturer']; $description = $doc['description']; $datasheet_link = 'https://www.datasheet.live/'. rawurlencode( $model ) .'-datasheet.html'; $product_link = 'https://www.product.network/'. rawurlencode( $model ) .'-product.html'; // document metadata $mpdf->SetTitle( $_SERVER['HTTP_HOST'] .' '. $model ); $mpdf->SetAuthor( $_SERVER['HTTP_HOST'] ); $mpdf->SetCreator( $_SERVER['HTTP_HOST'] ); $mpdf->SetSubject( $_SERVER['HTTP_HOST'] ); $mpdf->SetKeywords( $_SERVER['HTTP_HOST'] .' '. $description ); // define an html headers/footers $mpdf->defaultheaderfontsize = 12; $mpdf->defaultfooterfontsize = 12; $mpdf->SetHeader( '| '. $model .' |' ); $mpdf->SetFooter( '© {DATE Y} | https://'. strtolower( $_SERVER['HTTP_HOST'] .' |' ) ); // https://www.php.net/manual/en/function.file-get-contents.php // https://www.jsdelivr.com/package/npm/bootstrap $stylesheet = file_get_contents( __DIR__ . '/images/mpdf.css' ); $mpdf->WriteHTML( $stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS ); // html content body // https://mpdf.github.io/css-stylesheets/supported-css.html#common-text-styles $html = <<

$model

$manufacturer

$description

EOF; $mpdf->WriteHTML( $html, \Mpdf\HTMLParserMode::HTML_BODY ); // Adobe Portable Document Format (PDF) header( 'Content-Type: application/pdf' ); // output a pdf file directly to the browser $mpdf->Output(); exit; } } // index.php pdf output $datasheet = new DataSheet(); $datasheet->run();