Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Images with PDF::Builder

by Stickybit (Novice)
on Sep 12, 2019 at 11:58 UTC ( [id://11106063]=perlquestion: print w/replies, xml ) Need Help??

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

Hi everyone

This one is really bugging me - an the example is really hard to understand ( https://metacpan.org/source/PMPERRY/PDF-Builder-3.016/examples/Content.pl )

I would like to a add a image to my PDF, and looking in the example, didn't actually help me (how can you call methods on a object without initializing the object at first? - at line 49 in the example).

If someone could post a simple example adding a image to a .pdf - that would be much apreatiated.

Thanks in advance.

Replies are listed 'Best First'.
Re: Images with PDF::Builder
by poj (Abbot) on Sep 12, 2019 at 12:49 UTC

    The call to sub nextPage() on line 37 initialises the objects

    #!/usr/bin/perl use strict; use PDF::Builder; my $pdf = PDF::Builder->new(); my $page = $pdf->page(); my $img_obj = $pdf->image_jpeg('myimage.jpg'); my $grfx = $page->gfx(); $grfx->image($img_obj, 5,5, 500,500); $pdf->saveas('new.pdf');
    poj
      Thanks .. worked as a charm. :-)
Re: Images with PDF::Builder
by roboticus (Chancellor) on Sep 12, 2019 at 16:34 UTC

    Stickybit:

    When the documentation of a module doesn't give you quite enough detail, I find it helpful to go to the tests (./t/) directory for the module, and then grep the files to find which tests exercise the function of interest. Then you can see how to call the function. One advantage of this method is that authors try to make the tests as small as possible, so it won't be cluttered up with a bunch of extraneous things you don't need.

    I don't have PDF::Builder on my machine, so I just chose a module at random (Ref::Util) from my cpan folder and scanned through the test directory for the test files that use the "is_plain_hashref(" function:

    $ grep -r "is_plain_hashref(" .cpan/build/Ref-Util-0.204-0/t/*.t .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: is_p +lain_hashref($value), .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: "is_ +plain_hashref($plain_type) is true", .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: !is_ +plain_hashref($value), .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: "is_ +plain_hashref($plain_type) is false", .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: !is_plai +n_hashref($value), .cpan/build/Ref-Util-0.204-0/t/all-permutations.t: "is_plai +n_hashref($blessed_type) is false", .cpan/build/Ref-Util-0.204-0/t/functions.t: is_plain_hashre +f => is_plain_hashref($value), .cpan/build/Ref-Util-0.204-0/t/magic-readonly.t:ok( is_plain_hashref($ +rh2), 'They are not plain!' );

    From here, you can simply look at the test files and see how they do it.

    Note: for poorly-tested modules, you may not find anything useful. But in that case, how interested are you in using the module? :^P

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found