{"id":35184,"date":"2017-12-30T03:01:29","date_gmt":"2017-12-29T17:01:29","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=35184"},"modified":"2017-12-30T08:21:53","modified_gmt":"2017-12-29T22:21:53","slug":"linux-diff-pdf-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-diff-pdf-tutorial\/","title":{"rendered":"Linux diff PDF Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Linux diff PDF Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff_fpdf.jpg\" title=\"Linux diff PDF Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Linux diff PDF Tutorial<\/p><\/div>\n<p>Today it&#8217;s time to talk <a target=_blank title='Portable document format (PDF) information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Portable_Document_Format'>PDF<\/a> (Portable Document Format) and an extremely useful PDF generation class for PHP called <a target=_blank title='Fpdf PHP class' href='http:\/\/www.fpdf.org\/'>Fpdf<\/a> adding on to yesterday&#8217;s <a title='Linux diff Supervisor Tutorial' href='#lst'>Linux diff Supervisor Tutorial<\/a>&#8216;s very limited report output format choices.   So <b>now<\/b> we can output reports &#8230;<\/p>\n<ul>\n<li>HTML<\/li>\n<li><b>PDF with default PDF application reader<\/b><\/li>\n<li><b>PDF as a downloaded file to client system<\/b><\/li>\n<li><b>PDF as an attachment in an email<\/b><\/li>\n<\/ul>\n<p>The big deal about PDF is threefold (at the very least) &#8230;<\/p>\n<ul>\n<li>as its name suggests, it is portable, and very well supported as such<\/li>\n<li>it is the online world&#8217;s equivalent of (a) hardcopy (printout)<\/li>\n<li>it has a great deal of data fidelity (as there is no metadata that can be meddled with)<\/li>\n<\/ul>\n<p>And so to have a tool such as <a target=_blank title='Fpdf PHP class' href='http:\/\/www.fpdf.org\/'>Fpdf<\/a> to call on, with the &#8220;F&#8221; standing for &#8220;Free&#8221; (thanks), to create PDF data, this is really great news!  Now, to master <a target=_blank title='Fpdf PHP class' href='http:\/\/www.fpdf.org\/'>Fpdf<\/a> &#8230; well, if you read about PDF writing solutions lots of people will point you in other directions, but so far, with textual data it has sufficed fine for us, at our rudimentary skills level.  In other words, you have a product that you feel you can get better at, which is definitely a good sign.  Probably not the Rolls Royce of PDF creation tools, but you pay good money otherwise, perhaps in installments for the rest of your life?!<\/p>\n<p>We wrote all our wording, after the &#8220;<i>require(&#8216;fpdf.php&#8217;);<\/i>&#8221; loading of Fpdf and the &#8220;<i>$outputpdf = new FPDF();<\/i>&#8221; constructor, via &#8230;<\/p>\n<p><code><br \/>\n$outputpdf->Cell($x, $y, $line_of_text);<br \/>\n<\/code><\/p>\n<p> &#8230; and variations on &#8220;<i>$outputpdf->Output();<\/i>&#8221; for outputs &#8230; but we probably need to learn about Fpdf tables to go that next stage further.  In the meantime &#8230;<\/p>\n<p>Try the Difference File Reporter <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php\">live run<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php-GETME\">prediff.php<\/a> PHP code&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php-GETME\">last changes<\/a> to make this interfacing with PDF and the Fpdf approach to creating it, happen. Thanks to this <a target=_blank title='Useful link' href='https:\/\/stackoverflow.com\/questions\/4353271\/email-pdf-attachment-with-php-using-fpdf\/8900290'>useful link<\/a> regarding emailing PHP code ideas illustrated in today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff_fpdf.jpg\" title=\"Tutorial picture\">execution example<\/a> involving Google&#8217;s <a target=_blank title='Google Gmail' href='http:\/\/www.gmail.com'>Gmail<\/a> email client web application.<\/p>\n<hr>\n<p id='lst'>Previous relevant <a target=_blank title='Linux diff Supervisor Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-diff-supervisor-tutorial\/'>Linux diff Supervisor Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Linux diff Supervisor Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.jpg\" title=\"Linux diff Supervisor Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Linux diff Supervisor Tutorial<\/p><\/div>\n<p>Do you remember long ago our &#8220;start of regime&#8221; trying to show you, as users, the code differences as we go through a project when we presented the <a title='Linux diff Primer Tutorial' href='#lpt'>Linux diff Primer Tutorial<\/a> starring the Linux (or unix) <a target=_blank title='diff' href='https:\/\/www.computerhope.com\/unix\/udiff.htm'><i>diff<\/i><\/a> command?<\/p>\n<p>Well, today, we build a layer (&#8220;onions of the 4th dimension&#8221; methinks) on top of it, that brings together PHP (<b>some for the first time<\/b>) &#8230;<\/p>\n<ul>\n<li><a target=_blank title='PHP glob() method information' href='http:\/\/php.net\/manual\/en\/function.glob.php'>glob<\/a><\/li>\n<li><b><a target=_blank title='PHP filemtime information' href='http:\/\/php.net\/manual\/en\/function.filemtime.php'>filemtime<\/a><\/b><\/li>\n<li><a target=_blank href='http:\/\/au1.php.net\/function.exec' title='PHP exec command'>exec<\/a><\/li>\n<li><b><a target=_blank href='http:\/\/au1.php.net\/function.passthru' title='PHP passthru command'>passthru<\/a><\/b><\/li>\n<li><a target=_blank title='diff' href='https:\/\/www.computerhope.com\/unix\/udiff.htm'><i>diff<\/i><\/a><\/li>\n<li><a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/CURL' title='Curl information from Wikipedia ... thanks'>curl<\/a><\/li>\n<\/ul>\n<p> &#8230; and as its (command) name might suggest &#8220;passthru&#8221; can do just that in your PHP.  The PHP is writing out HTML (or other types of data via an appropriate <a target=_blank title='PHP header method' href='http:\/\/php.net\/manual\/en\/function.header.php'>header<\/a> command) and at any time whatever you get as output from an operating system command line call of the command you have as <i>passthru<\/i>&#8216;s parameter becomes part of that HTML (or other data), unlike <a target=_blank href='http:\/\/au1.php.net\/function.exec' title='PHP exec command'>exec<\/a>&#8216;s outputting of just the last line as a return or placed in an array and <a target=_blank href='http:\/\/au1.php.net\/function.shell_exec' title='PHP exec command'>shell_exec<\/a>&#8216;s outputting of all the output lines as a return (array) or placed into an array.<\/p>\n<p>The &#8220;onions of the 4th dimension&#8221; side to this is that via &#8220;passthru&#8221;&#8216;s &#8220;curl&#8221; (verbalised) command parameter we contain the gist of any one <i>diff<\/i> report run of the past, and all these can be being processed by our new <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php\">live run<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/prediff.php_GETME\">prediff.php<\/a> PHP code&#8217;s use of <i>glob<\/i> to harness &#8230;<\/p>\n<ul>\n<li>&#8220;filespec&#8221; (to the user is like a &#8220;urlspec&#8221; with a &#8220;filled in&#8221; and &#8220;readonly&#8221; website document root &#8220;URL&#8221; (of the webpage&#8217;s (web server) domain) as a prefix to a variable &#8220;subdirectoryfilespec&#8221; if you will <font size=1>&#8230; (and hope you see our concerns to really restrict what you can run a report on here<\/font>) &#8230; along with <\/li>\n<li>file modified date since (optionally set by user)<\/li>\n<li>file modified date before (optionally set by user)<\/li>\n<\/ul>\n<p> &#8230; presented in an HTML <a target=_blank title='HTML form element information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_form.asp'>form<\/a> method=POST action=.\/prediff.php (ie. here&#8217;s looking at you, kid).<\/p>\n<p>We don&#8217;t show much about the underlying <i>diff.php<\/i> (very hard working duck &#8230; &#8220;this time with a curl, rather than trapped in an iframe&#8221; &#8230; tee, hee), but it changed to cater for what the supervisor HTML presentation would ask of its underling.  No worries here, as long as the testing works for <i>diff.php<\/i> acting the same way it ever did unsupervised &#8230; which is &#8220;top priority&#8221; by the way.<\/p>\n<hr>\n<p id='lpt'>Previous relevant <a target=_blank title='Linux diff Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-diff-primer-tutorial\/'>Linux diff Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/diff\/diff.png\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux diff Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/diff\/diff.jpg\" title=\"Linux diff Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux diff Primer Tutorial<\/p><\/div>\n<p>The Linux (or unix) command <a target=_blank title='diff' href='http:\/\/pic.dhe.ibm.com\/infocenter\/zos\/v1r13\/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fdiff.htm'><i>diff<\/i><\/a> is a powerful command line tool that does file comparisons at the command line of a Linux (or unix) operating system.   When you are coding this type of tool can be very important.   You may not like to do such tasks in the command line, and have to say that a GUI (on Windows <a target=_blank title='UltraEdit' href='http:\/\/www.ultraedit.com\/'>UltraEdit<\/a> (text editor) is brilliant, on Mac think <a target=_blank title='TextWrangler' href='http:\/\/www.barebones.com\/products\/textwrangler\/'>TextWrangler<\/a> does a good job here) type of comparison works better for me, and <a target=_blank title='Source Control' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=source-control'>Source Control<\/a> techniques work well for many programmers, but GUI doesn&#8217;t always gel with integration, and want to show you today how the Linux diff can be incorporated into your PHP code.   In saying this, am recommending extreme care with this, as its misuse can have bad implications for the whole website to be exposed to the outside world.   Balancing this up against wanting to have a tool for users of this web blog to (have a more automated way to) be able to see the comparisons of files of changing code, as in yesterday&#8217;s tutorial, have decided to show the workings of this, in the rudimentary way it is used here.   At the other end of <i>diff<\/i>, its output can be used by <i>patch<\/i> to make <i>diff<\/i> an even more powerful tool, and there are links about all this below.<\/p>\n<p>Some good background reading here would be:<\/p>\n<ul>\n<li><a target=_blank title='diff' href='http:\/\/pic.dhe.ibm.com\/infocenter\/zos\/v1r13\/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fdiff.htm'>diff<\/a> (Linux or unix diff command)<\/li>\n<li><a target=_blank title='exec' href='http:\/\/php.net\/manual\/en\/function.exec.php'>exec<\/a> (as interface to use with PHP on the web)<\/li>\n<li><a target=_blank title='patch' href='http:\/\/pic.dhe.ibm.com\/infocenter\/zos\/v1r13\/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fpatch.htm'>patch<\/a> (as a way to use diff output as input to Linux or unix patch command)<\/li>\n<\/ul>\n<p>So &#8230; why does the picture for this tutorial not show a Linux command line screen?   Well, today we show you the power of the combination of Linux commands and the PHP way to access these commands (in our case with diff.php &#8230; the PHP exec() method).  The follow up issue that tomorrow&#8217;s tutorial will address is the idea of an Apache web server configuration allowing a file &#8220;extension&#8221; to be mapped to a URL arrangement of your choosing &#8230; will save the idea here for that future tutorial, as this topic area is very big and needs the user to step back and think about, a lot, before considering.<\/p>\n<p>Specifically, in diff.php (of the picture) it has a line of code &#8230; <\/p>\n<blockquote><p>  exec(&#8220;diff &#8221; . dirname(__FILE__) . &#8220;\/one.one &#8221; . dirname(__FILE__) . &#8220;\/two.two > &#8221; . dirname(__FILE__) . &#8220;\/huh.huh&#8221;);<\/p><\/blockquote>\n<p>&#8230; to bring (Linux) diff results to the web for file comparison purposes &#8230; clicking on the picture of the tutorial shows a picture showing the link that got clicked to create the webpage of the front picture.   This all sprung from yesterday&#8217;s <a target=_blank title='PHP\/Javascript\/HTML Geographicals By Placename Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5403'>PHP\/Javascript\/HTML Geographicals By Placename Tutorial<\/a>.  By the way, am not showing all the code of diff.php today, and am sorry about that, but rest assured the line of code above is its crucial part.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5435' onclick='var dv=document.getElementById(\"d5435\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5435' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d35164' onclick='var dv=document.getElementById(\"d35164\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/glob\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35164' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d35184' onclick='var dv=document.getElementById(\"d35184\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/pdf\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d35184' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today it&#8217;s time to talk PDF (Portable Document Format) and an extremely useful PDF generation class for PHP called Fpdf adding on to yesterday&#8217;s Linux diff Supervisor Tutorial&#8216;s very limited report output format choices. So now we can output reports &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-diff-pdf-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[234,284,301,328,1750,355,380,405,418,2426,2429,452,2430,1615,503,513,1996,576,707,2428,2427,913,932,997,1054,1133,1137,1319,1345,1411],"class_list":["post-35184","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-command-line","tag-curl","tag-date","tag-diff","tag-document-root","tag-domain","tag-email","tag-exec","tag-file","tag-filemtime","tag-filespec","tag-form","tag-fpdf","tag-glob","tag-gmail","tag-google","tag-header","tag-html","tag-linux","tag-onion","tag-passthru","tag-pdf","tag-php","tag-programming","tag-report","tag-share","tag-sharing","tag-tutorial","tag-url","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35184"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=35184"}],"version-history":[{"count":13,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35184\/revisions"}],"predecessor-version":[{"id":35204,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/35184\/revisions\/35204"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=35184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=35184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=35184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}