> endobj'; $objects[] = '2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj'; $objects[] = '3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >> endobj'; $objects[] = '4 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj'; $objects[] = '5 0 obj << /Length ' . $len . " >> stream\n" . $stream . "\nendstream endobj"; $pdf = "%PDF-1.4\n"; $offs = []; foreach ( $objects as $obj ) { $offs[] = strlen( $pdf ); $pdf .= $obj . "\n"; } $xref = strlen( $pdf ); $pdf .= "xref\n0 " . ( count( $objects ) + 1 ) . "\n"; $pdf .= "0000000000 65535 f \n"; foreach ( $offs as $off ) { $pdf .= str_pad( (string) $off, 10, '0', STR_PAD_LEFT ) . " 00000 n \n"; } $pdf .= 'trailer << /Size ' . ( count( $objects ) + 1 ) . ' /Root 1 0 R >> startxref ' . $xref . "\n%%EOF"; return $pdf; } /** * Escape text for PDF string literals. * * @param string $text Raw text. * @return string */ private static function escape( $text ) { $text = wp_strip_all_tags( html_entity_decode( $text, ENT_QUOTES, 'UTF-8' ) ); if ( function_exists( 'iconv' ) ) { $converted = iconv( 'UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $text ); if ( false !== $converted ) { $text = $converted; } } return str_replace( [ '\\', '(', ')' ], [ '\\\\', '\\(', '\\)' ], $text ); } }