Re: PDF suggestions ?
by MidLifeXis (Monsignor) on Mar 16, 2012 at 12:44 UTC
|
There is a problem when i am writing text to the pdf encoded in utf8.
What sort of a problem? Are there error messages being generated? Are moons turning to blood? Is your machine emitting flames?
Error messages, code that you have tried (inside of <code>...</code> tags), version of perl, and other pertinent information could be helpful.
| [reply] [d/l] |
Re: PDF suggestions ?
by kcott (Archbishop) on Mar 16, 2012 at 13:03 UTC
|
| [reply] |
Re: PDF suggestions ?
by CountZero (Bishop) on Mar 16, 2012 at 13:39 UTC
|
There is a problem when i am writing text to the pdf encoded in utf8. What kind of problem? None of the text gets included? Or it gets included but in a wrong encoding? The whole PDF file became corrupt?
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] |
Re: PDF suggestions ?
by Anonymous Monk on Mar 16, 2012 at 13:19 UTC
|
my $utftext=qq(SOme UTF text);
#$utftext=encode("utf8", decode("cp1251", $utftext) ) ;
#$utftext=encode("utf8", $utftext ) ;
my $pdf;
$pdf = PDF::API2->open('first.pdf');
my $page_number = 1;
my $page = $pdf->openpage($page_number);
my $font = $pdf->corefont('Verdana');# ,-encoding => 'utf8'
my $text = $page->text();
$text->font($font, 30);
$text->translate(359, 713);
$text->text("$utftext");
$pdf->saveas('mysaved.pdf');
| [reply] [d/l] |
|
|
(I'm supposing you're the same AM as in the OP)
Don't use the corefonts, use ttfont() instead and specify the path to the respective .ttf file directly (a subset of the font, i.e. the required glyphs, will automatically be embedded into the PDF):
my $font = $pdf->ttfont('/path/to/verdana.ttf');
See also Re^2: PDF::API2 / unicode characters.
(And do not encode("utf8", $utftext) the string yourself... — leave it decoded, so Perl can handle Unicode characters correctly.) | [reply] [d/l] [select] |
|
|
I got the following error:
Use of uninitialized value in pack at C:/Perl/site/lib/Font/TTF/Cmap.pm line 329.
Any ideas how to solve the problem ?
my $utftext=qq(SOme UTF text);
#$utftext=encode("utf8", decode("cp1251", $utftext) ) ;
#$utftext=encode("utf8", $utftext ) ;
my $pdf;
$pdf = PDF::API2->open('first.pdf');
my $page_number = 1;
my $page = $pdf->openpage($page_number);
#my $font = $pdf->corefont('Verdana');# ,-encoding => 'utf8'
my $font = $pdf->ttfont('mypath/times.ttf');
my $text = $page->text();
$text->font($font, 30);
$text->translate(359, 713);
$text->text("$utftext");
$pdf->saveas('new.pdf');
| [reply] [d/l] |
Re: PDF suggestions ?
by JavaFan (Canon) on Mar 16, 2012 at 13:44 UTC
|
There is a problem when i am writing text to the pdf encoded in utf8.
Then at least one of two things are happening:
- There's a bug.
- You are doing it wrong.
Good luck!
Do keep in mind, the more specific your question, the more specific your answer.
| [reply] |
Re: PDF suggestions ?
by Anonymous Monk on Mar 16, 2012 at 14:09 UTC
|
Problem with the encoding type. After i open the new file the text doesn't show properly. | [reply] |
|
|
Could be the encoding, could be the fonts (as Elijah mentioned), could be anything else, depending on what you mean by "doesn't show properly".
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
| [reply] |