Apr 28, 2009, 9:52 AM
Post #1 of 1
Need help with PDF generation
I'm running into a weird problem here and was wondering if anyone has solved this problem. I have a text file that contains the following text:
"This is some text"
"This is yet another text"
If I have multiple white spaces between each word, the alignment is not preserved when I read the string from the text file and write it to a PDF. However, when I view this using a text editor, the alignment is preserved. Meaning, if "s" in the word "some" appears to be right on top of the character "y" in the word "yet", this alignment is lost when I write this to a PDF.
Do you know how I can write strings to a PDF file and maintain the spaces between words just like a regular text file??
Here's the code I'm using to read the text file and write the PDF.
my $pdf = new PDF::Create('filename'=>"test.pdf", 'Version'=>1.2,'PageMode'=>'UseOutlines','Author'=>'','Title'=>'',);
my $root = $pdf->new_page('MediaBox'=>[0,0,595, 800]);
my $fontnorm = $pdf->font('Subtype'=>'Type1','Encoding'=>'WinAnsiEncoding','BaseFont'=>'Helvetica');
my $page = $root->new_page;
open (FILE, "<test.txt");
foreach $line (<FILE>)
$page->string($fontnorm, 10, 20, $ypos-=$incr, $line);
Any help would be greatly appreciated!
(This post was edited by bpejman on Apr 28, 2009, 10:01 AM)