#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    15
    Rep Power
    0

    How to read raw pdf data


    I'm using MimeMailParser to parse an email message. The code also allows you to get attachment data. The problem I'm having is reading the raw pdf data in the attachments.
    The basic code to get the email is below and you can see the handling of the attachments below that. The variable $finalbytes does contain the pdf raw code. Now if I could only display it.
    If anyone can give me some direction I'd appreciate it.

    Thanks,
    Tom

    $path = $row['EmailFileName'];
    $Parser = new MimeMailParser();
    $Parser->setPath($path);
    $to = $Parser->getHeader('to');
    $from = $Parser->getHeader('from');
    $subject = imap_utf8($Parser->getHeader('subject'));
    $text = $Parser->getMessageBody('text');
    $html = $Parser->getMessageBody('html');
    $attachments = $Parser->getAttachments();
    echo "To: " . $to . "<br/>";
    echo "From: " . $from . "<br/>";
    echo "Subject: " . $subject;

    attachment code:
    foreach($attachments as $attachment)
    {
    $filename = $attachment->filename;
    if ($fp = fopen($save_dir.$filename, 'w'))
    {
    while($bytes = $attachment->read()) {
    $finalbytes .= $bytes;
    }
    fclose($fp);
    }
    }
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,130
    Rep Power
    9398
    Since the $finalbytes is the raw binary content of the PDF "file", you can show it to the user like you would any other arbitrary file:
    PHP Code:
    header("Content-Type: application/pdf");
    echo 
    $finalbytes
    Remember that you can't do this unless the PDF is the only thing outputted. As in it wouldn't work with those echos you have in there now.

IMN logo majestic logo threadwatch logo seochat tools logo