Linux diff PDF Tutorial

Linux diff PDF Tutorial

Linux diff PDF Tutorial

Today it’s time to talk PDF (Portable Document Format) and an extremely useful PDF generation class for PHP called Fpdf adding on to yesterday’s Linux diff Supervisor Tutorial‘s very limited report output format choices. So now we can output reports …

  • HTML
  • PDF with default PDF application reader
  • PDF as a downloaded file to client system
  • PDF as an attachment in an email

The big deal about PDF is threefold (at the very least) …

  • as its name suggests, it is portable, and very well supported as such
  • it is the online world’s equivalent of (a) hardcopy (printout)
  • it has a great deal of data fidelity (as there is no metadata that can be meddled with)

And so to have a tool such as Fpdf to call on, with the “F” standing for “Free” (thanks), to create PDF data, this is really great news! Now, to master Fpdf … 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?!

We wrote all our wording, after the “require(‘fpdf.php’);” loading of Fpdf and the “$outputpdf = new FPDF();” constructor, via …


$outputpdf->Cell($x, $y, $line_of_text);

… and variations on “$outputpdf->Output();” for outputs … but we probably need to learn about Fpdf tables to go that next stage further. In the meantime …

Try the Difference File Reporter live run‘s prediff.php PHP code’s last changes to make this interfacing with PDF and the Fpdf approach to creating it, happen. Thanks to this useful link regarding emailing PHP code ideas illustrated in today’s execution example involving Google’s Gmail email client web application.


Previous relevant Linux diff Supervisor Tutorial is shown below.

Linux diff Supervisor Tutorial

Linux diff Supervisor Tutorial

Do you remember long ago our “start of regime” trying to show you, as users, the code differences as we go through a project when we presented the Linux diff Primer Tutorial starring the Linux (or unix) diff command?

Well, today, we build a layer (“onions of the 4th dimension” methinks) on top of it, that brings together PHP (some for the first time) …

… and as its (command) name might suggest “passthru” can do just that in your PHP. The PHP is writing out HTML (or other types of data via an appropriate header command) and at any time whatever you get as output from an operating system command line call of the command you have as passthru‘s parameter becomes part of that HTML (or other data), unlike exec‘s outputting of just the last line as a return or placed in an array and shell_exec‘s outputting of all the output lines as a return (array) or placed into an array.

The “onions of the 4th dimension” side to this is that via “passthru”‘s “curl” (verbalised) command parameter we contain the gist of any one diff report run of the past, and all these can be being processed by our new live run‘s prediff.php PHP code’s use of glob to harness …

  • “filespec” (to the user is like a “urlspec” with a “filled in” and “readonly” website document root “URL” (of the webpage’s (web server) domain) as a prefix to a variable “subdirectoryfilespec” if you will … (and hope you see our concerns to really restrict what you can run a report on here) … along with
  • file modified date since (optionally set by user)
  • file modified date before (optionally set by user)

… presented in an HTML form method=POST action=./prediff.php (ie. here’s looking at you, kid).

We don’t show much about the underlying diff.php (very hard working duck … “this time with a curl, rather than trapped in an iframe” … 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 diff.php acting the same way it ever did unsupervised … which is “top priority” by the way.


Previous relevant Linux diff Primer Tutorial is shown below.

Linux diff Primer Tutorial

Linux diff Primer Tutorial

The Linux (or unix) command diff 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 UltraEdit (text editor) is brilliant, on Mac think TextWrangler does a good job here) type of comparison works better for me, and Source Control techniques work well for many programmers, but GUI doesn’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’s tutorial, have decided to show the workings of this, in the rudimentary way it is used here. At the other end of diff, its output can be used by patch to make diff an even more powerful tool, and there are links about all this below.

Some good background reading here would be:

  • diff (Linux or unix diff command)
  • exec (as interface to use with PHP on the web)
  • patch (as a way to use diff output as input to Linux or unix patch command)

So … 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 … the PHP exec() method). The follow up issue that tomorrow’s tutorial will address is the idea of an Apache web server configuration allowing a file “extension” to be mapped to a URL arrangement of your choosing … 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.

Specifically, in diff.php (of the picture) it has a line of code …

exec(“diff ” . dirname(__FILE__) . “/one.one ” . dirname(__FILE__) . “/two.two > ” . dirname(__FILE__) . “/huh.huh”);

… to bring (Linux) diff results to the web for file comparison purposes … 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’s PHP/Javascript/HTML Geographicals By Placename Tutorial. 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.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>