14.2.12

PDF-CreateSimple

In the belief that Google will last longer than my computers or backups, I record this for my own info.

I have been tasked to produce a receipt, and the method proposed is for the office to feed relevant data into a web form, then advise the recipient that the receipt can be collected from a clickable link.

First problem is how to generate the PDF. I selected PDF-CreateSimple from CPAN. It requires PDF::API2 which was available as a package for this SUSE.

PDF-CreateSimple however required building, it had a faulty Makefile, but changing the paths from lib/PDF/CreateSimple.pm to ./CreateSimple.pm fixed it enought to get it installed.

Much reading, and this script produced a PDF like what is shown in the image below;

#!/usr/bin/perl

use PDF::CreateSimple;

my $pdfPath = '/home/owen/yyy.pdf';
my $pdfFile = PDF::CreateSimple->new($pdfPath);

           #--------------------------------------
           # Add a new page
           #--------------------------------------
           # $pdfFile->addNewPage;

           #--------------------------------------
           # Write Text
           #--------------------------------------

$pdfFile->drawText('Verdana 12pt ','Verdana',12,200,350,'blue');
$pdfFile->drawText('Courier 14pt ','Courier',14,200,250,'blue');
$pdfFile->drawText('Times-Italic 16pt ','Times-Italic',16,200,150,'blue');
$pdfFile->drawText('Helvetica 18pt ','Helvetica',18,200,50,'blue');

$pdfFile->drawText('12pt 500,200','Verdana',12,500,200,'black');
$pdfFile->drawText('14pt 300,200','Verdana',14,300,200,'black');
$pdfFile->drawText('16pt 100,200','Verdana',16,100,200,'black');
$pdfFile->drawText('17pt 200,100','Verdana',17,300,100,'black');
$pdfFile->drawText('18pt 300,400','Verdana',18,300,400,'black');
$pdfFile->drawText('19pt 300,500','Verdana',19,300,500,'black');
$pdfFile->drawText('20pt 300,300','Verdana',20,300,300,'black');
$pdfFile->drawText('21pt 300,700','Verdana',21,300,700,'black');
$pdfFile->drawText('42pt 300,600','Verdana',42,300,600,'black');

$pdfFile->drawLine(490,0,490,841.89,2,'black');
$pdfFile->drawRectangle(60,60,100,100,5,'blue');

$pdfFile->drawImage('/home/owen/PCUG_Logo_b.png',40,680,0.20);

$pdfFile->closeFile;

15.9.11

28.8.11

Random Numbers and Bluetooth

I keep losing this page

I came accross this site and having several BT dongles, decided to give it a try.

It relies on the bccmd out of bluez. Worked well with an el cheapo $2 dongle.

The script below produced a low of 0, and a high of 65535, so presumeably it is filling a 16 bit register with 1s and 0s and bccmd is producing a decimal number. My bccmd is a binary, so guess I will have find the source for it somewhere.



======================================

#!/usr/bin/perl

use strict;

my $bccmd = "/usr/sbin/bccmd rand";

my $high_nr = 0;

my $low_nr = 65568;

foreach (1 .. 100000){

my $cmd_output = `$bccmd`;

#print "$cmd_output\n"; # Random number: 0x8fd7 (36823)

if ($cmd_output =~ m/\((\d+)/)

{$high_nr = $1 if ($1 > $high_nr);$low_nr = $1 if ($1 < $low_nr) };

}



print "$low_nr\t$high_nr\n";

======================================


I generated 1000000 random numbers, took 7 hours and 11 minutes (40 numbers per second) and produced a file 5830542 bytes in size.

Then statistics time, but it seems my grasp of stats is extremely poor as I was clueless as to what I was doing. Never the less I took the million decimal numbers and calculated these facts;



Home generated stats:



mean is 32779

Lowest nr is 0

Highest number is 65535



Stats using the perl module Statistics::Descriptive

Minumun Value 0

Lower quantile 16410 (guess expected would be 65536/4 or 16384 - close?)

Second quantile 32786 (expected 65536/2 or 32768 - also close)

Third quantile 49164

Fourth quantile 65535

Number counted 1000000

Mean of count 32779.339758 (expected 32768)



key = 8191.875, count = 124887 (expected is 1000000/8 or 125000)

key = 16383.75, count = 124690

key = 24575.625, count = 125487

key = 32767.5, count = 124680

key = 40959.375, count = 124870

key = 49151.25, count = 125195

key = 57343.125, count = 124590

key = 65535, count = 125601