John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I want to make some ruled paper, to put writing guidelines on preferred paper stock, create templates for learning calligraphy, etc.

Existing things I see on the web are PDF files or PDF file generators. That seems like a good way to go, since I can deal with measurements and not complete ultra-high resolution bitmaps.

Are there any recommended PDF-create tools for Perl I might use?

—John

Replies are listed 'Best First'.
Re: Making ruled paper
by almut (Canon) on May 01, 2008 at 15:51 UTC

    You could use PDF::API2 or PDF::API2::Lite, for example.  Or you could create a little text file with some PostScript code, and send it to your printer, or view it (or create a PDF from it) with Ghostscript. Adjust the parameters as appropriate. The sample creates equidistant lines, but it could easily be modified to print any other pattern...

    %!PS /numpages 1 def /numlines 32 def /linedistance 20 def /linewidth 0.1 def /linelength 500 def /marginleft 50 def /top 700 def % (by default, all units are in points, i.e. 1/72 inch) linewidth setlinewidth 1 1 numpages { pop /y top def 1 1 numlines { pop marginleft y moveto linelength 0 rlineto stroke /y y linedistance sub def } for showpage } for

    (Sorry, couldn't resist...:)

Re: Making ruled paper
by KurtSchwind (Chaplain) on May 01, 2008 at 15:34 UTC

    Have you tried hitting cpan?

    I've used PDF::Create a bit and it works nicely. Check out the low level 'drawing' functions.

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.
      I was looking in CPAN at the same time I was asking. I found stuff for reading in files and working with metadata, but yes it looks like PDF::Create has the low-level drawing primitives I need.

Re: Making ruled paper
by zentara (Cardinal) on May 01, 2008 at 21:00 UTC
    Well I just happened to have this Gtk2 example handy, that uses it's built-in Ruler widget. You might find it interesting. Just run it, it will auto save when closing.

    Also the Gtkdatabox widget has rulers and criss-crossing gridlines. The only drawback is a perl port is only available for the earliest versions (< 0.30 ) See example screenshots

    I suppose the advantage of using it, is the ease of making modifications to scales.

    #!/usr/bin/perl -w # this example came from Stephen Wilhelm's gtk-perl tutorial, # http://personal.riverusers.com/~swilhelm/gtkperl-tutorial/ # which was derived from the original gtk tutorial, # http://gtk.org/tutorial/ # # ported to gtk2-perl (which wan't hard) by muppet # save function added by zentara use strict; use Glib qw/FALSE/; use Gtk2 -init; my $xsize = 600; my $ysize = 400; my $window; my $table; my $area; my $hrule; my $vrule; # Create the window $window = new Gtk2::Window ( "toplevel" ); $window->signal_connect ("delete_event", sub { &screenshot; exit; }); $window->set_border_width (10); # Create a table for placing the ruler and the drawing area $table = new Gtk2::Table (3, 2, FALSE); $window->add ($table); # Create the drawing area. $area = new Gtk2::DrawingArea; $area->size ($xsize, $ysize); $table->attach ($area, 1, 2, 1, 2, ['expand', 'fill'], ['expand', 'fill'], 0, 0); $area->set_events (['pointer_motion_mask', 'pointer_motion_hint_mask'] +); # The horizontal ruler goes on top. As the mouse moves across the # drawing area, a motion_notify_event event is propagated to the # ruler so that the ruler can update itself properly. $hrule = new Gtk2::HRuler; $hrule->set_metric ('pixels'); $hrule->set_range (7, 13, 0, 20); $area->signal_connect (motion_notify_event => sub { $hrule->event ($_[ +1]) }); $table->attach ($hrule, 1, 2, 0, 1, ['expand', 'shrink', 'fill'], [], 0, 0 ); # The vertical ruler goes on the left. As the mouse moves across the # drawing area, a motion_notify_event event is propagated to the # ruler so that the ruler can update itself properly. $vrule = new Gtk2::VRuler; $vrule->set_metric ('pixels'); $vrule->set_range (0, $ysize, 10, $ysize); $area->signal_connect (motion_notify_event => sub { $vrule->event ($_[ +1]) }); $table->attach ($vrule, 0, 1, 1, 2, [], ['fill', 'expand', 'shrink'], 0, 0 ); # Now show everything $window->show_all; Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } ##################################### sub screenshot{ #we are going to save only the graph area my $gdkwindow = $window->window; my ($width, $height) = $gdkwindow->get_size; # create blank pixbuf to hold the image my $gdkpixbuf = Gtk2::Gdk::Pixbuf->new ('rgb', 0, 8, $width, $height); $gdkpixbuf->get_from_drawable ($gdkwindow, undef, 0, 0, 0, 0, $width, $height); #only jpeg and png is supported !!!! it's 'jpeg', not 'jpg' $gdkpixbuf->save ("$0.jpg", 'jpeg', quality => 100); return FALSE; }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Making ruled paper
by TGI (Parson) on May 01, 2008 at 18:10 UTC

    PDF is definitely one way to go, but don't forget about SVG. It's easy to convert to PDF, and can be easily edited or viewed by a number of applications.


    TGI says moo

Re: Making ruled paper
by leocharre (Priest) on May 01, 2008 at 21:20 UTC
    Why not use inkscape, sodipodi, skencil - and make a vector layout. Then you don't have to worry about scale (and cpu, mem, etc). You print out the size you want.
      couldn't agree more about the recommendations to use SVG/inkscape/etc...unless you have a specific need to use PDF throughout. SVG has a very good (in my opinion) font creation/description ability, geared towards calligraphy.
      the hardest line to type correctly is: stty erase ^H
        If I wrote/generated SVG in an XML file, how do I print that nicely?
Re: Making ruled paper
by duelafn (Parson) on May 02, 2008 at 00:53 UTC

    I tend to generate PostScript code (by hand or using perl) then, if necessary, convert the result to PDF.

    Good Day,
        Dean