Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Perl script/module?

  • 16-05-2014 01:03PM
    #1
    Registered Users, Registered Users 2 Posts: 668 ✭✭✭


    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, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


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


  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭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, Registered Users 2 Posts: 1,110 ✭✭✭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, Registered Users 2 Posts: 668 ✭✭✭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, Registered Users 2 Posts: 1,110 ✭✭✭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, Registered Users 2 Posts: 668 ✭✭✭jamesbil


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


  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭jamesbil


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


  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭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, Registered Users 2 Posts: 668 ✭✭✭jamesbil


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


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


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


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭jamesbil


    great thanks


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 668 ✭✭✭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