in reply to How can I print hash content to pdf file ?

Have you checked that you get the correct data and can print it to the screen instead of a PDF file?

use strict; use PDF::API2::Simple; my %data = (...); #my $pdf = PDF::API2::Simple->new( file => 'file.pdf' } foreach my $keys( sort { $data{$a} <=> $data{$b}} keys %data ){ print $data{$keys}{'Name'}, "\n"; }

The next thing would be to check that you can actually print to the PDF file. Try printing a plain list to a PDF file:

use strict; use PDF::API2::Simple; my @names = (Diana Bruce Clark); my $pdf = PDF::API2::Simple->new( file => 'file.pdf' } foreach my $name( @names ){ $pdf->text($name}); }

One of the two programs should work for you and should help you determine where your problem lies, in the data or in writing the data to the PDF.

Replies are listed 'Best First'.
Re^2: How can I print hash content to pdf file ?
by vkk05 (Initiate) on Dec 10, 2017 at 09:26 UTC
    Yes, I tried printing a plain text something like this: $pdf->text( 'Hello PERL', x => 300, y => 300 ); The plain text printing perfectly. Is there any syntax to print the hash ?

      If you need to supply coordinates, why don't you supply them when you print in your loop?

      Try maybe printing stuff into separate lines?

      my $offset = 300; for my $line (@names) { $pdf->text( "Hello PERL", x => 300, y => $offset ); $offset = $offset + 50; # move to "next line" };

      I chose 50 by random, maybe you want 12 (points) or 24.

        Passing offset is a good suggestion. But I need to print hash value instead of 'Hello Perl'. I mean inside $pdf->text what can be written?