Printing Car Cards in Advance for Freight Commander

The existing version of the model railroading operations “train game” program that 4dNtrak uses produces paper car cards that can be printed in advance and does not require equipment to be hauled to exhibition shows.  When I showed off the current progress of Freight Commander to the club, it became clear that this gaming style was still important.  Since Freight Commander is built around the idea of an active layout, I didn’t have a clear idea on how to implement this static play mode, however I’ve now figured it out.

The big problem is printing.  Train Game (I wish I came up with a better name) displays car cards as a table rendered in HTML, that when printed in Internet Explorer 8, had the car cards line up so that pages could be stacked and cut all at once.  Unfortunately, IE8 came and went and this is now broken with modern web-browsers.  If this sounds like a bad implementation, that’s because it is.  Formatting got screwed up and now train game is pretty awkward to use.

Freight Commander is built around a MySQL database, and at this time, I’m planning an web-based frontend like the existing train game implementation.  This gives me easy access for connectivity and hosting.  Like train game, I wouldn’t be able to get direct access to the server so formatting would need to render in the browser which isn’t a good solution.  It occurred to me the other day that I can still use the browser to deliver content if it sent via another format, like PDF!  I can do all my rendering on the server where I have control over the formatting and then send it to the browser for delivery without having to worry about it changing.  Problem solved.

Some cursory research revealed that several libraries exist for producing PDF documents.  One that appealed to me is FPDF, which is a PHP class which allows users to “generate PDF files with pure PHP…” and the “F from FPDF stands for Free” where it may be used and modified as needed.  It’s a viable solution to this problem that I’ll be exploring as I continue development.

Since I have a printing solution in mind, I wrote a new stored procedure for the Freight Commander game logic to produce shipping orders in advance for a given layout so that the client will be able to download a PDF containing car cards.  If you’re interested in looking (and you should, since it’s highly documented), search for #uspStartOfflineGame() in the source code, located here:  https://github.com/tbdye/FreightCommander/blob/master/MySQL/procedures.sql

-td

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s