in reply to Re: PDFlib context pointer (nil) is invalid
in thread PDFlib context pointer (nil) is invalid

I suggest you test the creation statement; I am not familiar with this module but the error messages suggest the problem is in the beginning.

$p = PDF_new() or die "PDF creation failed\n";
1 Peter 4:10