1
package Text::PDF::String;
5
Text::PDF::String - PDF String type objects and superclass for simple objects
6
that are basically stringlike (Number, Name, etc.)
13
use vars qw(@ISA %trans %out_trans);
14
# no warnings qw(uninitialized);
16
use Text::PDF::Objind;
17
@ISA = qw(Text::PDF::Objind);
42
=head2 Text::PDF::String->from_pdf($string)
44
Creates a new string object (not a full object yet) from a given string.
45
The string is parsed according to input criteria with escaping working.
51
my ($class, $str) = @_;
55
$self->{'val'} = $self->convert($str);
56
$self->{' realised'} = 1;
61
=head2 Text::PDF::String->new($string)
63
Creates a new string object (not a full object yet) from a given string.
64
The string is parsed according to input criteria with escaping working.
70
my ($class, $str) = @_;
74
$self->{'val'} = $str;
75
$self->{' realised'} = 1;
80
=head2 $s->convert($str)
82
Returns $str converted as per criteria for input from PDF file
88
my ($self, $str) = @_;
90
$str =~ s/\\([nrtbf\\()]|[0-7]+)/defined $trans{$1} ? $trans{$1} : chr(oct($1))/oegi;
91
# $str =~ s/\\([0-7]+)/chr(oct($1))/oeg; # thanks to kundrat@kundrat.sk
92
1 while $str =~ s/\<([0-9a-f]{2})[\r\n]*/chr(hex($1))."\<"/oige;
93
$str =~ s/\<([0-9a-f]?)\>/chr(hex($1."0"))/oige;
101
Returns the value of this string (the string itself).
111
Returns the string formatted for output as PDF for PDF File object $pdf.
118
my ($str) = $self->{'val'};
120
if ($str =~ m/[^\n\r\t\b\f\040-\176\200-\377]/oi)
122
$str =~ s/(.)/sprintf("%02X", ord($1))/oge;
126
$str =~ s/([\n\r\t\b\f\\()])/\\$out_trans{$1}/ogi;
131
=head2 $s->outobjdeep
133
Outputs the string in PDF format, complete with necessary conversions
139
my ($self, $fh, $pdf, %opts) = @_;
141
$fh->print($self->as_pdf ($pdf));
145
=head2 $s->copy($inpdf, $res, $unique, $outpdf, %opts)
147
Copies an object. See Text::PDF::Objind::Copy() for details
153
my ($self, $inpdf, $res, $unique, $outpdf, %opts) = @_;
156
$res = $self->SUPER::copy($inpdf, $res, $unique, $outpdf, %opts);
157
$res->{'val'} = $self->{'val'};
158
$res->{' realised'} = 1;