PDFs, barcodes and more, oh my!

1 view
Skip to first unread message

Jeff Rafter

unread,
Nov 5, 2007, 11:28:46 AM11/5/07
to baobab-v...@googlegroups.com
Hi Baobab volunteers!

I am hoping one of you (or more) are old Perl junkies and can help us out. In the past couple weeks we came up with a plan that will help in rolling out the system at a couple of locations. First some background: In Malawi (like many other countries) we are coming from a paper based system. Practically this means each patient has a "Mastercard" which is a big card that explains who thet are, why/when they started HIV treatments, and some details about each visit (each page of the mastercard represents one year). There is a PDF in the files as an example.

http://groups.google.com/group/baobab-volunteers/web/mastercard.pdf

Last week we used Ruby FPDF to build the mastercard printout. We also hacked in a couple of helpers for testing (which should be expanded). We have come up with a plan that requires someone to scan in the barcode on the form, pass it through a printer and the system will print out the most recent visit. We are looking to pilot this soon. However we need some barcode loving on the form. I built a quick barcode extension using the info from the FPDF website (prints UPC-A and EAN13). But what we really would like to have is a CODE128 barcode. I found a public version of this on CPAN (in Perl) here:

http://search.cpan.org/~wrw/Barcode-Code128-2.01/lib/Barcode/Code128.pm

Ideally we would translate this to Ruby and shove it into an extension. I was wondering if anyone wanted to take on the task. I uploaded the files I completed to the group while we continue to sort out git repo access

http://groups.google.com/group/baobab-volunteers/web/fpdf_test_helper.rb
http://groups.google.com/group/baobab-volunteers/web/fpdf_barcode_extension.rb
http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf.rb

There is a very limited test here... obviously I was hacking away when I should have been BDDing:

http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf_test.rb

Apart from the new barcode extension we need to add some better tests to this. The biggest things to test:

it should print out only the visits when the only_visit option is set
it should print out only the header when the only_header option is set
it should print out only the data when the only_data option is set
it should create one page for each visit year
it should output the visit text at the specified X, Y position for each month
it should print the barcode on each page
it should print the dates using a Euro format (not ISO 8601)

Obviously testing how each field is output and so forth is a big deal too.... Any takers?

Thanks!
Jeff Rafter

MagpieUK

unread,
Nov 5, 2007, 4:42:32 PM11/5/07
to Baobab Volunteers
Don't know if this might help but looks promising:

http://gbarcode.rubyforge.org/rdoc/index.html

On Nov 5, 4:28 pm, "Jeff Rafter" <jeffraf...@gmail.com> wrote:
> Hi Baobab volunteers!
>
> I am hoping one of you (or more) are old Perl junkies and can help us out.
> In the past couple weeks we came up with a plan that will help in rolling
> out the system at a couple of locations. First some background: In Malawi
> (like many other countries) we are coming from a paper based system.
> Practically this means each patient has a "Mastercard" which is a big card
> that explains who thet are, why/when they started HIV treatments, and some
> details about each visit (each page of the mastercard represents one year).
> There is a PDF in the files as an example.
>
> http://groups.google.com/group/baobab-volunteers/web/mastercard.pdf
>
> Last week we used Ruby FPDF to build the mastercard printout. We also hacked
> in a couple of helpers for testing (which should be expanded). We have come
> up with a plan that requires someone to scan in the barcode on the form,
> pass it through a printer and the system will print out the most recent
> visit. We are looking to pilot this soon. However we need some barcode
> loving on the form. I built a quick barcode extension using the info from
> the FPDF website (prints UPC-A and EAN13). But what we really would like to
> have is a CODE128 barcode. I found a public version of this on CPAN (in
> Perl) here:
>
> http://search.cpan.org/~wrw/Barcode-Code128-2.01/lib/Barcode/Code128.pm
>
> Ideally we would translate this to Ruby and shove it into an extension. I
> was wondering if anyone wanted to take on the task. I uploaded the files I
> completed to the group while we continue to sort out git repo access
>

> http://groups.google.com/group/baobab-volunteers/web/fpdf_test_helper.rbhttp://groups.google.com/group/baobab-volunteers/web/fpdf_barcode_ext...http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf.rb


>
> There is a very limited test here... obviously I was hacking away when I
> should have been BDDing:
>

> http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf_t...

Mike McKay

unread,
Nov 6, 2007, 1:39:41 AM11/6/07
to baobab-v...@googlegroups.com
Nice Magpie! So the question is whether someone can make it work with
FPDF. It seems like this is something that would be generally useful for
the FPDF library (not just for Baobab).

Nina Jansen

unread,
Nov 6, 2007, 5:24:03 AM11/6/07
to Baobab Volunteers
Hi

I am a bit of a perl-hacker but I have this huge dealine coming up. If
this can wait (for a month or so) I'd love to attack it.

:-)

Nina

On Nov 5, 5:28 pm, "Jeff Rafter" <jeffraf...@gmail.com> wrote:
> Hi Baobab volunteers!
>
> I am hoping one of you (or more) are old Perl junkies and can help us out.
> In the past couple weeks we came up with a plan that will help in rolling
> out the system at a couple of locations. First some background: In Malawi
> (like many other countries) we are coming from a paper based system.
> Practically this means each patient has a "Mastercard" which is a big card
> that explains who thet are, why/when they started HIV treatments, and some
> details about each visit (each page of the mastercard represents one year).
> There is a PDF in the files as an example.
>
> http://groups.google.com/group/baobab-volunteers/web/mastercard.pdf
>
> Last week we used Ruby FPDF to build the mastercard printout. We also hacked
> in a couple of helpers for testing (which should be expanded). We have come
> up with a plan that requires someone to scan in the barcode on the form,
> pass it through a printer and the system will print out the most recent
> visit. We are looking to pilot this soon. However we need some barcode
> loving on the form. I built a quick barcode extension using the info from
> the FPDF website (prints UPC-A and EAN13). But what we really would like to
> have is a CODE128 barcode. I found a public version of this on CPAN (in
> Perl) here:
>
> http://search.cpan.org/~wrw/Barcode-Code128-2.01/lib/Barcode/Code128.pm
>
> Ideally we would translate this to Ruby and shove it into an extension. I
> was wondering if anyone wanted to take on the task. I uploaded the files I
> completed to the group while we continue to sort out git repo access
>

> http://groups.google.com/group/baobab-volunteers/web/fpdf_test_helper.rbhttp://groups.google.com/group/baobab-volunteers/web/fpdf_barcode_ext...http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf.rb


>
> There is a very limited test here... obviously I was hacking away when I
> should have been BDDing:
>

> http://groups.google.com/group/baobab-volunteers/web/mastercard_pdf_t...

MagpieUK

unread,
Nov 7, 2007, 2:42:24 AM11/7/07
to Baobab Volunteers
I posted the query into the ruby mailing list and they suggested we
look at using a code 128 font.

So here is one I found http://freebarcodefonts.dobsonsw.com/#Code128

Licensing info : http://freebarcodefonts.dobsonsw.com/Barcode_Font_Licensing.htm
which looks ok to me as he offers a freeware license. Would be worth
checking with him.

So now we just need to workout the encoding.

These links may be of use for this:

http://freebarcodefonts.dobsonsw.com/Code128Transformation.htm
PHP example http://www.mribti.com/barcode/download.php
Java http://www.pdflib.com/en/pdflib-cookbook/fonts-and-encodings/barcode-font/


Lee Irving(MagpieUK)

unread,
Nov 7, 2007, 3:57:13 AM11/7/07
to Baobab Volunteers
Final links for now

http://www.openbarcode.org/wiki/Code_128_specification
http://code.google.com/p/barcode-generator/
http://www.itgens.cn/snippets/show/4482


So the options for us seem to be:

1) Convert the Perl / PHP scripts using GD to ruby using ruby-gd
2) Use the Code128 font and work out the character map
3) Use the Gbarcode creator to create the barcode and then insert into
PDF

I am betting the option 3 is the simplest but option 1 would be the
coolest :)

Option 2 might work depending on the license.


On Nov 7, 7:42 am, MagpieUK <irvin...@gmail.com> wrote:
> I posted the query into the ruby mailing list and they suggested we
> look at using a code 128 font.
>

> So here is one I foundhttp://freebarcodefonts.dobsonsw.com/#Code128


>
> Licensing info :http://freebarcodefonts.dobsonsw.com/Barcode_Font_Licensing.htm
> which looks ok to me as he offers a freeware license. Would be worth
> checking with him.
>
> So now we just need to workout the encoding.
>
> These links may be of use for this:
>
> http://freebarcodefonts.dobsonsw.com/Code128Transformation.htm
> PHP examplehttp://www.mribti.com/barcode/download.php

> Javahttp://www.pdflib.com/en/pdflib-cookbook/fonts-and-encodings/barcode-...

Lee Irving(MagpieUK)

unread,
Nov 7, 2007, 6:13:25 AM11/7/07
to Baobab Volunteers
Ok I could not wait to test so here is a generated Code128 barcode.

It saves the file into the public directory in a barcode directory so
it can easily be accessed. Rather than an ActionView::Base extension I
also added a ActionController::Base extension so in the controller i
can simply say barcode 'MAGPIEUK', :encoding_format =>
Gbarcode::BARCODE_128

http://baobab-volunteers.googlegroups.com/web/MAGPIEUK.png

It should be a relatively simple PDF action to include the image in
the file. Will look at this next.

Lee Irving(MagpieUK)

unread,
Nov 7, 2007, 6:24:50 AM11/7/07
to Baobab Volunteers
The image way looks very easy to do however looking again at the FPDF
examples I have found the following which looks very like the one
supplied by Jeff. It is currently PHP but talks to FPDF

http://tom.harding.free.fr/downloads/code128barcode/

So we may now have an option 4 :)

Jeff Rafter

unread,
Nov 7, 2007, 9:14:17 AM11/7/07
to baobab-v...@googlegroups.com
Hi Magpie great work!

I really did search for stuff and didn't come up with half of the links you did :) I looked into the code 128 fonts and just wasn't excited about that solution. In general for two reasons: (1) I didn't find a free font (you beat me again!) and (2) the thought of embedding the free font into the FDPF lib as a font definition made me shudder. If someone else is excited to do either of those then I am game to sit on the sidelines and cheer :).

I looked into gbarcode yesterday after you sent over the links and thought it was cool but didn't get it working as fast as you did. I have two questions: (1) do you have to output to a file or can you do it all in mem? (2) Do you know how the image scales, as it is png and not vector I am thinking it would take some toying to get it to scale/scan but it should work. This is the code for embedding an image:

    self.Image(RAILS_ROOT + '/public/images/magpie_barcode.png',13,13,80,0,'PNG') # x,y,w,h, JPEG and PNG supported

Looking at FPDF it would be pretty easy to write an extension that handled reading from memory instead of a file (hacking on the parsepng method). I can hack that out if desired.

As for option 4: how did you find that!? you must have some serious google-fu. A quick scan looks like this is pretty easy to translate-- maybe I will have a go at that unless someone else beats me to it. In any event I think that the gbarcode stuff is going to be useful for us.

Awesome work again!

Jeff/njero

Lee Irving(MagpieUK)

unread,
Nov 7, 2007, 12:21:58 PM11/7/07
to Baobab Volunteers
Don't know if we can leave the image in memory but will take a look.
Worst case is we just wright something to clean up after.

As for scaling we can pass a height and width to the barcode function
so we can probably make them what ever size we need.


Reply all
Reply to author
Forward
0 new messages