Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Creating Open Office Doc with Hebrew

by sachss (Sexton)
on Sep 18, 2016 at 21:51 UTC ( #1172080=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to create an Open Office Document with Hebrew characters within it.
I have a separate file defining the Hebrew characters, and the file to create the Open Office Document.

myHebrew.pl
use charnames (); #URL: http://perldoc.perl.org/perluniintro.html #URL: https://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_al +phabet our $alef = charnames::string_vianame("HEBREW LETTER ALEF"); our $bet = charnames::string_vianame("HEBREW LETTER BET"); our $gimel = charnames::string_vianame("HEBREW LETTER GIMEL"); our $dalet = charnames::string_vianame("HEBREW LETTER DALET"); our $he = charnames::string_vianame("HEBREW LETTER HE"); our $vav = charnames::string_vianame("HEBREW LETTER VAV"); our $zayin = charnames::string_vianame("HEBREW LETTER ZAYIN"); our $het = charnames::string_vianame("HEBREW LETTER HET"); our $tet = charnames::string_vianame("HEBREW LETTER TET"); our $yod = charnames::string_vianame("HEBREW LETTER YOD"); our $final_kaf = charnames::string_vianame("HEBREW LETTER FINAL KAF"); our $kaf = charnames::string_vianame("HEBREW LETTER KAF"); our $lamed = charnames::string_vianame("HEBREW LETTER LAMED"); our $final_mem = charnames::string_vianame("HEBREW LETTER FINAL MEM"); our $mem = charnames::string_vianame("HEBREW LETTER MEM"); our $final_nun = charnames::string_vianame("HEBREW LETTER FINAL NUN"); our $nun = charnames::string_vianame("HEBREW LETTER NUN"); our $samekh = charnames::string_vianame("HEBREW LETTER SAMEKH"); our $ayin = charnames::string_vianame("HEBREW LETTER AYIN"); our $final_pe = charnames::string_vianame("HEBREW LETTER FINAL PE"); our $pe = charnames::string_vianame("HEBREW LETTER PE"); our $final_tsadi = charnames::string_vianame("HEBREW LETTER FINAL TSAD +I"); our $tsadi = charnames::string_vianame("HEBREW LETTER TSADI"); our $qof = charnames::string_vianame("HEBREW LETTER QOF"); our $resh = charnames::string_vianame("HEBREW LETTER RESH"); our $shin = charnames::string_vianame("HEBREW LETTER SHIN"); our $tav = charnames::string_vianame("HEBREW LETTER TAV"); our $geresh = charnames::string_vianame("HEBREW PUNCTUATION GERESH"); our $gershayim = charnames::string_vianame("HEBREW PUNCTUATION GERSHAY +IM"); 1;

and "createOODoc.pl"

#!/usr/bin/perl -w use strict; use warnings; require "myHebrew.pl"; our ($alef, $bet, $gimel, $dalet, $he, $vav, $zayin, $het, $tet, $yod, $final_kaf, $kaf, $lamed, $final_mem, $mem, $final_nun, $nun, $samekh, $ayin, $final_pe, $pe, $final_tsadi, $tsadi, $qof, $resh, $shin, $tav, $geresh, $gershayim); use OpenOffice::OODoc; use utf8; my $header = $bet . $samekh . $gershayim . $dalet; my $doc = odfDocument( file => "Parsha.odt", create => 'text' ); my $p = $doc->appendParagraph( text => "", style => "optionalParagraphStyle" ); $doc->extendText($p, $header); $p = $doc->appendParagraph(text => $header, style => "optionalParagraphStyle" ); $doc->save; exit 0; ### End of File ###

When I run this, I get

Use of uninitialized value in lc at C:/Perl64/site/lib/OpenOffice/OODoc/File.pm line 378.

Cannot decode string with wide characters at C:/Perl64/lib/Encode.pm line 176.

What am I doing wrong? Can someone help me correct this?

Replies are listed 'Best First'.
Re: Creating Open Office Doc with Hebrew
by Your Mother (Archbishop) on Sep 18, 2016 at 22:34 UTC

    This might do it, untested, no experience with it, just going by the error–

    use Encode; $doc->extendText($p, encode_utf8 $header);

    The error seems to indicate the $doc expects raw bytes instead of characters.

    Update. Tested now, I was right. Need both the above and the second one I missed–

    $p = $doc->appendParagraph(text => encode_utf8($header), style => "optionalParagraphStyle" );

    Creates a doc with these two lines–

    בס״ד
    בס״ד
      That did it. Thanks.
Re: Creating Open Office Doc with Hebrew
by Anonymous Monk on Sep 18, 2016 at 22:07 UTC

    What am I doing wrong? Can someone help me correct this?

    You forgot to check/ddumper the value of  $header

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1172080]
Approved by kevbot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-07-03 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?