use PDF::API2; my $pdf = PDF::API2->new(); my $page = $pdf->page(); my $text = $page->text(); my $font = $pdf->corefont('Helvetica-Roman'); $text->font($font, 16); $text->translate(50, 620); $text->text('Print some text'); # define rect with gfx my $rect = $page->gfx; $rect->rect(50, 560, 400, 18); $rect->fillcolor('#000000'); $rect->fill(); # Go back to text $text->fillcolor('#ffffff'); $text->translate(62, 565); $text->text('Print text in rect'); $pdf->saveas('test.pdf');