in reply to Writing PDF binary file from stream yields malformed PDF
Do you have an example PDF that breaks? I tried this code on my Mac system with a 4.9 MB pdf in Perl 5.18 and the output PDF opened without error in Adobe Reader for Mac.