{"id":1256,"date":"2018-01-19T19:22:37","date_gmt":"2018-01-19T19:22:37","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/php-for-pdf-page-3\/"},"modified":"2018-01-19T19:24:39","modified_gmt":"2018-01-19T19:24:39","slug":"php-for-pdf-page-3","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/php-for-pdf-page-3\/","title":{"rendered":"PHP for PDF Page 3"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Luca Perugini<\/div>\n<div class=\"\">on October 26, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<h2> Distilling PDF document<\/h2>\n<div class=\"articlePara\">\nNow we&#8217;re ready to generate PDF on the fly!<\/div>\n<div class=\"articlePara\">\nIn this little example we&#8217;ll generate brochure on demand for FlyStore Inc.,<br \/>\ntaking data from a catalogue database.<\/div>\n<h2> Prepare Database Test<\/h2>\n<div class=\"articlePara\">\nI am going to assume a *little* experience in databases. Having said that, I&#8217;m<br \/>\nreally only hoping that you know how to create a database and insert tables<br \/>\ninto that database.<\/div>\n<div class=\"articlePara\">\nCreating table <i>catalogue<\/i>:<\/div>\n<div class=\"articlePara\">\n<pre>\ncreate table catalogue(\n  id           smallint(8) unsigned DEFAULT '0' NOT NULL,\n  item         varchar(100)         DEFAULT ''  NOT NULL,\n  description  tinytext,\n  img_data     longblob,\n  imgname      varchar(60),\n  imgsize      varchar(60),\n  imgtype      varchar(60),\n  price        smallint(8) unsigned DEFAULT '0' NOT NULL,\n  PRIMARY      KEY (id),\n  KEY          item (item(20))\n);\n<\/pre>\n<\/div>\n<h2> Sending MIME Header Information<\/h2>\n<div class=\"articlePara\">\nIn order to have our document show up correctly, we need to<br \/>\nsend correct header information to the user&#8217;s browser. <\/div>\n<div class=\"articlePara\">\nWith PHP we can do that using the <i>header<\/i> function.<br \/>\nThe following code sends the correct MIME type to the browser.<\/div>\n<div class=\"articlePara\">\n<pre>\nheader( \"Content-type: application\/pdf\" );\nheader( \"Content-Disposition: attachment; filename=modulo.pdf\" ); \nheader( \"Content-Description: PHP3 Generated Data\" );\n<\/pre>\n<\/div>\n<h2> Important Notes<\/h2>\n<div class=\"articlePara\">\nWhat you need to know is that you must not send anything before <i>header<\/i> output.<br \/>\nA common mistake is the presence of spaces at the beginning of the  file. <\/div>\n<h2> Getting Data From MySQL<\/h2>\n<div class=\"articlePara\">\nHere we&#8217;ve got a snapshot of code for retrieving data from the catalogue database. <\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>\u00a0\u00a0$link\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">mysql_connect\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"127.0.0.1\"<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #DD0000\">\"flyadm\"<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #DD0000\">\"flystore\"<\/span><span style=\"color: #007700\">)<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0or\u00a0die\u00a0(<\/span><span style=\"color: #DD0000\">\"Could\u00a0not\u00a0connect\"<\/span><span style=\"color: #007700\">);<\/p>\n<p>\u00a0\u00a0<\/span><span style=\"color: #0000BB\">mysql_select_db\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"flystore\"<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$link<\/span><span style=\"color: #007700\">);<\/p>\n<p>\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$result\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">mysql_query\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"SELECT\u00a0*\u00a0FROM\u00a0catalogue\"<\/span><span style=\"color: #007700\">,\u00a0<\/span><span style=\"color: #0000BB\">$link<\/span><span style=\"color: #007700\">)<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0or\u00a0die\u00a0(<\/span><span style=\"color: #DD0000\">\"Invalid\u00a0query\"<\/span><span style=\"color: #007700\">);<\/p>\n<p>\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$data\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #0000BB\">mysql_fetch_row\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">);<br \/>\n<br \/>\u00a0....<br \/>\n<br \/>\u00a0....<br \/>\n<br \/>\u00a0\u00a0<\/span><span style=\"color: #0000BB\">mysql_close\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$link<\/span><span style=\"color: #007700\">);<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"perugini200010264658.html?page=2\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"perugini20001026.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"perugini200010264658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">3<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"perugini20001026fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"perugini20001026fdb0.html?page=4\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>By Luca Perugini on October 26, 2000 Distilling PDF document Now we&#8217;re ready to generate PDF on the fly! In this little example we&#8217;ll generate brochure on demand for FlyStore Inc., taking data from a catalogue database. Prepare Database Test I am going to assume a *little* experience in databases&#8230;. <a href=\"https:\/\/phpbuilder.com\/php-for-pdf-page-3\/\" class=\"readmore\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1256","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1256"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1256\/revisions"}],"predecessor-version":[{"id":3151,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1256\/revisions\/3151"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}