Text formatting issues
\ hotkitty (7 May 2008)
. \ Gunnar Hjalmarsson (7 May 2008)
. \ Rob Dixon (7 May 2008)
. \ Dr.Ruud (7 May 2008)
. \ hotkitty (9 May 2008)
. . \ Rob Dixon (9 May 2008)
. \ hotkitty (11 May 2008)
. . \ Rob Dixon (11 May 2008)
. \ hotkitty (11 May 2008)
. \ Dr.Ruud (11 May 2008)

1 msgre: find path to current file, NOT working dire...
2 msgPassing Creadentials and parameters through htt...
7 msghow to shorten this code ? x occur how many tim...
1 msgCompare String is not match !
3 msgCompile error
5 msgchaining defines
2 msgsed split on pipe
4 msgcsv file question
6 msgWriting side of square
11 msgcomparing kit names
2 msgOT: help crle ruin my solaris :-(
6 msggenerating number ranges using rand function
1 msgquestion on unblocking the signals
5 msghowto simplfy this regex if ($string =~/^$match...
7 msghow to reun perl script on other pc without hav...
14 msghow to simplify this script
10 msgdisplaying inline images in HTML email
15 msganother help on input record separator clarity ...
2 msgPerl Expect help
Subject:Text formatting issues
Group:Perl-beginners
From:hotkitty
Date:7 May 2008


 
First and foremost thanks for all the help I've received on this
board, especially Gunnar who keeps this place running!

I've come a long way in my code and am trying to format some text and
then put it into a nice pdf file. My problem is putting the formatted
text into the pdf and for it to display correctly. I am just trying to
justify the text and then set the margins. I can put the text in the
pdf and it looks like it is trying to justify it but it won't wrap to
the next line. I've looked at the documentation for both the
Text::Autoformat and PDF::API2 modules but can't seem to figure it
out.

I have 2 questions: 1. What am I doing wrong in that the text will
appear fine when I "print" it but that it won't appear correctly in
the pdf file? 2. Also, if the text is more than 1 page, how can I get
it to automatically create a new page and continue onto the newly
created page?

My code:


#!/usr/bin/perl

use warnings;

use LWP::Simple;
use HTML::TokeParser;
use PDF::API2;
use Text::Autoformat;


# Print out the subtitle

my $oldtext = "trying to test if this sentence will be formatted the
correct way when it appears in the pdf file. For some reason I just
can't seem to get this to work. Well, maybe I can find help to get
this working. If I could get it to work it would really make my kitty
purrrr";

my $newtext = autoformat $oldtext, { left=>8, right=>70, justify =>
'full' };
print $newtext;

#----create the pdf file----->
my $file = "This PDF";
my $pdf = PDF::API2->new( -file => "$file.pdf" );
my $page = $pdf->page;
$page->mediabox ('A4');
$page->bleedbox(25,25,5,10);
$page->cropbox (7.5,7.5,97.5,120.5);
my %font = (
Helvetica => {
Bold => $pdf->corefont( 'Helvetica-Bold', -encoding =>
'latin1' ),
Roman => $pdf->corefont( 'Helvetica', -encoding =>
'latin1' ),
Italic => $pdf->corefont( 'Helvetica-Oblique', -encoding =>
'latin1' ),
},
Times => {
Bold => $pdf->corefont( 'Times-Bold', -encoding =>
'latin1' ),
Roman => $pdf->corefont( 'Times', -encoding =>
'latin1' ),
Italic => $pdf->corefont( 'Times-Italic', -encoding =>
'latin1' ),
},
);

my $main_text = $page->text;
$main_text->font( $font{'Times'}{'Roman'}, 2 );
$main_text->fillcolor('black');
$main_text->translate( 5, 100 );
$main_text->text("$newtext");

$pdf->save;
$pdf->end();


--
To unsubscribe, e-mail: beginners-unsubscribe
For additional commands, e-mail: beginners-help
http://learn.perl.org/




© 2004-2008 readlist.com