in reply to Re: saving pdf attachments
in thread saving pdf attachments

Hi Jaap, Here's the code that saves the attachment:

if ($code =~ /quoted-printable/i) { print "printing $num to c:\\$filename\n"; open(K, ">c:\\$filename"); binmode(K); #not sure when to use this, seems to be necessary for pd +f attachments print K MIME::QuotedPrint::decode_qp(join "", @{ $message->{body}->{ +data} }); close K; }

The error when trying to open the bad pdf is:
"The file is damaged and cannot be repaired."

Here's a snippet of a good one (note that in Notepad the
line-endings are little squares - \r I presume):

%PDF-1.2 %ßÜÂÞ - Business Objects 1 0 obj << /Type /Pages /Count 1 /Kids [ 4 0 R ] >> endobj 2 0 obj << /CreationDate (D:20030206205259Z) /ModDate (D:20030206205259Z)

And here's a bad one:

%PDF-1.2 %ßÜÂÞ - Business Objects 1 0 obj << /Type /Pages /Count 17 /Kids [ 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 +R 14 0 R 15 0 R 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R ] >> endobj 2 0 obj << /CreationDate (D:20030206205456Z) /ModDate (D:20030206205456Z)

Any advice would be great!

Replies are listed 'Best First'.
Re: Re: Re: saving pdf attachments
by Jaap (Curate) on Feb 26, 2003 at 23:10 UTC
    It sound like maybe the PDF reader is very critical about line endings. On a windows platform a line ends in \r\n while on *nix platforms a line ends in just \n. It could be that the quotedprintable decoder messes up the newlines.
    Although i do not have a clear answer for you, you can test this more by substituting the line endings in the bad pdf with other line endings:
    my $pdfContent = MIME::QuotedPrint::decode_qp(join "", @{ $message->{b +ody}->{data} }); $pdfContent =~ s/\n/\r\n/g;
    Play a little with the line endings and test it.
      I tried messing with the line endings, and ended up
      with pdfs that open, but the content is missing (blank
      documents). ??? Yet some work perfectly with no
      manipulation of line endings. Thanks for the advice. I'll
      keep plugging away...