what's in a name?

Wrapping text in FPDF table cells

October 5th, 2007

This article aims to help those who like myself wondered how to make text wrap within a table cell using FPDF to generate a the PDF. A few posts around the web seem to have missed the point that wrapping comes out of the box in FPDF using the MultiCell function. However, it’s just a tiny bit tricky but not prohibitively so. So, this is what we are aiming for - an invoice.

FPDF Invoice

There are 2 examples of wrapping here. Firstly the client address is wrapped, and secondly the first row of the line item data has a wrapped description.

View the PDF here

In both cases the MultiCell in-built function is used. Before I had this solution working I was using the Cell function. In that case, long text simply continued through to the next cell ‘Quantity’. In the case of Cell, you can simply output a series of calls to the function with a cell width and so fourth and the cells will line up against each other on the same line.

When I switched to MultiCell for the first cell of each row only, I found that it would cause all subsequent cells in the same row to wrap to the next line. Therefore my solution was to use the SetXY function to reposition the ‘cursor’ back to where the 2nd cell of the current row would normally be, and then proceed to use Cell calls.

In order to do that it’s a case of marking the current X and Y coordinates of the cursor prior to entering the line item loop and calling SetXY just after the 1st cell MultiCell function call. That solved the line wrapping issue and my text wrapped inside the first cell - great.

The second issue however is that the MultiCell is arbitrarily high depending on the amount of text wrapping going on. I had been provided a static height to my Cell calls as as such they were now out of line with the first column, that is, the text and border lines were all out of sync with the 1st column.

To solve that problem it was a case of grabbing the Y coordinate of the cursor before and immediately after the MultiCell call, finding the difference to ascertain the height of the cell, and then using this to size the height of the remaining Cell calls on the row.

Source Code

Please feel free to download the source code for this article which builds the invoice PDF as described.

The source code is provided as a ZIP file with index.php and InvoicePDF.class.php. You will need to obtain the FPDF library yourself and modify the index.php include file locations.

Best of luck!

by Allistair

A rare chance to talk to Microsoft

October 5th, 2007

It’s not often you will get the chance to be heard by some of the leaders of Microsoft services such as Live.com, Office Live, XBOX Live, Hotmail and more, but that chance is being offered by Major Nelson, XBOX Live Community Chap Extraordinaire on his blog.

He’ll be attending a 2 day meeting with said leaders and will try and share feedback from the world as we know it on what it thinks of Microsoft services, what they do well, what they can do better.

If you feel like sharing your opinions, and I urge you to do so, head over to Major Nelson and get posting.

by Allistair

Moo - a simple idea done fantastically well

September 7th, 2007

Today is very exciting for me (as well as others - National Defence Day in Pakistan, Independence Day in Brazil and Victory Day in Mozambique). But I’m excited because I received my Moo minicards - my roxxor business cards.

Moo is an online printing company that produce a small set of quality eco-friendly products such as minicards, stickerbooks and notecards, and for a great price and fast global delivery.

Moo Minicards Box

The great thing about Moo is that you can upload your photos or (the bit that I like) brilliantly get it to import photos out of your favourite image-related accounts that you may have around the web such as Flickr, Bebo, VOX and more. Or, if you don’t have any images, they have some stuff for you to choose from. They don’t yet do full photo albums but I really hope they do in future.

We decided at roxxor to use Moo Minicards for our business cards. A business card says a lot about the person or company giving it and we felt we wanted to (as Ben likes to say) “eat our own dog food” and demonstrate our awareness and support of excellent web businesses.

My Moo Minicard Front

Moo provides an online editor for entering the information for your card and placing imagery if you are customising it yourself. We chose to download the Photoshop templates for ours but you need not. When you’re happy, you submit your design, pay a good price and just 3 days later you get an exciting little box packed full of cards. Simplicity.

The first thing you’ll notice is their size. This size was typical of “calling cards” back in the day, and are 1/2 the size of a normal business card. Most of the time normal business cards do not use that space and if they do look over-crowded and ugly. The material is best described as a satin finish - that is, not glossy and not matte but just a slight sheen. The thickness is pleasingly thick and together with their size makes bending only possible in one direction.

My Moo Minicard

We chose to make an impact with our brand on the front side of the card, whilst adding limited contact information to the rear. And yet even with this smaller card, it looks fresh and spacious whilst still providing clear brand and enough information.

We highly recommend Moo - it’s one of the more useful companies out there on the web doing a fantastic job of a simple idea - just as business should be.

by Allistair

What Browser Version To Design For

August 16th, 2007

We always try to design things so they are cross browser compatible and that things work and look the same for all user no matter what version or operating system they are using.

We encountered a problem recently with a site not rendering correctly in IE6.0 - of course our dev guys fixed this right up but this inspired me to get some stats on just what browsers folks were using on our clients web sites. I took a peak at the analytics for this across a range of our clients that have significant traffic volumes (in excess of 1M visit per month) and a varied demographic user base across a range of industry sectors (Fashion, Retail and Transport) to make these stats work as ‘real’ averages.

It made interesting reading and I thought you might like to see the results.

ORDER BROWSER PERCENTAGE OF TRAFFIC
1 Internet Explorer 88.58%
a v6.0 57.71%
b v7.0 41.68%
c v5.5 0.37%
2 Firefox 9.00%
a 2.0.0.6 37.79%
b 2.0.0.5 30.91%
c 2.0.0.4 11.84%
d 1.5.0.12 7.97%
e 1.0.7 2.13%
3 Safari 1.91%
4 Opera 0.29%
5 Mozilla 0.08%

Based on this data we have decided to rule out IE5.5 from any design/dev decisions going forwards. Sorry to any of you still using this, but there just aren’t enough of you out there to warrant the additional tests.

by Ben

Ubuntu 7.04 Server, Int 14 Boot Error

August 14th, 2007

Having heard rave reviews of Ubuntu being a real alternative to Windows, I was keen to test this hypothesis out. I downloaded the latest server edition (7.04) and burned the ISO to a CD.

Installation was fine and completed but booting Ubuntu failed at the very start of the boot process just when “Starting …” is shown. The following dump is produced (or similar)

Int 14: CR2 f0000000 err 00000000 EIP c828c384 CS 000000060 flags 00010003
Stack: c007eb0 c83f129b c8371d8c 000000082 c00f7eb9 000f7eb8 00000000 00000000

I’ve read a great many posts about this issue. Suggestions have been made that

  • It’s a dual boot issue
  • It’s a laptop issue
  • It’s a RAID disk issue
  • It’s a video card driver issue
  • It’s a BIOS issue
  • It’s an incompatibility issue with the way the server edition kernel is compiled

Suggestions to fix the issue are also broad ranging from updating BIOS firmware to booting into recovery mode and twiddling with core system files.

Conclusion

If you have found this post hoping for a concrete answer then I don’t have it for you. The problem could be one in the list above or maybe another. Right now, it does not seem Ubuntu has addressed this explicitly despite the number of reports

However, one suggestion did work for me behind which I’ll throw my support.

Install the Ubuntu Alternative Desktop 7.04. This is available on the same Ubuntu download page as the server edition. You have to select the Desktop edition and then a checkbox indicating you want the alternative ISO. It weighs in a couple hundred megabytes heavier, but after installation I booted into Ubuntu no problems.

The server features I wanted; Apache, MySQL, PHP, I have added with XAMPP, though you could probably find the relevant packages in the package manager too.

I’ve been using Ubuntu for about a week now with no problems; wireless, mail, messaging, internet and so far the experience has been good.

by Allistair

Windows Live Writer

July 30th, 2007

Always keen to trial new bits of software I came across Windows Live Writer and figured my first Roxxor Blog post was pretty much the perfect opportunity to test it out.

I find the only time I get to do any blogging is during downtime on the train or while waiting for some other kind of public transport.

I am a fan of any bit of kit that lets me work on something - check it and then publish. I love the Adwords Editor for exactly the same reasons.

This seems pretty good so far, very Office like & easy to use - check it out.

by Ben

Populate PHP Object Attributes from Database Column Names Dynamically

July 3rd, 2007

If you like coding PHP the OOP way then you will often find yourself in the arduous position of needing to populate your object attributes (member variables) from database row data. And you do this again and again and again, and you find it all rather repetitive, which it is. And you don’t fancy looking at an object relational mapping solution for now, but promise yourself you will “Another Time”.

Here it is;

  1. class MyObject {
  2.  function __construct($data = NULL) {
  3.   if ($data) {
  4.    foreach ($data as $ak => $av) {
  5.     eval(\$this->” . $this->db2Camel($ak) . ” = ‘{$av}’;”);
  6.    }
  7.   }
  8.  }
  9.  
  10.  function db2Camel($str) {
  11.   $str = strtolower($str);
  12.   $parts = explode(‘_’, $str);
  13.   for ($i = 0; $i < count($parts); $i++) {
  14.    if ($i == 0) {
  15.     $parts[$i] = strtolower($parts[$i]);
  16.    } else {
  17.     $parts[$i] = ucfirst($parts[$i]);
  18.    }
  19.   }
  20.   return implode(, $parts);
  21.  } 
  22. }

This code relies on a number of assumptions. These are, but are probably not limited to;

  1. The data parameter to the constructor is an associative array, depicting a row from the database. 
  2. That the database column names are lowercase, and separated by underscores, e.g. the_column_name
  3. Your attributes will be in camel casing as governed by the db2Camel function
  4. Your attributes will be public as they do not benefit from an explicit declaration of access scope such as private or protected.
  5. You will access the attributes direct on the object, not through get accessors, e.g. $obj->theAttribute
  6. A programmer would not know the attributes that an object contained from reading the code, they would need to understand the constructor’s function and consult the database column names to infer the attribute names.

If you are happy with all those assumptions, then this code might just prove quite handy in expediating the process of population of PHP object attributes dynamically from a database.

by Allistair

Minepik - DreamBuildPlay XNA Game Competition Entry Submitted

July 3rd, 2007

Anyone who knows me knows I like gaming, programming, coffee and food. Those first 2 came together recently on July 2nd with the submission of my first XNA game, written in C# therefore, entitled Minepik, which I submitted to the DreamBuildPlay.com competition run by the big M.

I spent hours on Sunday tweaking the game levels with my girlfriend and hit the sack at 0200am, and just found out today they extended the deadline until July 6th. Arrgggh!

Anyway, if you’re a fan of Sudoku or any other type of numeric puzzle game, head over to the Minepik project page in the shed to learn more.

by Allistair

XAMPP on Vista

June 26th, 2007

Getting XAMPP working on Vista requires 2 things as far as I can see. I tried a fresh 1.6.2 install today but it does not work out of the box. Vista complains only about the Apache web server.

Reading around, I saw developers saying all sorts, such as making copies of the XAMPP folder to ensure Vista had the right permissions, or turning Vista’s User Access Control mechanism off, or installing services from the command line and so on and fourth.

But amongst all these suggestions, only 2 things need to be done to get XAMPP (1.6.2 anyway) working on Vista.

First, don’t forget to run setup_xampp.bat in the XAMPP installation folder.

And secondly, you need a file called msvcp71.dll to reside in the root XAMPP folder. I copied this from my old XP Windows/system32 folder, but you might need to get it elsewhere.

If you do these 2 things, XAMPP should fire up no problem.

by Allistair

Handling HTML Entities in XML Passed to Flash Dynamic Text Fields

June 26th, 2007

Today I had to solve the problem of HTML entities such as &apos; showing their full entity-selves when injected dynamically into dynamic text fields.

The entities originated from an XML input stream fed into the Flash movie.

Quite a few folk out there seem to have developed string search and replace functions, but these are limited by the anticipated characters.

I found a much simpler method was just to set the dynamic text field instance’s .html attribute to true, and then inject the text into the .htmlText rather than the .text attribute. Flash apparantly then displays the characters properly.

And I should add that the dynamic text field in question still has anti-aliasing applied in case any of you are worried that using the html attributes do not support it.

Happy days.

by Allistair