LostS has asked for the wisdom of the Perl Monks concerning the following question:

Hey Everyone Again,

OK I am making a PDF with no problem... However I need to word wrap it... currently on long lines it jut cuts it off the side of the page... I need to make it count say ohh 60 characters and then do a \n if the 61st character is a space... if it isn't go backwords until you find the last space and do a \n...
Any suggestions??

-----------------------
Billy S.
Slinar Hardtail - Guildless
Datal Ephialtes - Guildless
RallosZek.Net Admin/WebMaster
Aerynth.Net Admin/WebMaster

perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

Replies are listed 'Best First'.
Re: PDF and Line Wraping
by Beatnik (Parson) on Oct 08, 2001 at 22:17 UTC
    /me suggests Text::Autoformat...
    #!/usr/bin/perl -w use strict; use Text::Autoformat; my $rawtext = "foo bar baz" x 100; my $formatted = autoformat $rawtext, { left=>0, right=>60 };
    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      Hey

      Well I also got it working via Text::Wrap also... However... I need to do this everytime it has a new line... $loc -= 14;

      What do you all think I can do??

      -----------------------
      Billy S.
      Slinar Hardtail - Guildless
      Datal Ephialtes - Guildless
      RallosZek.Net Admin/WebMaster
      Aerynth.Net Admin/WebMaster

      perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'
        I had to do a similar thing with pdflib

        With Text::Wrap and Text::ParseWords...
        @lines = parse2array($doc,"\s");
        $wrap = wrap(" ","", @lines), "\n";
        @lines = parse2array($wrap,"\n");


        This wrapped the text nicely in an array
        so I could deal with the in-house pdf
        formatting constructs.


        here's the parse2array subroutine
        sub parse2array { return quotewords($_[1],0,$_[0]); }

        This is via the Cookbook 1.15 recipe
        cheers...