{"id":291,"date":"2016-11-15T15:43:45","date_gmt":"2016-11-15T07:43:45","guid":{"rendered":"http:\/\/www.shenmdyw.com\/?p=291"},"modified":"2016-11-18T14:41:40","modified_gmt":"2016-11-18T06:41:40","slug":"tcpdf-header-footer","status":"publish","type":"post","link":"http:\/\/www.shenmdyw.com\/index.php\/2016\/11\/15\/tcpdf-header-footer\/","title":{"rendered":"TCPDF\u81ea\u5b9a\u4e49\u9875\u7709\u548c\u9875\u811a"},"content":{"rendered":"<p>TCPDF\u81ea\u5b9a\u4e49\u9875\u7709\u548c\u9875\u811a<\/p>\n<p>\u81ea\u5b9a\u4e49\u9875\u9762\u9875\u7709\u548c\u9875\u811a\u662f\u901a\u8fc7\u6269\u5c55TCPDF\u7c7b\u548c\u91cd\u5199header()\u548cfooter()\u65b9\u6cd5\u5b9a\u4e49\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">require_once('\/tcpdf\/examples\/tcpdf_include.php');\r\n\/\/ Extend the TCPDF class to create custom Header and Footer\r\nclass MYPDF extends \\TCPDF {\r\n\r\n    \/\/Page header \u81ea\u5b9a\u4e49\u9875\u7709\r\n    public function Header() {\r\n        $this-&gt;SetFont('stsongstdlight', '', 18);\r\n        \/\/$this-&gt;SetHeaderData('', '', ''.' 001', '', array(0,64,255), array(0,64,128));\r\n        \/\/ Title\r\n        $this-&gt;Cell(0, 10, 'title', 0, false, 'C', 0, '', 0, false, 'M', 'M');\r\n        $this-&gt;SetFont('stsongstdlight', '', 12);\r\n        $this-&gt;SetX(1);\r\n        $this-&gt;SetY(2+$this-&gt;GetY());\r\n        $this-&gt;Cell(0, 10, 'title2', 0, 0, 'C');\r\n        $this-&gt;SetX(1);\r\n        $this-&gt;SetY(8+$this-&gt;GetY());\r\n        $this-&gt;Cell(180, 0, '', 1, 0, 'C', 0, '', 0, true);\r\n    }\r\n\r\n    \/\/ Page footer \u81ea\u5b9a\u4e49\u9875\u811a\r\n    public function Footer() {\r\n        \/\/ Position at 15 mm from bottom\r\n        $this-&gt;SetY(-15);\r\n        $this-&gt;Cell(180, 0, '', 1, 0, 'C', 0, '', 0, true);\r\n        \/\/ Set font\r\n        $this-&gt;SetX(1);\r\n        $this-&gt;SetFont('stsongstdlight', '', 8);\r\n        \/\/ Page number\r\n        $this-&gt;Cell(0, 10, '123333 ', 0, false, 'C', 0, '', 0, false, 'T', 'M');\r\n        $this-&gt;SetFont('stsongstdlight', '', 8);\r\n        $this-&gt;SetX(1);\r\n        $this-&gt;SetY(5+$this-&gt;GetY());\r\n        $this-&gt;Cell(0, 10, '3434343 ', 0, false, 'C', 0, '', 0, false, 'T', 'M');\r\n        $this-&gt;Cell(0, 10, 'Page '.$this-&gt;getAliasNumPage().'\/'.$this-&gt;getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');\r\n    }\r\n}\r\n<\/pre>\n<p><!--more--><\/p>\n<p>\u4f7f\u7528tcpdf<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">            $pdf = new MYPDF();\r\n\t    $pdf-&gt;SetCreator(PDF_CREATOR);\r\n\t    $pdf-&gt;SetAuthor('Nicola Asuni');\r\n\t    $pdf-&gt;SetTitle(\"\u6807\u9898\");\/\/\u6807\u9898\r\n\t    $pdf-&gt;SetSubject('TCPDF Tutorial');\r\n\t    $pdf-&gt;SetKeywords('TCPDF, PDF, example, test, guide');\r\n\t    \/\/echo PDF_HEADER_LOGO;exit;\r\n\t    \/\/ set default header data\r\n\t    \/\/$pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, 180)\r\n\r\n\t    \/\/ set header and footer fonts\r\n\t   \/\/ $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));\r\n\t    \/\/$pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));\r\n\t     \r\n\t    \/\/ set default monospaced font\r\n\t    $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);\r\n\t     \r\n\t    \/\/ set margins\r\n\t    $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, 15, PDF_MARGIN_RIGHT);\r\n\t    $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);\r\n\t    $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);\r\n\t     \r\n\t    \/\/ set auto page breaks\r\n\t    $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);\r\n\t     \r\n\t    \/\/ set image scale factor\r\n\t    $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);\r\n\t     \r\n\t    \/\/ set some language-dependent strings (optional)\r\n\t    if (@file_exists(dirname(__FILE__).'\/lang\/zho.php')) {\r\n\t        require_once(dirname(__FILE__).'\/lang\/zho.php');\r\n\t        $pdf-&gt;setLanguageArray($l);\r\n\t    }\r\n\t     \r\n\t    \/\/ ---------------------------------------------------------\r\n\r\n\t    \/\/ add a page\r\n\t    $pdf-&gt;AddPage();\r\n\t    \/\/ writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')\r\n\t    \/\/ writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)\r\n\t     \r\n\t    \/\/ create some HTML content\r\n\t    $pdf-&gt;SetFont('stsongstdlight', '', 10);\r\n           $html=\"\u5185\u5bb9\";\/\/\u53ef\u4ee5\u653e\u5165html\u6807\u7b7e\r\n\t    \/\/ output the HTML content\r\n\t    $pdf-&gt;writeHTML($html, true, false, true, false, '');\/\/\r\n\t   \r\n\t    $pdf-&gt;Output('example_006.pdf', 'I');\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>TCPDF\u81ea\u5b9a\u4e49\u9875\u7709\u548c\u9875\u811a \u81ea\u5b9a\u4e49\u9875\u9762\u9875\u7709\u548c\u9875\u811a\u662f\u901a\u8fc7\u6269\u5c55TCPDF\u7c7b\u548c\u91cd\u5199header()\u548cfooter() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[125,127,126],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-php","tag-tcpdf-custom-header-and-footer","tag-tcpdf","tag-x-tcpdf-custom-header","clear"],"_links":{"self":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/comments?post=291"}],"version-history":[{"count":2,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":294,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/291\/revisions\/294"}],"wp:attachment":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/media?parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/categories?post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/tags?post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}