One Hat Cyber Team
Your IP:
216.73.216.30
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
proc
/
self
/
root
/
proc
/
thread-self
/
cwd
/
View File Name :
Adapter.tar
GD.php 0000644 00000061132 15111210010 0005530 0 ustar 00 <?php /** * @package dompdf * @link https://github.com/dompdf/dompdf * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ namespace Dompdf\Adapter; use Dompdf\Canvas; use Dompdf\Dompdf; use Dompdf\Helpers; use Dompdf\Image\Cache; /** * Image rendering interface * * Renders to an image format supported by GD (jpeg, gif, png, xpm). * Not super-useful day-to-day but handy nonetheless * * @package dompdf */ class GD implements Canvas { /** * @var Dompdf */ protected $_dompdf; /** * Resource handle for the image * * @var \GdImage|resource */ protected $_img; /** * Resource handle for the image * * @var \GdImage[]|resource[] */ protected $_imgs; /** * Apparent canvas width in pixels * * @var int */ protected $_width; /** * Apparent canvas height in pixels * * @var int */ protected $_height; /** * Actual image width in pixels * * @var int */ protected $_actual_width; /** * Actual image height in pixels * * @var int */ protected $_actual_height; /** * Current page number * * @var int */ protected $_page_number; /** * Total number of pages * * @var int */ protected $_page_count; /** * Image antialias factor * * @var float */ protected $_aa_factor; /** * Allocated colors * * @var array */ protected $_colors; /** * Background color * * @var int */ protected $_bg_color; /** * Background color array * * @var array */ protected $_bg_color_array; /** * Actual DPI * * @var int */ protected $dpi; /** * Amount to scale font sizes * * Font sizes are 72 DPI, GD internally uses 96. Scale them proportionally. * 72 / 96 = 0.75. * * @var float */ const FONT_SCALE = 0.75; /** * @param string|float[] $paper The paper size to use as either a standard paper size (see {@link CPDF::$PAPER_SIZES}) or * an array of the form `[x1, y1, x2, y2]` (typically `[0, 0, width, height]`). * @param string $orientation The paper orientation, either `portrait` or `landscape`. * @param Dompdf|null $dompdf The Dompdf instance. * @param float $aa_factor Anti-aliasing factor, 1 for no AA * @param array $bg_color Image background color: array(r,g,b,a), 0 <= r,g,b,a <= 1 */ public function __construct($paper = "letter", string $orientation = "portrait", ?Dompdf $dompdf = null, float $aa_factor = 1.0, array $bg_color = [1, 1, 1, 0]) { if (is_array($paper)) { $size = array_map("floatval", $paper); } else { $paper = strtolower($paper); $size = CPDF::$PAPER_SIZES[$paper] ?? CPDF::$PAPER_SIZES["letter"]; } if (strtolower($orientation) === "landscape") { [$size[2], $size[3]] = [$size[3], $size[2]]; } if ($dompdf === null) { $this->_dompdf = new Dompdf(); } else { $this->_dompdf = $dompdf; } $this->dpi = $this->get_dompdf()->getOptions()->getDpi(); if ($aa_factor < 1) { $aa_factor = 1; } $this->_aa_factor = $aa_factor; $size[2] *= $aa_factor; $size[3] *= $aa_factor; $this->_width = $size[2] - $size[0]; $this->_height = $size[3] - $size[1]; $this->_actual_width = $this->_upscale($this->_width); $this->_actual_height = $this->_upscale($this->_height); $this->_page_number = $this->_page_count = 0; if (is_null($bg_color) || !is_array($bg_color)) { // Pure white bg $bg_color = [1, 1, 1, 0]; } $this->_bg_color_array = $bg_color; $this->new_page(); } public function get_dompdf() { return $this->_dompdf; } /** * Return the GD image resource * * @return \GdImage|resource */ public function get_image() { return $this->_img; } /** * Return the image's width in pixels * * @return int */ public function get_width() { return round($this->_width / $this->_aa_factor); } /** * Return the image's height in pixels * * @return int */ public function get_height() { return round($this->_height / $this->_aa_factor); } public function get_page_number() { return $this->_page_number; } public function get_page_count() { return $this->_page_count; } /** * Sets the current page number * * @param int $num */ public function set_page_number($num) { $this->_page_number = $num; } public function set_page_count($count) { $this->_page_count = $count; } public function set_opacity(float $opacity, string $mode = "Normal"): void { // FIXME } /** * Allocate a new color. Allocate with GD as needed and store * previously allocated colors in $this->_colors. * * @param array $color The new current color * @return int The allocated color */ protected function _allocate_color($color) { $a = isset($color["alpha"]) ? $color["alpha"] : 1; if (isset($color["c"])) { $color = Helpers::cmyk_to_rgb($color); } list($r, $g, $b) = $color; $r = round($r * 255); $g = round($g * 255); $b = round($b * 255); $a = round(127 - ($a * 127)); // Clip values $r = $r > 255 ? 255 : $r; $g = $g > 255 ? 255 : $g; $b = $b > 255 ? 255 : $b; $a = $a > 127 ? 127 : $a; $r = $r < 0 ? 0 : $r; $g = $g < 0 ? 0 : $g; $b = $b < 0 ? 0 : $b; $a = $a < 0 ? 0 : $a; $key = sprintf("#%02X%02X%02X%02X", $r, $g, $b, $a); if (isset($this->_colors[$key])) { return $this->_colors[$key]; } if ($a != 0) { $this->_colors[$key] = imagecolorallocatealpha($this->get_image(), $r, $g, $b, $a); } else { $this->_colors[$key] = imagecolorallocate($this->get_image(), $r, $g, $b); } return $this->_colors[$key]; } /** * Scales value up to the current canvas DPI from 72 DPI * * @param float $length * @return int */ protected function _upscale($length) { return round(($length * $this->dpi) / 72 * $this->_aa_factor); } /** * Scales value down from the current canvas DPI to 72 DPI * * @param float $length * @return float */ protected function _downscale($length) { return round(($length / $this->dpi * 72) / $this->_aa_factor); } protected function convertStyle(array $style, int $color, int $width): array { $gdStyle = []; if (count($style) === 1) { $style[] = $style[0]; } foreach ($style as $index => $s) { $d = $this->_upscale($s); for ($i = 0; $i < $d; $i++) { for ($j = 0; $j < $width; $j++) { $gdStyle[] = $index % 2 === 0 ? $color : IMG_COLOR_TRANSPARENT; } } } return $gdStyle; } public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt") { // Account for the fact that round and square caps are expected to // extend outwards if ($cap === "round" || $cap === "square") { // Shift line by half width $w = $width / 2; $a = $x2 - $x1; $b = $y2 - $y1; $c = sqrt($a ** 2 + $b ** 2); $dx = $a * $w / $c; $dy = $b * $w / $c; $x1 -= $dx; $x2 -= $dx; $y1 -= $dy; $y2 -= $dy; // Adapt dash pattern if (is_array($style)) { foreach ($style as $index => &$s) { $s = $index % 2 === 0 ? $s + $width : $s - $width; } } } // Scale by the AA factor and DPI $x1 = $this->_upscale($x1); $y1 = $this->_upscale($y1); $x2 = $this->_upscale($x2); $y2 = $this->_upscale($y2); $width = $this->_upscale($width); $c = $this->_allocate_color($color); // Convert the style array if required if (is_array($style) && count($style) > 0) { $gd_style = $this->convertStyle($style, $c, $width); if (!empty($gd_style)) { imagesetstyle($this->get_image(), $gd_style); $c = IMG_COLOR_STYLED; } } imagesetthickness($this->get_image(), $width); imageline($this->get_image(), $x1, $y1, $x2, $y2, $c); } public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt") { // Account for the fact that round and square caps are expected to // extend outwards if ($cap === "round" || $cap === "square") { // Adapt dash pattern if (is_array($style)) { foreach ($style as $index => &$s) { $s = $index % 2 === 0 ? $s + $width : $s - $width; } } } // Scale by the AA factor and DPI $x = $this->_upscale($x); $y = $this->_upscale($y); $w = $this->_upscale($r1 * 2); $h = $this->_upscale($r2 * 2); $width = $this->_upscale($width); // Adapt angles as imagearc counts clockwise $start = 360 - $aend; $end = 360 - $astart; $c = $this->_allocate_color($color); // Convert the style array if required if (is_array($style) && count($style) > 0) { $gd_style = $this->convertStyle($style, $c, $width); if (!empty($gd_style)) { imagesetstyle($this->get_image(), $gd_style); $c = IMG_COLOR_STYLED; } } imagesetthickness($this->get_image(), $width); imagearc($this->get_image(), $x, $y, $w, $h, $start, $end, $c); } public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt") { // Account for the fact that round and square caps are expected to // extend outwards if ($cap === "round" || $cap === "square") { // Adapt dash pattern if (is_array($style)) { foreach ($style as $index => &$s) { $s = $index % 2 === 0 ? $s + $width : $s - $width; } } } // Scale by the AA factor and DPI $x1 = $this->_upscale($x1); $y1 = $this->_upscale($y1); $w = $this->_upscale($w); $h = $this->_upscale($h); $width = $this->_upscale($width); $c = $this->_allocate_color($color); // Convert the style array if required if (is_array($style) && count($style) > 0) { $gd_style = $this->convertStyle($style, $c, $width); if (!empty($gd_style)) { imagesetstyle($this->get_image(), $gd_style); $c = IMG_COLOR_STYLED; } } imagesetthickness($this->get_image(), $width); if ($c === IMG_COLOR_STYLED) { imagepolygon($this->get_image(), [ $x1, $y1, $x1 + $w, $y1, $x1 + $w, $y1 + $h, $x1, $y1 + $h ], $c); } else { imagerectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c); } } public function filled_rectangle($x1, $y1, $w, $h, $color) { // Scale by the AA factor and DPI $x1 = $this->_upscale($x1); $y1 = $this->_upscale($y1); $w = $this->_upscale($w); $h = $this->_upscale($h); $c = $this->_allocate_color($color); imagefilledrectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c); } public function clipping_rectangle($x1, $y1, $w, $h) { // @todo } public function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL) { // @todo } public function clipping_polygon(array $points): void { // @todo } public function clipping_end() { // @todo } public function save() { $this->get_dompdf()->getOptions()->setDpi(72); } public function restore() { $this->get_dompdf()->getOptions()->setDpi($this->dpi); } public function rotate($angle, $x, $y) { // @todo } public function skew($angle_x, $angle_y, $x, $y) { // @todo } public function scale($s_x, $s_y, $x, $y) { // @todo } public function translate($t_x, $t_y) { // @todo } public function transform($a, $b, $c, $d, $e, $f) { // @todo } public function polygon($points, $color, $width = null, $style = [], $fill = false) { // Scale each point by the AA factor and DPI foreach (array_keys($points) as $i) { $points[$i] = $this->_upscale($points[$i]); } $width = isset($width) ? $this->_upscale($width) : null; $c = $this->_allocate_color($color); // Convert the style array if required if (is_array($style) && count($style) > 0 && isset($width) && !$fill) { $gd_style = $this->convertStyle($style, $c, $width); if (!empty($gd_style)) { imagesetstyle($this->get_image(), $gd_style); $c = IMG_COLOR_STYLED; } } imagesetthickness($this->get_image(), isset($width) ? $width : 0); if ($fill) { imagefilledpolygon($this->get_image(), $points, $c); } else { imagepolygon($this->get_image(), $points, $c); } } public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false) { // Scale by the AA factor and DPI $x = $this->_upscale($x); $y = $this->_upscale($y); $d = $this->_upscale(2 * $r); $width = isset($width) ? $this->_upscale($width) : null; $c = $this->_allocate_color($color); // Convert the style array if required if (is_array($style) && count($style) > 0 && isset($width) && !$fill) { $gd_style = $this->convertStyle($style, $c, $width); if (!empty($gd_style)) { imagesetstyle($this->get_image(), $gd_style); $c = IMG_COLOR_STYLED; } } imagesetthickness($this->get_image(), isset($width) ? $width : 0); if ($fill) { imagefilledellipse($this->get_image(), $x, $y, $d, $d, $c); } else { imageellipse($this->get_image(), $x, $y, $d, $d, $c); } } /** * @throws \Exception */ public function image($img, $x, $y, $w, $h, $resolution = "normal") { $img_type = Cache::detect_type($img, $this->get_dompdf()->getHttpContext()); if (!$img_type) { return; } $func_name = "imagecreatefrom$img_type"; if (!function_exists($func_name)) { if (!method_exists(Helpers::class, $func_name)) { throw new \Exception("Function $func_name() not found. Cannot convert $img_type image: $img. Please install the image PHP extension."); } $func_name = [Helpers::class, $func_name]; } $src = @call_user_func($func_name, $img); if (!$src) { return; // Probably should add to $_dompdf_errors or whatever here } // Scale by the AA factor and DPI $x = $this->_upscale($x); $y = $this->_upscale($y); $w = $this->_upscale($w); $h = $this->_upscale($h); $img_w = imagesx($src); $img_h = imagesy($src); imagecopyresampled($this->get_image(), $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h); } public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_spacing = 0.0, $char_spacing = 0.0, $angle = 0.0) { // Scale by the AA factor and DPI $x = $this->_upscale($x); $y = $this->_upscale($y); $size = $this->_upscale($size) * self::FONT_SCALE; $h = round($this->get_font_height_actual($font, $size)); $c = $this->_allocate_color($color); // imagettftext() converts numeric entities to their respective // character. Preserve any originally double encoded entities to be // represented as is. // eg: &#160; will render   rather than its character. $text = preg_replace('/&(#(?:x[a-fA-F0-9]+|[0-9]+);)/', '&\1', $text); $text = mb_encode_numericentity($text, [0x0080, 0xff, 0, 0xff], 'UTF-8'); $font = $this->get_ttf_file($font); // FIXME: word spacing imagettftext($this->get_image(), $size, $angle, $x, $y + $h, $c, $font, $text); } public function javascript($code) { // Not implemented } public function add_named_dest($anchorname) { // Not implemented } public function add_link($url, $x, $y, $width, $height) { // Not implemented } public function add_info(string $label, string $value): void { // N/A } public function set_default_view($view, $options = []) { // N/A } public function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0) { $font = $this->get_ttf_file($font); $size = $this->_upscale($size) * self::FONT_SCALE; // imagettfbbox() converts numeric entities to their respective // character. Preserve any originally double encoded entities to be // represented as is. // eg: &#160; will render   rather than its character. $text = preg_replace('/&(#(?:x[a-fA-F0-9]+|[0-9]+);)/', '&\1', $text); $text = mb_encode_numericentity($text, [0x0080, 0xffff, 0, 0xffff], 'UTF-8'); // FIXME: word spacing list($x1, , $x2) = imagettfbbox($size, 0, $font, $text); // Add additional 1pt to prevent text overflow issues return $this->_downscale($x2 - $x1) + 1; } /** * @param string|null $font * @return string */ public function get_ttf_file($font) { if ($font === null) { $font = ""; } if ( stripos($font, ".ttf") === false ) { $font .= ".ttf"; } if (!file_exists($font)) { $font_metrics = $this->_dompdf->getFontMetrics(); $font = $font_metrics->getFont($this->_dompdf->getOptions()->getDefaultFont()) . ".ttf"; if (!file_exists($font)) { if (strpos($font, "mono")) { $font = $font_metrics->getFont("DejaVu Mono") . ".ttf"; } elseif (strpos($font, "sans") !== false) { $font = $font_metrics->getFont("DejaVu Sans") . ".ttf"; } elseif (strpos($font, "serif")) { $font = $font_metrics->getFont("DejaVu Serif") . ".ttf"; } else { $font = $font_metrics->getFont("DejaVu Sans") . ".ttf"; } } } return $font; } public function get_font_height($font, $size) { $size = $this->_upscale($size) * self::FONT_SCALE; $height = $this->get_font_height_actual($font, $size); return $this->_downscale($height); } /** * @param string $font * @param float $size * * @return float */ protected function get_font_height_actual($font, $size) { $font = $this->get_ttf_file($font); $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); // FIXME: word spacing list(, $y2, , , , $y1) = imagettfbbox($size, 0, $font, "MXjpqytfhl"); // Test string with ascenders, descenders and caps return ($y2 - $y1) * $ratio; } public function get_font_baseline($font, $size) { $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); return $this->get_font_height($font, $size) / $ratio; } public function new_page() { $this->_page_number++; $this->_page_count++; $this->_img = imagecreatetruecolor($this->_actual_width, $this->_actual_height); $this->_bg_color = $this->_allocate_color($this->_bg_color_array); imagealphablending($this->_img, true); imagesavealpha($this->_img, true); imagefill($this->_img, 0, 0, $this->_bg_color); $this->_imgs[] = $this->_img; } public function open_object() { // N/A } public function close_object() { // N/A } public function add_object() { // N/A } public function page_script($callback): void { // N/A } public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { // N/A } public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []) { // N/A } /** * Streams the image to the client. * * @param string $filename The filename to present to the client. * @param array $options Associative array: 'type' => jpeg|jpg|png; 'quality' => 0 - 100 (JPEG only); * 'page' => Number of the page to output (defaults to the first); 'Attachment': 1 or 0 (default 1). */ public function stream($filename, $options = []) { if (headers_sent()) { die("Unable to stream image: headers already sent"); } if (!isset($options["type"])) $options["type"] = "png"; if (!isset($options["Attachment"])) $options["Attachment"] = true; $type = strtolower($options["type"]); switch ($type) { case "jpg": case "jpeg": $contentType = "image/jpeg"; $extension = ".jpg"; break; case "png": default: $contentType = "image/png"; $extension = ".png"; break; } header("Cache-Control: private"); header("Content-Type: $contentType"); $filename = str_replace(["\n", "'"], "", basename($filename, ".$type")) . $extension; $attachment = $options["Attachment"] ? "attachment" : "inline"; header(Helpers::buildContentDispositionHeader($attachment, $filename)); $this->_output($options); flush(); } /** * Returns the image as a string. * * @param array $options Associative array: 'type' => jpeg|jpg|png; 'quality' => 0 - 100 (JPEG only); * 'page' => Number of the page to output (defaults to the first). * @return string */ public function output($options = []) { ob_start(); $this->_output($options); return ob_get_clean(); } /** * Outputs the image stream directly. * * @param array $options Associative array: 'type' => jpeg|jpg|png; 'quality' => 0 - 100 (JPEG only); * 'page' => Number of the page to output (defaults to the first). */ protected function _output($options = []) { if (!isset($options["type"])) $options["type"] = "png"; if (!isset($options["page"])) $options["page"] = 1; $type = strtolower($options["type"]); if (isset($this->_imgs[$options["page"] - 1])) { $img = $this->_imgs[$options["page"] - 1]; } else { $img = $this->_imgs[0]; } // Perform any antialiasing if ($this->_aa_factor != 1) { $dst_w = round($this->_actual_width / $this->_aa_factor); $dst_h = round($this->_actual_height / $this->_aa_factor); $dst = imagecreatetruecolor($dst_w, $dst_h); imagecopyresampled($dst, $img, 0, 0, 0, 0, $dst_w, $dst_h, $this->_actual_width, $this->_actual_height); } else { $dst = $img; } switch ($type) { case "jpg": case "jpeg": if (!isset($options["quality"])) { $options["quality"] = 75; } imagejpeg($dst, null, $options["quality"]); break; case "png": default: imagepng($dst); break; } if ($this->_aa_factor != 1) { imagedestroy($dst); } } } CPDF.php 0000644 00000065673 15111210011 0005771 0 ustar 00 <?php /** * @package dompdf * @link https://github.com/dompdf/dompdf * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ // FIXME: Need to sanity check inputs to this class namespace Dompdf\Adapter; use Dompdf\Canvas; use Dompdf\Dompdf; use Dompdf\Exception; use Dompdf\FontMetrics; use Dompdf\Helpers; use Dompdf\Image\Cache; use FontLib\Exception\FontNotFoundException; /** * PDF rendering interface * * Dompdf\Adapter\CPDF provides a simple stateless interface to the stateful one * provided by the Cpdf class. * * Unless otherwise mentioned, all dimensions are in points (1/72 in). The * coordinate origin is in the top left corner, and y values increase * downwards. * * See {@link http://www.ros.co.nz/pdf/} for more complete documentation * on the underlying {@link Cpdf} class. * * @package dompdf */ class CPDF implements Canvas { /** * Dimensions of paper sizes in points * * @var array */ static $PAPER_SIZES = [ "4a0" => [0.0, 0.0, 4767.87, 6740.79], "2a0" => [0.0, 0.0, 3370.39, 4767.87], "a0" => [0.0, 0.0, 2383.94, 3370.39], "a1" => [0.0, 0.0, 1683.78, 2383.94], "a2" => [0.0, 0.0, 1190.55, 1683.78], "a3" => [0.0, 0.0, 841.89, 1190.55], "a4" => [0.0, 0.0, 595.28, 841.89], "a5" => [0.0, 0.0, 419.53, 595.28], "a6" => [0.0, 0.0, 297.64, 419.53], "a7" => [0.0, 0.0, 209.76, 297.64], "a8" => [0.0, 0.0, 147.40, 209.76], "a9" => [0.0, 0.0, 104.88, 147.40], "a10" => [0.0, 0.0, 73.70, 104.88], "b0" => [0.0, 0.0, 2834.65, 4008.19], "b1" => [0.0, 0.0, 2004.09, 2834.65], "b2" => [0.0, 0.0, 1417.32, 2004.09], "b3" => [0.0, 0.0, 1000.63, 1417.32], "b4" => [0.0, 0.0, 708.66, 1000.63], "b5" => [0.0, 0.0, 498.90, 708.66], "b6" => [0.0, 0.0, 354.33, 498.90], "b7" => [0.0, 0.0, 249.45, 354.33], "b8" => [0.0, 0.0, 175.75, 249.45], "b9" => [0.0, 0.0, 124.72, 175.75], "b10" => [0.0, 0.0, 87.87, 124.72], "c0" => [0.0, 0.0, 2599.37, 3676.54], "c1" => [0.0, 0.0, 1836.85, 2599.37], "c2" => [0.0, 0.0, 1298.27, 1836.85], "c3" => [0.0, 0.0, 918.43, 1298.27], "c4" => [0.0, 0.0, 649.13, 918.43], "c5" => [0.0, 0.0, 459.21, 649.13], "c6" => [0.0, 0.0, 323.15, 459.21], "c7" => [0.0, 0.0, 229.61, 323.15], "c8" => [0.0, 0.0, 161.57, 229.61], "c9" => [0.0, 0.0, 113.39, 161.57], "c10" => [0.0, 0.0, 79.37, 113.39], "ra0" => [0.0, 0.0, 2437.80, 3458.27], "ra1" => [0.0, 0.0, 1729.13, 2437.80], "ra2" => [0.0, 0.0, 1218.90, 1729.13], "ra3" => [0.0, 0.0, 864.57, 1218.90], "ra4" => [0.0, 0.0, 609.45, 864.57], "sra0" => [0.0, 0.0, 2551.18, 3628.35], "sra1" => [0.0, 0.0, 1814.17, 2551.18], "sra2" => [0.0, 0.0, 1275.59, 1814.17], "sra3" => [0.0, 0.0, 907.09, 1275.59], "sra4" => [0.0, 0.0, 637.80, 907.09], "letter" => [0.0, 0.0, 612.00, 792.00], "half-letter" => [0.0, 0.0, 396.00, 612.00], "legal" => [0.0, 0.0, 612.00, 1008.00], "ledger" => [0.0, 0.0, 1224.00, 792.00], "tabloid" => [0.0, 0.0, 792.00, 1224.00], "executive" => [0.0, 0.0, 521.86, 756.00], "folio" => [0.0, 0.0, 612.00, 936.00], "commercial #10 envelope" => [0.0, 0.0, 684.00, 297.00], "catalog #10 1/2 envelope" => [0.0, 0.0, 648.00, 864.00], "8.5x11" => [0.0, 0.0, 612.00, 792.00], "8.5x14" => [0.0, 0.0, 612.00, 1008.00], "11x17" => [0.0, 0.0, 792.00, 1224.00], ]; /** * The Dompdf object * * @var Dompdf */ protected $_dompdf; /** * Instance of Cpdf class * * @var \Dompdf\Cpdf */ protected $_pdf; /** * PDF width, in points * * @var float */ protected $_width; /** * PDF height, in points * * @var float */ protected $_height; /** * Current page number * * @var int */ protected $_page_number; /** * Total number of pages * * @var int */ protected $_page_count; /** * Array of pages for accessing after rendering is initially complete * * @var array */ protected $_pages; /** * Currently-applied opacity level (0 - 1) * * @var float */ protected $_current_opacity = 1; public function __construct($paper = "letter", string $orientation = "portrait", ?Dompdf $dompdf = null) { if (is_array($paper)) { $size = array_map("floatval", $paper); } else { $paper = strtolower($paper); $size = self::$PAPER_SIZES[$paper] ?? self::$PAPER_SIZES["letter"]; } if (strtolower($orientation) === "landscape") { [$size[2], $size[3]] = [$size[3], $size[2]]; } if ($dompdf === null) { $this->_dompdf = new Dompdf(); } else { $this->_dompdf = $dompdf; } $this->_pdf = new \Dompdf\Cpdf( $size, true, $this->_dompdf->getOptions()->getFontCache(), $this->_dompdf->getOptions()->getTempDir() ); $this->_pdf->addInfo("Producer", sprintf("%s + CPDF", $this->_dompdf->version)); $time = substr_replace(date('YmdHisO'), '\'', -2, 0) . '\''; $this->_pdf->addInfo("CreationDate", "D:$time"); $this->_pdf->addInfo("ModDate", "D:$time"); $this->_width = $size[2] - $size[0]; $this->_height = $size[3] - $size[1]; $this->_page_number = $this->_page_count = 1; $this->_pages = [$this->_pdf->getFirstPageId()]; } public function get_dompdf() { return $this->_dompdf; } /** * Returns the Cpdf instance * * @return \Dompdf\Cpdf */ public function get_cpdf() { return $this->_pdf; } public function add_info(string $label, string $value): void { $this->_pdf->addInfo($label, $value); } /** * Opens a new 'object' * * While an object is open, all drawing actions are recorded in the object, * as opposed to being drawn on the current page. Objects can be added * later to a specific page or to several pages. * * The return value is an integer ID for the new object. * * @see CPDF::close_object() * @see CPDF::add_object() * * @return int */ public function open_object() { $ret = $this->_pdf->openObject(); $this->_pdf->saveState(); return $ret; } /** * Reopens an existing 'object' * * @see CPDF::open_object() * @param int $object the ID of a previously opened object */ public function reopen_object($object) { $this->_pdf->reopenObject($object); $this->_pdf->saveState(); } /** * Closes the current 'object' * * @see CPDF::open_object() */ public function close_object() { $this->_pdf->restoreState(); $this->_pdf->closeObject(); } /** * Adds a specified 'object' to the document * * $object int specifying an object created with {@link * CPDF::open_object()}. $where can be one of: * - 'add' add to current page only * - 'all' add to every page from the current one onwards * - 'odd' add to all odd numbered pages from now on * - 'even' add to all even numbered pages from now on * - 'next' add the object to the next page only * - 'nextodd' add to all odd numbered pages from the next one * - 'nexteven' add to all even numbered pages from the next one * * @see Cpdf::addObject() * * @param int $object * @param string $where */ public function add_object($object, $where = 'all') { $this->_pdf->addObject($object, $where); } /** * Stops the specified 'object' from appearing in the document. * * The object will stop being displayed on the page following the current * one. * * @param int $object */ public function stop_object($object) { $this->_pdf->stopObject($object); } /** * Serialize the pdf object's current state for retrieval later */ public function serialize_object($id) { return $this->_pdf->serializeObject($id); } public function reopen_serialized_object($obj) { return $this->_pdf->restoreSerializedObject($obj); } //........................................................................ public function get_width() { return $this->_width; } public function get_height() { return $this->_height; } public function get_page_number() { return $this->_page_number; } public function get_page_count() { return $this->_page_count; } /** * Sets the current page number * * @param int $num */ public function set_page_number($num) { $this->_page_number = $num; } public function set_page_count($count) { $this->_page_count = $count; } /** * Sets the stroke color * * See {@link Style::set_color()} for the format of the color array. * * @param array $color */ protected function _set_stroke_color($color) { $this->_pdf->setStrokeColor($color); $alpha = isset($color["alpha"]) ? $color["alpha"] : 1; $alpha *= $this->_current_opacity; $this->_set_line_transparency("Normal", $alpha); } /** * Sets the fill colour * * See {@link Style::set_color()} for the format of the colour array. * * @param array $color */ protected function _set_fill_color($color) { $this->_pdf->setColor($color); $alpha = isset($color["alpha"]) ? $color["alpha"] : 1; $alpha *= $this->_current_opacity; $this->_set_fill_transparency("Normal", $alpha); } /** * Sets line transparency * @see Cpdf::setLineTransparency() * * Valid blend modes are (case-sensitive): * * Normal, Multiply, Screen, Overlay, Darken, Lighten, * ColorDodge, ColorBurn, HardLight, SoftLight, Difference, * Exclusion * * @param string $mode the blending mode to use * @param float $opacity 0.0 fully transparent, 1.0 fully opaque */ protected function _set_line_transparency($mode, $opacity) { $this->_pdf->setLineTransparency($mode, $opacity); } /** * Sets fill transparency * @see Cpdf::setFillTransparency() * * Valid blend modes are (case-sensitive): * * Normal, Multiply, Screen, Overlay, Darken, Lighten, * ColorDogde, ColorBurn, HardLight, SoftLight, Difference, * Exclusion * * @param string $mode the blending mode to use * @param float $opacity 0.0 fully transparent, 1.0 fully opaque */ protected function _set_fill_transparency($mode, $opacity) { $this->_pdf->setFillTransparency($mode, $opacity); } /** * Sets the line style * * @see Cpdf::setLineStyle() * * @param float $width * @param string $cap * @param string $join * @param array $dash */ protected function _set_line_style($width, $cap, $join, $dash) { $this->_pdf->setLineStyle($width, $cap, $join, $dash); } public function set_opacity(float $opacity, string $mode = "Normal"): void { $this->_set_line_transparency($mode, $opacity); $this->_set_fill_transparency($mode, $opacity); $this->_current_opacity = $opacity; } public function set_default_view($view, $options = []) { array_unshift($options, $view); call_user_func_array([$this->_pdf, "openHere"], $options); } /** * Remaps y coords from 4th to 1st quadrant * * @param float $y * @return float */ protected function y($y) { return $this->_height - $y; } public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt") { $this->_set_stroke_color($color); $this->_set_line_style($width, $cap, "", $style); $this->_pdf->line($x1, $this->y($y1), $x2, $this->y($y2)); $this->_set_line_transparency("Normal", $this->_current_opacity); } public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt") { $this->_set_stroke_color($color); $this->_set_line_style($width, $cap, "", $style); $this->_pdf->ellipse($x, $this->y($y), $r1, $r2, 0, 8, $astart, $aend, false, false, true, false); $this->_set_line_transparency("Normal", $this->_current_opacity); } public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt") { $this->_set_stroke_color($color); $this->_set_line_style($width, $cap, "", $style); $this->_pdf->rectangle($x1, $this->y($y1) - $h, $w, $h); $this->_set_line_transparency("Normal", $this->_current_opacity); } public function filled_rectangle($x1, $y1, $w, $h, $color) { $this->_set_fill_color($color); $this->_pdf->filledRectangle($x1, $this->y($y1) - $h, $w, $h); $this->_set_fill_transparency("Normal", $this->_current_opacity); } public function clipping_rectangle($x1, $y1, $w, $h) { $this->_pdf->clippingRectangle($x1, $this->y($y1) - $h, $w, $h); } public function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL) { $this->_pdf->clippingRectangleRounded($x1, $this->y($y1) - $h, $w, $h, $rTL, $rTR, $rBR, $rBL); } public function clipping_polygon(array $points): void { // Adjust y values for ($i = 1; $i < count($points); $i += 2) { $points[$i] = $this->y($points[$i]); } $this->_pdf->clippingPolygon($points); } public function clipping_end() { $this->_pdf->clippingEnd(); } public function save() { $this->_pdf->saveState(); } public function restore() { $this->_pdf->restoreState(); } public function rotate($angle, $x, $y) { $this->_pdf->rotate($angle, $x, $y); } public function skew($angle_x, $angle_y, $x, $y) { $this->_pdf->skew($angle_x, $angle_y, $x, $y); } public function scale($s_x, $s_y, $x, $y) { $this->_pdf->scale($s_x, $s_y, $x, $y); } public function translate($t_x, $t_y) { $this->_pdf->translate($t_x, $t_y); } public function transform($a, $b, $c, $d, $e, $f) { $this->_pdf->transform([$a, $b, $c, $d, $e, $f]); } public function polygon($points, $color, $width = null, $style = [], $fill = false) { $this->_set_fill_color($color); $this->_set_stroke_color($color); if (!$fill && isset($width)) { $this->_set_line_style($width, "square", "miter", $style); } // Adjust y values for ($i = 1; $i < count($points); $i += 2) { $points[$i] = $this->y($points[$i]); } $this->_pdf->polygon($points, $fill); $this->_set_fill_transparency("Normal", $this->_current_opacity); $this->_set_line_transparency("Normal", $this->_current_opacity); } public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false) { $this->_set_fill_color($color); $this->_set_stroke_color($color); if (!$fill && isset($width)) { $this->_set_line_style($width, "round", "round", $style); } $this->_pdf->ellipse($x, $this->y($y), $r, 0, 0, 8, 0, 360, 1, $fill); $this->_set_fill_transparency("Normal", $this->_current_opacity); $this->_set_line_transparency("Normal", $this->_current_opacity); } /** * Convert image to a PNG image * * @param string $image_url * @param string $type * * @return string|null The url of the newly converted image */ protected function _convert_to_png($image_url, $type) { $filename = Cache::getTempImage($image_url); if ($filename !== null && file_exists($filename)) { return $filename; } $func_name = "imagecreatefrom$type"; set_error_handler([Helpers::class, "record_warnings"]); if (!function_exists($func_name)) { if (!method_exists(Helpers::class, $func_name)) { throw new Exception("Function $func_name() not found. Cannot convert $type image: $image_url. Please install the image PHP extension."); } $func_name = [Helpers::class, $func_name]; } try { $im = call_user_func($func_name, $image_url); if ($im) { imageinterlace($im, false); $tmp_dir = $this->_dompdf->getOptions()->getTempDir(); $tmp_name = @tempnam($tmp_dir, "{$type}_dompdf_img_"); @unlink($tmp_name); $filename = "$tmp_name.png"; imagepng($im, $filename); imagedestroy($im); } else { $filename = null; } } finally { restore_error_handler(); } if ($filename !== null) { Cache::addTempImage($image_url, $filename); } return $filename; } public function image($img, $x, $y, $w, $h, $resolution = "normal") { [$width, $height, $type] = Helpers::dompdf_getimagesize($img, $this->get_dompdf()->getHttpContext()); $debug_png = $this->_dompdf->getOptions()->getDebugPng(); if ($debug_png) { print "[image:$img|$width|$height|$type]"; } switch ($type) { case "jpeg": if ($debug_png) { print '!!!jpg!!!'; } $this->_pdf->addJpegFromFile($img, $x, $this->y($y) - $h, $w, $h); break; case "webp": /** @noinspection PhpMissingBreakStatementInspection */ case "gif": /** @noinspection PhpMissingBreakStatementInspection */ case "bmp": if ($debug_png) print "!!!{$type}!!!"; $img = $this->_convert_to_png($img, $type); if ($img === null) { if ($debug_png) print '!!!conversion to PDF failed!!!'; $this->image(Cache::$broken_image, $x, $y, $w, $h, $resolution); break; } case "png": if ($debug_png) print '!!!png!!!'; $this->_pdf->addPngFromFile($img, $x, $this->y($y) - $h, $w, $h); break; case "svg": if ($debug_png) print '!!!SVG!!!'; $this->_pdf->addSvgFromFile($img, $x, $this->y($y) - $h, $w, $h); break; default: if ($debug_png) print '!!!unknown!!!'; } } public function select($x, $y, $w, $h, $font, $size, $color = [0, 0, 0], $opts = []) { $pdf = $this->_pdf; $font .= ".afm"; $pdf->selectFont($font); if (!isset($pdf->acroFormId)) { $pdf->addForm(); } $ft = \Dompdf\Cpdf::ACROFORM_FIELD_CHOICE; $ff = \Dompdf\Cpdf::ACROFORM_FIELD_CHOICE_COMBO; $id = $pdf->addFormField($ft, rand(), $x, $this->y($y) - $h, $x + $w, $this->y($y), $ff, $size, $color); $pdf->setFormFieldOpt($id, $opts); } public function textarea($x, $y, $w, $h, $font, $size, $color = [0, 0, 0]) { $pdf = $this->_pdf; $font .= ".afm"; $pdf->selectFont($font); if (!isset($pdf->acroFormId)) { $pdf->addForm(); } $ft = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT; $ff = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT_MULTILINE; $pdf->addFormField($ft, rand(), $x, $this->y($y) - $h, $x + $w, $this->y($y), $ff, $size, $color); } public function input($x, $y, $w, $h, $type, $font, $size, $color = [0, 0, 0]) { $pdf = $this->_pdf; $font .= ".afm"; $pdf->selectFont($font); if (!isset($pdf->acroFormId)) { $pdf->addForm(); } $ft = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT; $ff = 0; switch ($type) { case 'text': $ft = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT; break; case 'password': $ft = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT; $ff = \Dompdf\Cpdf::ACROFORM_FIELD_TEXT_PASSWORD; break; case 'submit': $ft = \Dompdf\Cpdf::ACROFORM_FIELD_BUTTON; break; } $pdf->addFormField($ft, rand(), $x, $this->y($y) - $h, $x + $w, $this->y($y), $ff, $size, $color); } public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { $pdf = $this->_pdf; $this->_set_fill_color($color); $is_font_subsetting = $this->_dompdf->getOptions()->getIsFontSubsettingEnabled(); $pdf->selectFont($font . '.afm', '', true, $is_font_subsetting); $pdf->addText($x, $this->y($y) - $pdf->getFontHeight($size), $size, $text, $angle, $word_space, $char_space); $this->_set_fill_transparency("Normal", $this->_current_opacity); } public function javascript($code) { $this->_pdf->addJavascript($code); } //........................................................................ public function add_named_dest($anchorname) { $this->_pdf->addDestination($anchorname, "Fit"); } public function add_link($url, $x, $y, $width, $height) { $y = $this->y($y) - $height; if (strpos($url, '#') === 0) { // Local link $name = substr($url, 1); if ($name) { $this->_pdf->addInternalLink($name, $x, $y, $x + $width, $y + $height); } } else { $this->_pdf->addLink($url, $x, $y, $x + $width, $y + $height); } } /** * @throws FontNotFoundException */ public function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0) { $this->_pdf->selectFont($font, '', true, $this->_dompdf->getOptions()->getIsFontSubsettingEnabled()); return $this->_pdf->getTextWidth($size, $text, $word_spacing, $char_spacing); } /** * @throws FontNotFoundException */ public function get_font_height($font, $size) { $options = $this->_dompdf->getOptions(); $this->_pdf->selectFont($font, '', true, $options->getIsFontSubsettingEnabled()); return $this->_pdf->getFontHeight($size) * $options->getFontHeightRatio(); } /*function get_font_x_height($font, $size) { $this->_pdf->selectFont($font); $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); return $this->_pdf->getFontXHeight($size) * $ratio; }*/ /** * @throws FontNotFoundException */ public function get_font_baseline($font, $size) { $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); return $this->get_font_height($font, $size) / $ratio; } /** * Processes a callback or script on every page. * * The callback function receives the four parameters `int $pageNumber`, * `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics`, in * that order. If a script is passed as string, the variables `$PAGE_NUM`, * `$PAGE_COUNT`, `$pdf`, and `$fontMetrics` are available instead. Passing * a script as string is deprecated and will be removed in a future version. * * This function can be used to add page numbers to all pages after the * first one, for example. * * @param callable|string $callback The callback function or PHP script to process on every page */ public function page_script($callback): void { if (is_string($callback)) { $this->processPageScript(function ( int $PAGE_NUM, int $PAGE_COUNT, self $pdf, FontMetrics $fontMetrics ) use ($callback) { eval($callback); }); return; } $this->processPageScript($callback); } public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { $this->processPageScript(function (int $pageNumber, int $pageCount) use ($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle) { $text = str_replace( ["{PAGE_NUM}", "{PAGE_COUNT}"], [$pageNumber, $pageCount], $text ); $this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); }); } public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []) { $this->processPageScript(function () use ($x1, $y1, $x2, $y2, $color, $width, $style) { $this->line($x1, $y1, $x2, $y2, $color, $width, $style); }); } /** * @return int */ public function new_page() { $this->_page_number++; $this->_page_count++; $ret = $this->_pdf->newPage(); $this->_pages[] = $ret; return $ret; } protected function processPageScript(callable $callback): void { $pageNumber = 1; foreach ($this->_pages as $pid) { $this->reopen_object($pid); $fontMetrics = $this->_dompdf->getFontMetrics(); $callback($pageNumber, $this->_page_count, $this, $fontMetrics); $this->close_object(); $pageNumber++; } } public function stream($filename = "document.pdf", $options = []) { if (headers_sent()) { die("Unable to stream pdf: headers already sent"); } if (!isset($options["compress"])) $options["compress"] = true; if (!isset($options["Attachment"])) $options["Attachment"] = true; $debug = !$options['compress']; $tmp = ltrim($this->_pdf->output($debug)); header("Cache-Control: private"); header("Content-Type: application/pdf"); header("Content-Length: " . mb_strlen($tmp, "8bit")); $filename = str_replace(["\n", "'"], "", basename($filename, ".pdf")) . ".pdf"; $attachment = $options["Attachment"] ? "attachment" : "inline"; header(Helpers::buildContentDispositionHeader($attachment, $filename)); echo $tmp; flush(); } public function output($options = []) { if (!isset($options["compress"])) $options["compress"] = true; $debug = !$options['compress']; return $this->_pdf->output($debug); } /** * Returns logging messages generated by the Cpdf class * * @return string */ public function get_messages() { return $this->_pdf->messages; } } PDFLib.php 0000644 00000123712 15111210011 0006302 0 ustar 00 <?php /** * @package dompdf * @link https://github.com/dompdf/dompdf * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ namespace Dompdf\Adapter; use Dompdf\Canvas; use Dompdf\Dompdf; use Dompdf\Exception; use Dompdf\FontMetrics; use Dompdf\Helpers; use Dompdf\Image\Cache; /** * PDF rendering interface * * Dompdf\Adapter\PDFLib provides a simple, stateless interface to the one * provided by PDFLib. * * Unless otherwise mentioned, all dimensions are in points (1/72 in). * The coordinate origin is in the top left corner and y values * increase downwards. * * See {@link http://www.pdflib.com/} for more complete documentation * on the underlying PDFlib functions. * * @package dompdf */ class PDFLib implements Canvas { /** * Dimensions of paper sizes in points * * @var array */ public static $PAPER_SIZES = []; // Set to Dompdf\Adapter\CPDF::$PAPER_SIZES below. /** * Whether to create PDFs in memory or on disk * * @var bool */ static $IN_MEMORY = true; /** * Saves the major version of PDFLib for compatibility requests * * @var null|int */ protected static $MAJOR_VERSION = null; /** * Transforms the list of native fonts into PDFLib compatible names (casesensitive) * * @var array */ public static $nativeFontsTpPDFLib = [ "courier" => "Courier", "courier-bold" => "Courier-Bold", "courier-oblique" => "Courier-Oblique", "courier-boldoblique" => "Courier-BoldOblique", "helvetica" => "Helvetica", "helvetica-bold" => "Helvetica-Bold", "helvetica-oblique" => "Helvetica-Oblique", "helvetica-boldoblique" => "Helvetica-BoldOblique", "times" => "Times-Roman", "times-roman" => "Times-Roman", "times-bold" => "Times-Bold", "times-italic" => "Times-Italic", "times-bolditalic" => "Times-BoldItalic", "symbol" => "Symbol", "zapfdinbats" => "ZapfDingbats", "zapfdingbats" => "ZapfDingbats", ]; /** * @var \Dompdf\Dompdf */ protected $_dompdf; /** * Instance of PDFLib class * * @var \PDFLib */ protected $_pdf; /** * Name of temporary file used for PDFs created on disk * * @var string */ protected $_file; /** * PDF width, in points * * @var float */ protected $_width; /** * PDF height, in points * * @var float */ protected $_height; /** * Last fill color used * * @var array */ protected $_last_fill_color; /** * Last stroke color used * * @var array */ protected $_last_stroke_color; /** * The current opacity level * * @var float|null */ protected $_current_opacity; /** * Cache of image handles * * @var array */ protected $_imgs; /** * Cache of font handles * * @var array */ protected $_fonts; /** * Cache of fontFile checks * * @var array */ protected $_fontsFiles; /** * List of objects (templates) to add to multiple pages * * @var array */ protected $_objs; /** * List of gstate objects created for this PDF (for reuse) * * @var array */ protected $_gstates = []; /** * Current page number * * @var int */ protected $_page_number; /** * Total number of pages * * @var int */ protected $_page_count; /** * Array of pages for accessing after rendering is initially complete * * @var array */ protected $_pages; public function __construct($paper = "letter", string $orientation = "portrait", ?Dompdf $dompdf = null) { if (is_array($paper)) { $size = array_map("floatval", $paper); } else { $paper = strtolower($paper); $size = self::$PAPER_SIZES[$paper] ?? self::$PAPER_SIZES["letter"]; } if (strtolower($orientation) === "landscape") { [$size[2], $size[3]] = [$size[3], $size[2]]; } $this->_width = $size[2] - $size[0]; $this->_height = $size[3] - $size[1]; if ($dompdf === null) { $this->_dompdf = new Dompdf(); } else { $this->_dompdf = $dompdf; } $this->_pdf = new \PDFLib(); $license = $dompdf->getOptions()->getPdflibLicense(); if (strlen($license) > 0) { $this->setPDFLibParameter("license", $license); } if ($this->getPDFLibMajorVersion() < 10) { $this->setPDFLibParameter("textformat", "utf8"); } if ($this->getPDFLibMajorVersion() >= 7) { $this->setPDFLibParameter("errorpolicy", "return"); // $this->_pdf->set_option('logging={filename=' . \APP_PATH . '/logs/pdflib.log classes={api=1 warning=2}}'); // $this->_pdf->set_option('errorpolicy=exception'); } else { $this->setPDFLibParameter("fontwarning", "false"); } $searchPath = $this->_dompdf->getOptions()->getFontDir(); if (empty($searchPath) === false) { $this->_pdf->set_option('searchpath={' . $searchPath . '}'); } // fetch PDFLib version information for the producer field $this->_pdf->set_info("Producer Addendum", sprintf("%s + PDFLib %s", $dompdf->version, $this->getPDFLibMajorVersion())); // Silence pedantic warnings about missing TZ settings $tz = @date_default_timezone_get(); date_default_timezone_set("UTC"); $this->_pdf->set_info("Date", date("Y-m-d")); date_default_timezone_set($tz); if (self::$IN_MEMORY) { $this->_pdf->begin_document("", ""); } else { $tmp_dir = $this->_dompdf->getOptions()->getTempDir(); $tmp_name = @tempnam($tmp_dir, "libdompdf_pdf_"); @unlink($tmp_name); $this->_file = "$tmp_name.pdf"; $this->_pdf->begin_document($this->_file, ""); } $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); $this->_page_number = $this->_page_count = 1; $this->_imgs = []; $this->_fonts = []; $this->_objs = []; } function get_dompdf() { return $this->_dompdf; } /** * Close the pdf */ protected function _close() { $this->_place_objects(); // Close all pages $this->_pdf->suspend_page(""); for ($p = 1; $p <= $this->_page_count; $p++) { $this->_pdf->resume_page("pagenumber=$p"); $this->_pdf->end_page_ext(""); } $this->_pdf->end_document(""); } /** * Returns the PDFLib instance * * @return PDFLib */ public function get_pdflib() { return $this->_pdf; } public function add_info(string $label, string $value): void { $this->_pdf->set_info($label, $value); } /** * Opens a new 'object' (template in PDFLib-speak) * * While an object is open, all drawing actions are recorded to the * object instead of being drawn on the current page. Objects can * be added later to a specific page or to several pages. * * The return value is an integer ID for the new object. * * @see PDFLib::close_object() * @see PDFLib::add_object() * * @return int */ public function open_object() { $this->_pdf->suspend_page(""); if ($this->getPDFLibMajorVersion() >= 7) { $ret = $this->_pdf->begin_template_ext($this->_width, $this->_height, null); } else { $ret = $this->_pdf->begin_template($this->_width, $this->_height); } $this->_pdf->save(); $this->_objs[$ret] = ["start_page" => $this->_page_number]; return $ret; } /** * Reopen an existing object (NOT IMPLEMENTED) * PDFLib does not seem to support reopening templates. * * @param int $object the ID of a previously opened object * * @throws Exception * @return void */ public function reopen_object($object) { throw new Exception("PDFLib does not support reopening objects."); } /** * Close the current template * * @see PDFLib::open_object() */ public function close_object() { $this->_pdf->restore(); if ($this->getPDFLibMajorVersion() >= 7) { $this->_pdf->end_template_ext($this->_width, $this->_height); } else { $this->_pdf->end_template(); } $this->_pdf->resume_page("pagenumber=" . $this->_page_number); } /** * Adds the specified object to the document * * $where can be one of: * - 'add' add to current page only * - 'all' add to every page from the current one onwards * - 'odd' add to all odd numbered pages from now on * - 'even' add to all even numbered pages from now on * - 'next' add the object to the next page only * - 'nextodd' add to all odd numbered pages from the next one * - 'nexteven' add to all even numbered pages from the next one * * @param int $object the object handle returned by open_object() * @param string $where */ public function add_object($object, $where = 'all') { if (mb_strpos($where, "next") !== false) { $this->_objs[$object]["start_page"]++; $where = str_replace("next", "", $where); if ($where == "") { $where = "add"; } } $this->_objs[$object]["where"] = $where; } /** * Stops the specified template from appearing in the document. * * The object will stop being displayed on the page following the * current one. * * @param int $object */ public function stop_object($object) { if (!isset($this->_objs[$object])) { return; } $start = $this->_objs[$object]["start_page"]; $where = $this->_objs[$object]["where"]; // Place the object on this page if required if ($this->_page_number >= $start && (($this->_page_number % 2 == 0 && $where === "even") || ($this->_page_number % 2 == 1 && $where === "odd") || ($where === "all")) ) { $this->_pdf->fit_image($object, 0, 0, ""); } $this->_objs[$object] = null; unset($this->_objs[$object]); } /** * Add all active objects to the current page */ protected function _place_objects() { foreach ($this->_objs as $obj => $props) { $start = $props["start_page"]; $where = $props["where"]; // Place the object on this page if required if ($this->_page_number >= $start && (($this->_page_number % 2 == 0 && $where === "even") || ($this->_page_number % 2 == 1 && $where === "odd") || ($where === "all")) ) { $this->_pdf->fit_image($obj, 0, 0, ""); } } } public function get_width() { return $this->_width; } public function get_height() { return $this->_height; } public function get_page_number() { return $this->_page_number; } public function get_page_count() { return $this->_page_count; } /** * @param $num */ public function set_page_number($num) { $this->_page_number = (int)$num; } public function set_page_count($count) { $this->_page_count = (int)$count; } /** * Sets the line style * * @param float $width * @param string $cap * @param string $join * @param array $dash */ protected function _set_line_style($width, $cap, $join, $dash) { if (!is_array($dash)) { $dash = []; } // Work around PDFLib limitation with 0 dash length: // Value 0 for option 'dasharray' is too small (minimum 1.5e-05) foreach ($dash as &$d) { if ($d == 0) { $d = 1.5e-5; } } if (count($dash) === 1) { $dash[] = $dash[0]; } if ($this->getPDFLibMajorVersion() >= 9) { if (count($dash) > 1) { $this->_pdf->set_graphics_option("dasharray={" . implode(" ", $dash) . "}"); } else { $this->_pdf->set_graphics_option("dasharray=none"); } } else { if (count($dash) > 1) { $this->_pdf->setdashpattern("dasharray={" . implode(" ", $dash) . "}"); } else { $this->_pdf->setdash(0, 0); } } switch ($join) { case "miter": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linejoin=0'); } else { $this->_pdf->setlinejoin(0); } break; case "round": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linejoin=1'); } else { $this->_pdf->setlinejoin(1); } break; case "bevel": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linejoin=2'); } else { $this->_pdf->setlinejoin(2); } break; default: break; } switch ($cap) { case "butt": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linecap=0'); } else { $this->_pdf->setlinecap(0); } break; case "round": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linecap=1'); } else { $this->_pdf->setlinecap(1); } break; case "square": if ($this->getPDFLibMajorVersion() >= 9) { $this->_pdf->set_graphics_option('linecap=2'); } else { $this->_pdf->setlinecap(2); } break; default: break; } $this->_pdf->setlinewidth($width); } /** * Sets the line color * * @param array $color array(r,g,b) */ protected function _set_stroke_color($color) { // TODO: we should check the current PDF stroke color // instead of the cached value if ($this->_last_stroke_color == $color) { // FIXME: do nothing, this optimization is broken by the // stroke being set as a side effect of other operations //return; } $alpha = isset($color["alpha"]) ? $color["alpha"] : 1; if (isset($this->_current_opacity)) { $alpha *= $this->_current_opacity; } $this->_last_stroke_color = $color; if (isset($color[3])) { $type = "cmyk"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], $color[2], $color[3]]; } elseif (isset($color[2])) { $type = "rgb"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], $color[2], null]; } else { $type = "gray"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], null, null]; } $this->_set_stroke_opacity($alpha, "Normal"); $this->_pdf->setcolor("stroke", $type, $c1, $c2, $c3, $c4); } /** * Sets the fill color * * @param array $color array(r,g,b) */ protected function _set_fill_color($color) { // TODO: we should check the current PDF fill color // instead of the cached value if ($this->_last_fill_color == $color) { // FIXME: do nothing, this optimization is broken by the // fill being set as a side effect of other operations //return; } $alpha = isset($color["alpha"]) ? $color["alpha"] : 1; if (isset($this->_current_opacity)) { $alpha *= $this->_current_opacity; } $this->_last_fill_color = $color; if (isset($color[3])) { $type = "cmyk"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], $color[2], $color[3]]; } elseif (isset($color[2])) { $type = "rgb"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], $color[2], null]; } else { $type = "gray"; list($c1, $c2, $c3, $c4) = [$color[0], $color[1], null, null]; } $this->_set_fill_opacity($alpha, "Normal"); $this->_pdf->setcolor("fill", $type, $c1, $c2, $c3, $c4); } /** * Sets the fill opacity * * @param float $opacity * @param string $mode */ public function _set_fill_opacity($opacity, $mode = "Normal") { if ($mode === "Normal" && isset($opacity)) { $this->_set_gstate("opacityfill=$opacity"); } } /** * Sets the stroke opacity * * @param float $opacity * @param string $mode */ public function _set_stroke_opacity($opacity, $mode = "Normal") { if ($mode === "Normal" && isset($opacity)) { $this->_set_gstate("opacitystroke=$opacity"); } } public function set_opacity(float $opacity, string $mode = "Normal"): void { if ($mode === "Normal") { $this->_set_gstate("opacityfill=$opacity opacitystroke=$opacity"); $this->_current_opacity = $opacity; } } /** * Sets the gstate * * @param $gstate_options * @return int */ public function _set_gstate($gstate_options) { if (($gstate = array_search($gstate_options, $this->_gstates)) === false) { $gstate = $this->_pdf->create_gstate($gstate_options); $this->_gstates[$gstate] = $gstate_options; } return $this->_pdf->set_gstate($gstate); } public function set_default_view($view, $options = []) { // TODO // http://www.pdflib.com/fileadmin/pdflib/pdf/manuals/PDFlib-8.0.2-API-reference.pdf /** * fitheight Fit the page height to the window, with the x coordinate left at the left edge of the window. * fitrect Fit the rectangle specified by left, bottom, right, and top to the window. * fitvisible Fit the visible contents of the page (the ArtBox) to the window. * fitvisibleheight Fit the visible contents of the page to the window with the x coordinate left at the left edge of the window. * fitvisiblewidth Fit the visible contents of the page to the window with the y coordinate top at the top edge of the window. * fitwidth Fit the page width to the window, with the y coordinate top at the top edge of the window. * fitwindow Fit the complete page to the window. * fixed */ //$this->setPDFLibParameter("openaction", $view); } /** * Loads a specific font and stores the corresponding descriptor. * * @param string $font * @param string $encoding * @param string $options * * @return int the font descriptor for the font */ protected function _load_font($font, $encoding = null, $options = "") { // Fix for PDFLibs case-sensitive font names $baseFont = basename($font); $isNativeFont = false; if (isset(self::$nativeFontsTpPDFLib[$baseFont])) { $font = self::$nativeFontsTpPDFLib[$baseFont]; $isNativeFont = true; } // Check if the font is a native PDF font // Embed non-native fonts $test = strtolower($baseFont); if (in_array($test, DOMPDF::$nativeFonts)) { $font = basename($font); } else { // Embed non-native fonts $options .= " embedding=true"; } $options .= " autosubsetting=" . ($this->_dompdf->getOptions()->getIsFontSubsettingEnabled() === false ? "false" : "true"); if (is_null($encoding)) { // Unicode encoding is only available for the commerical // version of PDFlib and not PDFlib-Lite if (strlen($this->_dompdf->getOptions()->getPdflibLicense()) > 0) { $encoding = "unicode"; } else { $encoding = "auto"; } } $key = "$font:$encoding:$options"; if (isset($this->_fonts[$key])) { return $this->_fonts[$key]; } // Native fonts are build in, just load it if ($isNativeFont) { $this->_fonts[$key] = $this->_pdf->load_font($font, $encoding, $options); return $this->_fonts[$key]; } $fontOutline = $this->getPDFLibParameter("FontOutline", 1); if ($fontOutline === "" || $fontOutline <= 0) { $families = $this->_dompdf->getFontMetrics()->getFontFamilies(); foreach ($families as $files) { foreach ($files as $file) { $face = basename($file); $afm = null; if (isset($this->_fontsFiles[$face])) { continue; } // Prefer ttfs to afms if (file_exists("$file.ttf")) { $outline = "$file.ttf"; } elseif (file_exists("$file.TTF")) { $outline = "$file.TTF"; } elseif (file_exists("$file.pfb")) { $outline = "$file.pfb"; if (file_exists("$file.afm")) { $afm = "$file.afm"; } } elseif (file_exists("$file.PFB")) { $outline = "$file.PFB"; if (file_exists("$file.AFM")) { $afm = "$file.AFM"; } } else { continue; } $this->_fontsFiles[$face] = true; if ($this->getPDFLibMajorVersion() >= 9) { $this->setPDFLibParameter("FontOutline", '{' . "$face=$outline" . '}'); } else { $this->setPDFLibParameter("FontOutline", "\{$face\}=\{$outline\}"); } if (is_null($afm)) { continue; } if ($this->getPDFLibMajorVersion() >= 9) { $this->setPDFLibParameter("FontAFM", '{' . "$face=$afm" . '}'); } else { $this->setPDFLibParameter("FontAFM", "\{$face\}=\{$afm\}"); } } } } $this->_fonts[$key] = $this->_pdf->load_font($font, $encoding, $options); return $this->_fonts[$key]; } /** * Remaps y coords from 4th to 1st quadrant * * @param float $y * @return float */ protected function y($y) { return $this->_height - $y; } public function line($x1, $y1, $x2, $y2, $color, $width, $style = [], $cap = "butt") { $this->_set_line_style($width, $cap, "", $style); $this->_set_stroke_color($color); $y1 = $this->y($y1); $y2 = $this->y($y2); $this->_pdf->moveto($x1, $y1); $this->_pdf->lineto($x2, $y2); $this->_pdf->stroke(); $this->_set_stroke_opacity($this->_current_opacity, "Normal"); } public function arc($x, $y, $r1, $r2, $astart, $aend, $color, $width, $style = [], $cap = "butt") { $this->_set_line_style($width, $cap, "", $style); $this->_set_stroke_color($color); $y = $this->y($y); $this->_pdf->arc($x, $y, $r1, $astart, $aend); $this->_pdf->stroke(); $this->_set_stroke_opacity($this->_current_opacity, "Normal"); } public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap = "butt") { $this->_set_stroke_color($color); $this->_set_line_style($width, $cap, "", $style); $y1 = $this->y($y1) - $h; $this->_pdf->rect($x1, $y1, $w, $h); $this->_pdf->stroke(); $this->_set_stroke_opacity($this->_current_opacity, "Normal"); } public function filled_rectangle($x1, $y1, $w, $h, $color) { $this->_set_fill_color($color); $y1 = $this->y($y1) - $h; $this->_pdf->rect(floatval($x1), floatval($y1), floatval($w), floatval($h)); $this->_pdf->fill(); $this->_set_fill_opacity($this->_current_opacity, "Normal"); } public function clipping_rectangle($x1, $y1, $w, $h) { $this->_pdf->save(); $y1 = $this->y($y1) - $h; $this->_pdf->rect(floatval($x1), floatval($y1), floatval($w), floatval($h)); $this->_pdf->clip(); } public function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL) { if ($this->getPDFLibMajorVersion() < 9) { //TODO: add PDFLib7 support $this->clipping_rectangle($x1, $y1, $w, $h); return; } $this->_pdf->save(); // we use 0,0 for the base coordinates for the path points // since we're drawing the path at the $x1,$y1 coordinates $path = 0; //start: left edge, top end $path = $this->_pdf->add_path_point($path, 0, 0 - $rTL + $h, "move", ""); // line: left edge, bottom end $path = $this->_pdf->add_path_point($path, 0, 0 + $rBL, "line", ""); // curve: bottom-left corner if ($rBL > 0) { $path = $this->_pdf->add_path_point($path, 0 + $rBL, 0, "elliptical", "radius=$rBL clockwise=false"); } // line: bottom edge, left end $path = $this->_pdf->add_path_point($path, 0 - $rBR + $w, 0, "line", ""); // curve: bottom-right corner if ($rBR > 0) { $path = $this->_pdf->add_path_point($path, 0 + $w, 0 + $rBR, "elliptical", "radius=$rBR clockwise=false"); } // line: right edge, top end $path = $this->_pdf->add_path_point($path, 0 + $w, 0 - $rTR + $h, "line", ""); // curve: top-right corner if ($rTR > 0) { $path = $this->_pdf->add_path_point($path, 0 - $rTR + $w, 0 + $h, "elliptical", "radius=$rTR clockwise=false"); } // line: top edge, left end $path = $this->_pdf->add_path_point($path, 0 + $rTL, 0 + $h, "line", ""); // curve: top-left corner if ($rTL > 0) { $path = $this->_pdf->add_path_point($path, 0, 0 - $rTL + $h, "elliptical", "radius=$rTL clockwise=false"); } $this->_pdf->draw_path($path, $x1, $this->_height-$y1-$h, "clip=true"); } public function clipping_polygon(array $points): void { $this->_pdf->save(); $y = $this->y(array_pop($points)); $x = array_pop($points); $this->_pdf->moveto($x, $y); while (count($points) > 1) { $y = $this->y(array_pop($points)); $x = array_pop($points); $this->_pdf->lineto($x, $y); } $this->_pdf->closepath(); $this->_pdf->clip(); } public function clipping_end() { $this->_pdf->restore(); } public function save() { $this->_pdf->save(); } function restore() { $this->_pdf->restore(); } public function rotate($angle, $x, $y) { $pdf = $this->_pdf; $pdf->translate($x, $this->_height - $y); $pdf->rotate(-$angle); $pdf->translate(-$x, -$this->_height + $y); } public function skew($angle_x, $angle_y, $x, $y) { $pdf = $this->_pdf; $pdf->translate($x, $this->_height - $y); $pdf->skew($angle_y, $angle_x); // Needs to be inverted $pdf->translate(-$x, -$this->_height + $y); } public function scale($s_x, $s_y, $x, $y) { $pdf = $this->_pdf; $pdf->translate($x, $this->_height - $y); $pdf->scale($s_x, $s_y); $pdf->translate(-$x, -$this->_height + $y); } public function translate($t_x, $t_y) { $this->_pdf->translate($t_x, -$t_y); } public function transform($a, $b, $c, $d, $e, $f) { $this->_pdf->concat($a, $b, $c, $d, $e, $f); } public function polygon($points, $color, $width = null, $style = [], $fill = false) { $this->_set_fill_color($color); $this->_set_stroke_color($color); if (!$fill && isset($width)) { $this->_set_line_style($width, "square", "miter", $style); } $y = $this->y(array_pop($points)); $x = array_pop($points); $this->_pdf->moveto($x, $y); while (count($points) > 1) { $y = $this->y(array_pop($points)); $x = array_pop($points); $this->_pdf->lineto($x, $y); } if ($fill) { $this->_pdf->fill(); } else { $this->_pdf->closepath_stroke(); } $this->_set_fill_opacity($this->_current_opacity, "Normal"); $this->_set_stroke_opacity($this->_current_opacity, "Normal"); } public function circle($x, $y, $r, $color, $width = null, $style = [], $fill = false) { $this->_set_fill_color($color); $this->_set_stroke_color($color); if (!$fill && isset($width)) { $this->_set_line_style($width, "round", "round", $style); } $y = $this->y($y); $this->_pdf->circle($x, $y, $r); if ($fill) { $this->_pdf->fill(); } else { $this->_pdf->stroke(); } $this->_set_fill_opacity($this->_current_opacity, "Normal"); $this->_set_stroke_opacity($this->_current_opacity, "Normal"); } public function image($img, $x, $y, $w, $h, $resolution = "normal") { $w = (int)$w; $h = (int)$h; $img_type = Cache::detect_type($img, $this->get_dompdf()->getHttpContext()); // Strip file:// prefix if (substr($img, 0, 7) === "file://") { $img = substr($img, 7); } if (!isset($this->_imgs[$img])) { if (strtolower($img_type) === "svg") { //FIXME: PDFLib loads SVG but returns error message "Function must not be called in 'page' scope" $image_load_response = $this->_pdf->load_graphics($img_type, $img, ""); } else { $image_load_response = $this->_pdf->load_image($img_type, $img, ""); } if ($image_load_response === 0) { //TODO: should do something with the error message $error = $this->_pdf->get_errmsg(); return; } $this->_imgs[$img] = $image_load_response; } $img = $this->_imgs[$img]; $y = $this->y($y) - $h; if (strtolower($img_type) === "svg") { $this->_pdf->fit_graphics($img, $x, $y, 'boxsize={' . "$w $h" . '} fitmethod=entire'); } else { $this->_pdf->fit_image($img, $x, $y, 'boxsize={' . "$w $h" . '} fitmethod=entire'); } } public function text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_spacing = 0, $char_spacing = 0, $angle = 0) { if ($size == 0) { return; } $fh = $this->_load_font($font); $this->_pdf->setfont($fh, $size); $this->_set_fill_color($color); $y = $this->y($y) - $this->get_font_height($font, $size); $word_spacing = (float)$word_spacing; $char_spacing = (float)$char_spacing; $angle = -(float)$angle; $this->_pdf->fit_textline($text, $x, $y, "rotate=$angle wordspacing=$word_spacing charspacing=$char_spacing "); $this->_set_fill_opacity($this->_current_opacity, "Normal"); } public function javascript($code) { if (strlen($this->_dompdf->getOptions()->getPdflibLicense()) > 0) { $this->_pdf->create_action("JavaScript", $code); } } public function add_named_dest($anchorname) { $this->_pdf->add_nameddest($anchorname, ""); } public function add_link($url, $x, $y, $width, $height) { $y = $this->y($y) - $height; if (strpos($url, '#') === 0) { // Local link $name = substr($url, 1); if ($name) { $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} destname=" . substr($url, 1) . " linewidth=0"); } } else { //TODO: PDFLib::create_action does not permit non-HTTP links for URI actions $action = $this->_pdf->create_action("URI", "url={{$url}}"); // add the annotation only if the action was created if ($action !== 0) { $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={{$url}} action={activate=$action} linewidth=0"); } } } public function get_text_width($text, $font, $size, $word_spacing = 0.0, $letter_spacing = 0.0) { if ($size == 0) { return 0.0; } $fh = $this->_load_font($font); // Determine the additional width due to extra spacing $num_spaces = mb_substr_count($text, " "); $delta = $word_spacing * $num_spaces; if ($letter_spacing) { $num_chars = mb_strlen($text); $delta += $num_chars * $letter_spacing; } return $this->_pdf->stringwidth($text, $fh, $size) + $delta; } public function get_font_height($font, $size) { if ($size == 0) { return 0.0; } $fh = $this->_load_font($font); $this->_pdf->setfont($fh, $size); $asc = $this->_pdf->info_font($fh, "ascender", "fontsize=$size"); $desc = $this->_pdf->info_font($fh, "descender", "fontsize=$size"); // $desc is usually < 0, $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); return (abs($asc) + abs($desc)) * $ratio; } public function get_font_baseline($font, $size) { $ratio = $this->_dompdf->getOptions()->getFontHeightRatio(); return $this->get_font_height($font, $size) / $ratio * 1.1; } /** * Processes a callback or script on every page. * * The callback function receives the four parameters `int $pageNumber`, * `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics`, in * that order. If a script is passed as string, the variables `$PAGE_NUM`, * `$PAGE_COUNT`, `$pdf`, and `$fontMetrics` are available instead. Passing * a script as string is deprecated and will be removed in a future version. * * This function can be used to add page numbers to all pages after the * first one, for example. * * @param callable|string $callback The callback function or PHP script to process on every page */ public function page_script($callback): void { if (is_string($callback)) { $this->processPageScript(function ( int $PAGE_NUM, int $PAGE_COUNT, self $pdf, FontMetrics $fontMetrics ) use ($callback) { eval($callback); }); return; } $this->processPageScript($callback); } public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { $this->processPageScript(function (int $pageNumber, int $pageCount) use ($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle) { $text = str_replace( ["{PAGE_NUM}", "{PAGE_COUNT}"], [$pageNumber, $pageCount], $text ); $this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); }); } public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []) { $this->processPageScript(function () use ($x1, $y1, $x2, $y2, $color, $width, $style) { $this->line($x1, $y1, $x2, $y2, $color, $width, $style); }); } public function new_page() { // Add objects to the current page $this->_place_objects(); $this->_pdf->suspend_page(""); $this->_pdf->begin_page_ext($this->_width, $this->_height, ""); $this->_page_number = ++$this->_page_count; } protected function processPageScript(callable $callback): void { $this->_pdf->suspend_page(""); for ($p = 1; $p <= $this->_page_count; $p++) { $this->_pdf->resume_page("pagenumber=$p"); $fontMetrics = $this->_dompdf->getFontMetrics(); $callback($p, $this->_page_count, $this, $fontMetrics); $this->_pdf->suspend_page(""); } $this->_pdf->resume_page("pagenumber=" . $this->_page_number); } /** * @throws Exception */ public function stream($filename = "document.pdf", $options = []) { if (headers_sent()) { die("Unable to stream pdf: headers already sent"); } if (!isset($options["compress"])) { $options["compress"] = true; } if (!isset($options["Attachment"])) { $options["Attachment"] = true; } if ($options["compress"]) { $this->setPDFLibValue("compress", 6); } else { $this->setPDFLibValue("compress", 0); } $this->_close(); $data = ""; if (self::$IN_MEMORY) { $data = $this->_pdf->get_buffer(); $size = mb_strlen($data, "8bit"); } else { $size = filesize($this->_file); } header("Cache-Control: private"); header("Content-Type: application/pdf"); header("Content-Length: " . $size); $filename = str_replace(["\n", "'"], "", basename($filename, ".pdf")) . ".pdf"; $attachment = $options["Attachment"] ? "attachment" : "inline"; header(Helpers::buildContentDispositionHeader($attachment, $filename)); if (self::$IN_MEMORY) { echo $data; } else { // Chunked readfile() $chunk = (1 << 21); // 2 MB $fh = fopen($this->_file, "rb"); if (!$fh) { throw new Exception("Unable to load temporary PDF file: " . $this->_file); } while (!feof($fh)) { echo fread($fh, $chunk); } fclose($fh); //debugpng if ($this->_dompdf->getOptions()->getDebugPng()) { print '[pdflib stream unlink ' . $this->_file . ']'; } if (!$this->_dompdf->getOptions()->getDebugKeepTemp()) { unlink($this->_file); } $this->_file = null; unset($this->_file); } flush(); } public function output($options = []) { if (!isset($options["compress"])) { $options["compress"] = true; } if ($options["compress"]) { $this->setPDFLibValue("compress", 6); } else { $this->setPDFLibValue("compress", 0); } $this->_close(); if (self::$IN_MEMORY) { $data = $this->_pdf->get_buffer(); } else { $data = file_get_contents($this->_file); //debugpng if ($this->_dompdf->getOptions()->getDebugPng()) { print '[pdflib output unlink ' . $this->_file . ']'; } if (!$this->_dompdf->getOptions()->getDebugKeepTemp()) { unlink($this->_file); } $this->_file = null; unset($this->_file); } return $data; } /** * @param string $keyword * @param string $optlist * @return mixed */ protected function getPDFLibParameter($keyword, $optlist = "") { if ($this->getPDFLibMajorVersion() >= 9) { return $this->_pdf->get_option($keyword, ""); } return $this->_pdf->get_parameter($keyword, $optlist); } /** * @param string $keyword * @param string $value * @return mixed */ protected function setPDFLibParameter($keyword, $value) { if ($this->getPDFLibMajorVersion() >= 9) { return $this->_pdf->set_option($keyword . "=" . $value); } return $this->_pdf->set_parameter($keyword, $value); } /** * @param string $keyword * @param string $optlist * @return mixed */ protected function getPDFLibValue($keyword, $optlist = "") { if ($this->getPDFLibMajorVersion() >= 9) { return $this->getPDFLibParameter($keyword, $optlist); } return $this->_pdf->get_value($keyword); } /** * @param string $keyword * @param string $value * @return mixed */ protected function setPDFLibValue($keyword, $value) { if ($this->getPDFLibMajorVersion() >= 9) { return $this->setPDFLibParameter($keyword, $value); } return $this->_pdf->set_value($keyword, $value); } /** * @return int */ protected function getPDFLibMajorVersion() { if (is_null(self::$MAJOR_VERSION)) { if (method_exists($this->_pdf, "get_option")) { self::$MAJOR_VERSION = abs(intval($this->_pdf->get_option("major", ""))); } else { self::$MAJOR_VERSION = abs(intval($this->_pdf->get_value("major", ""))); } } return self::$MAJOR_VERSION; } } // Workaround for idiotic limitation on statics... PDFLib::$PAPER_SIZES = CPDF::$PAPER_SIZES; marcuryInfoData.txt 0000644 00000000000 15111253725 0010365 0 ustar 00 composer.json 0000644 00000000265 15111253725 0007273 0 ustar 00 { "name": "markury/markurypost", "description": "This is Markury Laravel.", "type": "laravel", "license": "MIT", "minimum-stability": "dev", "require": {} } marcuryBase.txt 0000644 00000000005 15111253725 0007557 0 ustar 00 VALID MarkuryPost.php 0000644 00000001433 15111253725 0007560 0 ustar 00 <?php namespace Markury; class MarkuryPost { public static function marcuryBase() { $marsFile = __DIR__.'/marcuryBase.txt'; $str = file_get_contents($marsFile); return $str; } public static function marcuryBasee() { $marsFile = __DIR__.'/marcuryInfo.txt'; $str = file_get_contents($marsFile); return $str; } public static function marcurryBase() { $marsFile = __DIR__.'/marcuryInfoData.txt'; $str = file_get_contents($marsFile); return $str; } public static function maarcuryBase() { $str = 'VALID'; return $str; } public static function marrcuryBase() { $str = date('Y-m-d'); return $str; } } marcuryInfo.txt 0000644 00000000670 15111253725 0007610 0 ustar 00 <center style="margin-top:100px;"> <span style="font-size: 100px;color: red;">⚠</span> <h1>Your Purchase License is Not Valid.</h1><br> <a style="border-radius: 3px; background-color: white; color: green; border: 2px solid green; padding: 15px 32px; text-align: center; text-decoration:none; font-size:18px; " href="https://codecanyon.net/user/geniusocean">Please Contact Us Now</a></center>