Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Perl script/module?

Options
  • 16-05-2014 2:03pm
    #1
    Registered Users Posts: 662 ✭✭✭


    Hi,

    Im told someone familiar with pearl might be able to help me with this one:

    I need to print 365 a5 pages with nothing but a date in the centre of each. A page per day. Must be centred vertical and horizontal in certain font and size.
    eg:
    17
    May
    2014

    Is there a script or perl mudule to do this? Can one be written?

    Total noob btw:o
    Can they be printed in word/pdf?

    Thanks


Comments

  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    CPAN is the best source for Perl modules try PDF::Create


  • Registered Users Posts: 662 ✭✭✭jamesbil


    thanks,
    as I mentioned I have no experience of perl so i s there an easy guide on how to do it?


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Something like the following (WARNING Quick an ugly hack while waiting for a compile to complete on a Friday, untested code Your millage may vary terms and conditions apply)
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use PDF::Create;
    # initialize PDF
    my $pdf = PDF::Create->new('filename'     => 'page_a_day_cal.pdf',
                                            'Author'       => 'Bill James',
                                            'Title'        => 'Page a day calendar',
                                            'CreationDate' => [ localtime ], );
                                            
    # add an A5 sized page
    my $a5 = $pdf->new_page('MediaBox' => $pdf->get_page_size('A5'));
    
    # Prepare a font
    my $f1 = $pdf->font('BaseFont' => 'Helvetica');
    
    #Month names array
    my @mon=qw (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
    
    my $time =  1388576834 ; #epoch time on noon Jan 1st this year
    
    for (0..365){
        # Add a page which inherits its attributes from $a5
        my $page = $a5->new_page;
        my @date=localtime($time);
        my $date_string= $date[3]."\n$mon[$date[4]]\n". $date[5] + 1900;
                           #font #size #x #y #text #alignment 'c' for centred
        $page->stringc($f1, 40, 306, 426, $date_string, 'c');
        $time += (24 * 60 * 60) # increment the day
    }
    $pdf->close();
    


  • Registered Users Posts: 662 ✭✭✭jamesbil


    TYhanks for the help,
    I have installed strawberry perl
    copied the above script and pasted in notepad++ and saved as .pl
    now what?


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Not really a Windows user, but try perl -v in the console

    If that works, try perl c:\path\to\file.pl

    After that play with the font size and x y positioning until you're happy, then print.


  • Advertisement
  • Registered Users Posts: 662 ✭✭✭jamesbil


    ok perl -v returns version
    but the next says cant open perl script no such file


  • Registered Users Posts: 662 ✭✭✭jamesbil


    i saved your script in C:\perl cal\perl_cal
    is this the address I would use?


  • Registered Users Posts: 662 ✭✭✭jamesbil


    ok got a little further.
    now i am getting permission denied on line 8 of the above script
    also getting cant use undefined value as a symbol reference at c:/strawberry/perl/site/lib/PDF/Create.pm line 61


  • Registered Users Posts: 662 ✭✭✭jamesbil


    further still..
    now getting argument "1\nJan\n115" isn't numeric in addition <+> C:my path for line 28


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Hi again, try putting brackets around the addition ie ($date[5] +1900)


  • Advertisement
  • Registered Users Posts: 662 ✭✭✭jamesbil


    great thanks


  • Registered Users Posts: 1,106 ✭✭✭turbot


    jamesbil wrote: »
    great thanks

    if Perl doesnt work, you could:

    1) Create an excel file with a date in A1, then iterate that day by 1 day by choosing a2 = a1 +1 then copying and pasting that for 365 days

    2) Do a mailmerge in Word

    3) Save that as a 365 page PDF in Word.

    look up tutorials on mailmerges for this route!


  • Registered Users Posts: 662 ✭✭✭jamesbil


    ok I'm looking at excel now.
    how do I get it centred vertical and horizontal? and day in one cell then month then year?
    eg:
    17
    May
    2014


Advertisement