123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- namespace Pdf\Lib;
- use Dever;
- Dever::apply('fpdf/chinese', 'pdf');
- Dever::apply('tcpdf/tcpdf', 'pdf');
- class Core
- {
- public function init($page = 'P', $size = 'mm', $type = 'A4')
- {
- $this->pdf = new Pdf($page, $size, $type);
- $this->pdf->SetCreator('dever');
- $this->pdf->SetAuthor('dever');
- $this->pdf->SetFont('stsongstdlight', '', 10);
- $this->pdf->setHeaderFont(Array('stsongstdlight', '', '10'));
- $this->pdf->setFooterFont(Array('stsongstdlight', '', '8'));
-
- $this->pdf->setPrintHeader(false);
- $this->pdf->setPrintFooter(false);
- $this->pdf->AddPage();
- return $this->pdf;
- }
- }
- class Pdf extends \TCPDF
- {
- public function __construct($name, $size, $page)
- {
- parent::__construct($name, $size, $page, true, 'UTF-8', false);
- }
-
- public function font($size, $style = '', $font = '')
- {
- $this->SetFont($font, $style, $size);
- return $this;
- }
-
- public function content($name, $content, $size = 15)
- {
- if ($name) {
- $this->br(1, 1);
- $this->font($size, 'B');
- $this->left($name, 100);
- $this->br();
- }
-
- $this->font($size, '');
- $this->mleft($content);
- return $this;
- }
-
- public function add($text, $align = 'L', $width = 0, $height = 8, $border = 0, $ln = 0, $link = '', $fill = false)
- {
- if (!$height) {
- $height = 8;
- }
- if (!$width) {
- $this->br();
- }
- $this->Cell($width, $height, $text, $border, $ln, $align, $fill, $link);
- return $this;
- }
- public function left($text, $width = 0, $border = 0, $height = 8)
- {
- $this->add($text, 'L', $width, $height, $border);
- return $this;
- }
- public function right($text, $width = 0, $border = 0, $height = 8)
- {
- $this->add($text, 'R', $width, $height, $border);
- return $this;
- }
- public function center($text, $width = 0, $border = 0, $height = 8)
- {
- $this->add($text, 'C', $width, $height, $border);
- return $this;
- }
-
- public function madd($text, $align = 'L', $width = 0, $height = 8, $border = 0, $ln = 1, $fill = false, $x = '', $y = '', $reseth = true, $stretch = 0,$ishtml = false, $autopadding = false, $maxh = 0, $valign = 'T', $fitcell = false)
- {
- if (!$height) {
- $height = 8;
- }
- if (!$width) {
-
- }
- $this->MultiCell($width, $height, $text, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
- return $this;
- }
- public function mleft($text, $width = 0, $border = 0, $height = 8)
- {
- $this->madd($text, 'L', $width, $height, $border);
- return $this;
- }
- public function mright($text, $width = 0, $border = 0, $height = 8)
- {
- $this->madd($text, 'R', $width, $height, $border);
- return $this;
- }
- public function mcenter($text, $width = 0, $border = 0, $height = 8)
- {
- $this->madd($text, 'C', $width, $height, $border);
- return $this;
- }
- public function img($file, $x, $y = false, $w = 30, $h = 30)
- {
- if (!$y) {
- $y = $this->y();
- }
- $this->Image(Dever::pic($file), $x, $y, $w, $h);
- return $this;
- }
- public function hr($str = '-', $name = '')
- {
- $text = str_pad($name, 142, $str, STR_PAD_BOTH);
- $this->add($text);
- return $this;
- }
- public function br($num = 1, $size = null)
- {
- for ($i = 0; $i < $num; $i++) {
- $this->Ln($size);
- }
-
- return $this;
- }
- public function y()
- {
- return $this->GetY();
- }
- public function x()
- {
- return $this->GetX();
- }
- public function convert($string)
- {
- return Dever::convert($string);
- }
-
- public function out($name, $dest = 'I')
- {
- $this->Output($name, $dest);
- }
- }
|