use Barcode::DataMatrix; use PDF::API2; my $x = 100; my $y = 200; my $sz = 10; my $mat = Barcode::DataMatrix->new()->barcode('Hello World'); my $pdf = PDF::API2->open('original.pdf'); my $page = $pdf->openpage(1); my $content = $page->gfx(); for my $i (0 .. $#$mat) { for my $j (0 .. $#{$mat->[$i]}) { if ($mat->[$i][$j]) { $content->rect($x+$sz*$j, $y-$sz*$i, $sz, $sz); } } } $content->fill(); $pdf->saveas('modified.pdf');