Hi, I have one xml file, I extracted some comments and saved in pdf file.I written code like this
#!/usr/bin/perl use warnings; use strict; use PDF::API2; use PDF::API2::Page; use XML::LibXML::Reader; use Data::Dumper; my $file; open( $file, 'formal.xml'); my $reader = XML::LibXML::Reader->new( IO => $file ) or die ("unab +le to open file"); my %nums; while ($reader->nextElement( 'Number' )) { my $number = $reader->copyCurrentNode(1)->textContent; $reader->nextElement( 'address' ); my $node = $reader->copyCurrentNode(1); my $infohash = { house => $node->getElementsByTagName( 'housenumber' )[0]->tex +tContent, street => $node->getElementsByTagName( 'streetname' )[0]->tex +tContent, }; $nums{$number} = $infohash; } "syntax error here "}" my $pdf = PDF::API2->new(); # $pdf->mediabox('Letter'); my $font = $pdf->corefont('Times-Roman'); my $page = $pdf->page(); $page->mediabox('Letter'); my $cnt=0; for my $line (split /\n/, Dumper(%nums)) { if ($cnt > 46) { $page = $pdf->page(); $cnt=0; } my $text = $page->text(); $text->font($font,14); $text->translate(72, 720-$cnt*14); $text->text($line); ++$cnt; } $pdf->saveas('svr.pdf');
when I run this code it extracting and printing extracted tags as it is in pdf file like as shown below.
$VAR1 = '24'; $VAR2 = '<Address> <housenumber="120"/> <streetname="xxx"/> </Address>'; $VAR3 = '25'; $VAR4 = '<Address> <housenumber="150"/> <streetname="xxx"/> </Address>'; $VAR5 = '27'; $VAR6 = '<Address> <housenumber="140"/> <streetname="xxx"/> </Address>';
like that but i need to print data in pdf like this
number: 24, address information of the student. Information:Address, housenumber="120", streetname="xxx". number: 25, address information of the student. Information:Address, housenumber="150", streetname="xxx". number: 27, address information of the student. Information:Address, housenumber="140", streetname="xxx".
I need to print output like this in pdf file. In my Written code I am printing xml tags as it is. What should i do to print like, help me with script. I cahnged little bit and i am getting syntax errors at " ")[" near and "}" before pdf starts.

In reply to perl script to print data like this in pdf. by veerubiji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.