function get_margin_height() { $style = $this->get_style(); $font = $style->font_family; $size = $style->font_size; return $style->line_height / $size * Font_Metrics::get_font_height($font, $size); }
function pdf_create($html, $filename, $stream = TRUE) { $dompdf = new DOMPDF(); $dompdf->set_paper("A4"); $dompdf->load_html($html); $dompdf->render(); $canvas = $dompdf->get_canvas(); // get height and width of page $w = $canvas->get_width(); $h = $canvas->get_height(); // get font $font = Font_Metrics::get_font("helvetica", "normal"); $txtHeight = Font_Metrics::get_font_height($font, 7); //draw line for signature manager $mnline = $h - 10 * $txtHeight - 24; $colormn = array(0, 0, 0); $canvas->line(20, $mnline, $w - 470, $mnline, $colormn, 1); //text for signature Requestor/HOD $textmn = "Requestor/HOD"; $widthmn = Font_Metrics::get_text_width($textmn, $font, 12); $canvas->text($w - $widthmn - 480, $mnline, $textmn, $font, 12); // draw a line along the bottom $y = $h - 2 * $txtHeight - 24; $color = array(0, 0, 0); $canvas->line(16, $y, $w - 16, $y, $color, 1); //draw line for GM/Manager //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1); $canvas->line(330, $mnline, $w - 170, $mnline, $colormn, 1); $texthr = "GM/Manager"; $widthhr = Font_Metrics::get_text_width($texthr, $font, 12); $canvas->text($w - $widthmn - 160, $mnline, $texthr, $font, 12); //draw line for HR //$canvas->line(270, $mnline, $w - 240, $mnline, $colormn, 1); $canvas->line(180, $mnline, $w - 310, $mnline, $colormn, 1); $texthr = "HR"; $widthhr = Font_Metrics::get_text_width($texthr, $font, 12); $canvas->text($w - $widthmn - 325, $mnline, $texthr, $font, 12); //draw line for IT Officer $canvas->line(470, $mnline, $w - 20, $mnline, $colormn, 1); $textIT = "IT Officer"; $canvas->text($w - $widthmn - 30, $mnline, $textIT, $font, 12); // set page number on the left side //$canvas->page_text(16, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color); $canvas->page_text($w - 324, $y, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, $color); // set additional text $text = "ESRNL PORTAL"; $width = Font_Metrics::get_text_width($text, $font, 8); $canvas->text($w - $width - 16, $y, $text, $font, 8); if ($stream) { $dompdf->stream($filename . ".pdf"); } else { $CI =& get_instance(); $CI->load->helper('file'); write_file($filename, $dompdf->output()); } }
function get_margin_height() { // This function is called in add_frame_to_line() and is used to // determine the line height, so we actually want to return the // 'line-height' property, not the actual margin box $style = $this->get_style(); $font = $style->font_family; $size = $style->font_size; /* * pre_r('-----'); pre_r($style->line_height); pre_r($style->font_size); pre_r(Font_Metrics::get_font_height($font, $size)); pre_r(($style->line_height / $size) * Font_Metrics::get_font_height($font, $size)); */ return $style->line_height / $size * Font_Metrics::get_font_height($font, $size); }
/** * Class constructor * * @param Frame $frame the frame to decorate * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls) */ function __construct(Frame $frame, DOMPDF $dompdf) { parent::__construct($frame, $dompdf); $url = $frame->get_node()->getAttribute("src"); $debug_png = $dompdf->get_option("debug_png"); if ($debug_png) { print '[__construct ' . $url . ']'; } list($this->_image_url, , $this->_image_msg) = Image_Cache::resolve_url($url, $dompdf->get_protocol(), $dompdf->get_host(), $dompdf->get_base_path(), $dompdf); if (Image_Cache::is_broken($this->_image_url) && ($alt = $frame->get_node()->getAttribute("alt"))) { $style = $frame->get_style(); $style->width = 4 / 3 * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing); $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size); } }
/** * Class constructor * * @param Frame $frame the frame to decorate * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls) */ function __construct(Frame $frame, DOMPDF $dompdf) { global $_dompdf_warnings; parent::__construct($frame, $dompdf); $url = $frame->get_node()->getAttribute("src"); //debugpng if (DEBUGPNG) { print '[__construct ' . $url . ']'; } list($this->_image_url, $this->_image_ext) = Image_Cache::resolve_url($url, $dompdf->get_protocol(), $dompdf->get_host(), $dompdf->get_base_path()); if (strrpos($this->_image_url, DOMPDF_LIB_DIR . "/res/broken_image.png", 0) !== false && ($alt = $frame->get_node()->getAttribute("alt"))) { $style = $frame->get_style(); $style->width = 4 / 3 * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing); $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size); } }
/** * Class constructor * * @param Frame $frame the frame to decorate * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls) */ function __construct(Frame $frame, DOMPDF $dompdf) { global $_dompdf_warnings; parent::__construct($frame, $dompdf); $url = $frame->get_node()->getAttribute("src"); //debugpng if (DEBUGPNG) print '[__construct ' . $url . ']'; list($this->_image_url, $type, $this->_image_msg) = Image_Cache::resolve_url($url, $dompdf->get_protocol(), $dompdf->get_host(), $dompdf->get_base_path()); if (Image_Cache::is_broken($this->_image_url) && $alt = $frame->get_node()->getAttribute("alt") ) { $style = $frame->get_style(); $style->width = (4 / 3) * Font_Metrics::get_text_width($alt, $style->font_family, $style->font_size, $style->word_spacing); $style->height = Font_Metrics::get_font_height($style->font_family, $style->font_size); } }
protected function _layout_line() { $style = $this->_frame->get_style(); $text = $this->_frame->get_text(); $size = $style->font_size; $font = $style->font_family; $word_spacing = $style->length_in_pt($style->word_spacing); $char_spacing = $style->length_in_pt($style->letter_spacing); // Determine the text height $style->height = Font_Metrics::get_font_height($font, $size); $split = false; $add_line = false; // Handle text transform: // http://www.w3.org/TR/CSS21/text.html#propdef-text-transform switch (strtolower($style->text_transform)) { default: break; case "capitalize": $text = mb_convert_case($text, MB_CASE_TITLE); break; case "uppercase": $text = mb_convert_case($text, MB_CASE_UPPER); break; case "lowercase": $text = mb_convert_case($text, MB_CASE_LOWER); break; } // Handle white-space property: // http://www.w3.org/TR/CSS21/text.html#propdef-white-space switch ($style->white_space) { default: case "normal": $this->_frame->set_text($text = $this->_collapse_white_space($text)); if ($text == "") { break; } $split = $this->_line_break($text); break; case "pre": $split = $this->_newline_break($text); $add_line = $split !== false; break; case "nowrap": $this->_frame->set_text($text = $this->_collapse_white_space($text)); break; case "pre-wrap": $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; case "pre-line": // Collapse white-space except for \n $this->_frame->set_text($text = preg_replace("/[ \t]+/u", " ", $text)); if ($text == "") { break; } $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; } // Handle degenerate case if ($text === "") { return; } if ($split !== false) { // Handle edge cases if ($split == 0 && $text === " ") { $this->_frame->set_text(""); return; } if ($split == 0) { // Trim newlines from the beginning of the line //$this->_frame->set_text(ltrim($text, "\n\r")); $this->_block_parent->add_line(); $this->_frame->position(); // Layout the new line $this->_layout_line(); } else { if ($split < mb_strlen($this->_frame->get_text())) { // split the line if required $this->_frame->split_text($split); $t = $this->_frame->get_text(); // Remove any trailing newlines if ($split > 1 && $t[$split - 1] === "\n") { $this->_frame->set_text(mb_substr($t, 0, -1)); } // Do we need to trim spaces on wrapped lines? This might be desired, however, we // can't trim the lines here or the layout will be affected if trimming the line // leaves enough space to fit the next word in the text stream (because pdf layout // is performed elsewhere). /*if (!$this->_frame->get_prev_sibling() && !$this->_frame->get_next_sibling()) { $t = $this->_frame->get_text(); $this->_frame->set_text( trim($t) ); }*/ } } if ($add_line) { $this->_block_parent->add_line(); $this->_frame->position(); } } else { // Remove empty space from start and end of line, but only where there isn't an inline sibling // and the parent node isn't an inline element with siblings // FIXME: Include non-breaking spaces? $t = $this->_frame->get_text(); $parent = $this->_frame->get_parent(); $is_inline_frame = get_class($parent) === 'Inline_Frame_Decorator'; if (!$is_inline_frame && !$this->_frame->get_next_sibling() || $is_inline_frame && !$parent->get_next_sibling()) { $t = rtrim($t); } if (!$is_inline_frame && !$this->_frame->get_prev_sibling() || $is_inline_frame && !$parent->get_prev_sibling()) { $t = ltrim($t); } $this->_frame->set_text($t); } // Set our new width $width = $this->_frame->recalculate_width(); }
protected function _layout_line() { $style = $this->_frame->get_style(); $text = $this->_frame->get_text(); $size = $style->font_size; $font = $style->font_family; $word_spacing = $style->length_in_pt($style->word_spacing); // Determine the text height $style->height = Font_Metrics::get_font_height($font, $size); $split = false; $add_line = false; // Handle text transform: // http://www.w3.org/TR/CSS21/text.html#propdef-text-transform switch ($style->text_transform) { default: break; case "capitalize": $text = mb_convert_case($text, MB_CASE_TITLE, 'UTF-8'); break; case "uppercase": $text = mb_convert_case($text, MB_CASE_UPPER, 'UTF-8'); break; case "lowercase": $text = mb_convert_case($text, MB_CASE_LOWER, 'UTF-8'); break; } // Handle white-space property: // http://www.w3.org/TR/CSS21/text.html#propdef-white-space switch ($style->white_space) { default: case "normal": $this->_frame->set_text($text = $this->_collapse_white_space($text)); if ($text == "") { break; } $split = $this->_line_break($text); break; case "pre": $split = $this->_newline_break($text); $add_line = $split !== false; break; case "nowrap": $this->_frame->set_text($text = $this->_collapse_white_space($text)); break; case "pre-wrap": $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; case "pre-line": // Collapse white-space except for \n $this->_frame->set_text($text = preg_replace("/[ \t]+/u", " ", $text)); if ($text == "") { break; } $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; } // Handle degenerate case if ($text === "") { return; } if ($split !== false) { // Handle edge cases if ($split == 0 && $text === " ") { $this->_frame->set_text(""); return; } if ($split == 0) { // Trim newlines from the beginning of the line //$this->_frame->set_text(ltrim($text, "\n\r")); $this->_block_parent->add_line(); $this->_frame->position(); // Layout the new line $this->_layout_line(); } else { if ($split < mb_strlen($this->_frame->get_text())) { // split the line if required $this->_frame->split_text($split); // Remove any trailing newlines $t = $this->_frame->get_text(); if ($split > 1 && $t[$split - 1] === "\n") { $this->_frame->set_text(mb_substr($t, 0, -1)); } } } if ($add_line) { $this->_block_parent->add_line(); $this->_frame->position(); } // Set our new width $this->_frame->recalculate_width(); } else { $this->_frame->recalculate_width(); } }
function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $adjust = 0, $angle = 0) { $fh = $this->_load_font($font); $this->_pdf->setfont($fh, $size); $this->_set_fill_color($color); $y = $this->y($y) - Font_Metrics::get_font_height($font, $size); $adjust = (double) $adjust; $angle = -(double) $angle; //$this->_pdf->fit_textline(utf8_decode($text), $x, $y, "rotate=$angle wordspacing=$adjust"); $this->_pdf->fit_textline($text, $x, $y, "rotate={$angle} wordspacing={$adjust}"); }
function text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_spacing = 0, $char_spacing = 0, $angle = 0) { $fh = $this->_load_font($font); $this->_pdf->setfont($fh, $size); $this->_set_fill_color($color); $y = $this->y($y) - Font_Metrics::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 "); }
protected function _layout_line() { $frame = $this->_frame; $style = $frame->get_style(); $text = $frame->get_text(); $size = $style->font_size; $font = $style->font_family; $style->height = Font_Metrics::get_font_height($font, $size); $split = false; $add_line = false; switch (strtolower($style->text_transform)) { default: break; case "capitalize": $text = mb_convert_case($text, MB_CASE_TITLE); break; case "uppercase": $text = mb_convert_case($text, MB_CASE_UPPER); break; case "lowercase": $text = mb_convert_case($text, MB_CASE_LOWER); break; } switch ($style->white_space) { default: case "normal": $frame->set_text($text = $this->_collapse_white_space($text)); if ($text == "") { break; } $split = $this->_line_break($text); break; case "pre": $split = $this->_newline_break($text); $add_line = $split !== false; break; case "nowrap": $frame->set_text($text = $this->_collapse_white_space($text)); break; case "pre-wrap": $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; case "pre-line": $frame->set_text($text = preg_replace("/[ \t]+/u", " ", $text)); if ($text == "") { break; } $split = $this->_newline_break($text); if (($tmp = $this->_line_break($text)) !== false) { $add_line = $split < $tmp; $split = min($tmp, $split); } else { $add_line = true; } break; } if ($text === "") { return; } if ($split !== false) { if ($split == 0 && $text === " ") { $frame->set_text(""); return; } if ($split == 0) { $this->_block_parent->add_line(); $frame->position(); $this->_layout_line(); } else { if ($split < mb_strlen($frame->get_text())) { $frame->split_text($split); $t = $frame->get_text(); if ($split > 1 && $t[$split - 1] === "\n" && !$frame->is_pre()) { $frame->set_text(m_mb_substr($t, 0, -1)); } } } if ($add_line) { $this->_block_parent->add_line(); $frame->position(); } } else { $t = $frame->get_text(); $parent = $frame->get_parent(); $is_inline_frame = get_class($parent) === 'Inline_Frame_Decorator'; if (!$is_inline_frame && !$frame->get_next_sibling() || $is_inline_frame && !$parent->get_next_sibling()) { $t = rtrim($t); } if (!$is_inline_frame && !$frame->get_prev_sibling()) { $t = ltrim($t); } $frame->set_text($t); } $width = $frame->recalculate_width(); }
function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $adjust = 0, $angle = 0, $blend = "Normal", $opacity = 1.0) { list($r, $g, $b) = $color; $this->_pdf->setColor($r, $g, $b); $this->_set_line_transparency($blend, $opacity); $this->_set_fill_transparency($blend, $opacity); $font .= ".afm"; $this->_pdf->selectFont($font); $this->_pdf->addText($x, $this->y($y) - Font_Metrics::get_font_height($font, $size), $size, utf8_decode($text), $angle, $adjust); }
function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $word_spacing = 0, $char_spacing = 0, $angle = 0) { $fh = $this->_load_font($font); $this->_pdf->setfont($fh, $size); $this->_set_fill_color($color); $y = $this->y($y) - Font_Metrics::get_font_height($font, $size); $word_spacing = (double) $word_spacing; $char_spacing = (double) $char_spacing; $angle = -(double) $angle; //***$this->_pdf->fit_textline($text, $x, $y, "rotate=$angle wordspacing=$word_spacing charspacing=$char_spacing "); $this->_pdf->fit_textline($this->_pdf->utf8_to_utf16($text, ""), $x, $y, "rotate={$angle} wordspacing={$word_spacing} charspacing={$char_spacing} "); //*** }