-1

When echoing out file_get_contents on an uploaded pdf file, I get a load of nonsense displayed like so:

6}ÕìúÖ

Is there anyway of decoding this infomation?

Matt Jameson
  • 217
  • 1
  • 8
  • 21
  • What did you expect? A PDF has a binary file format, and its contents is *never* only plain text that you can read on a console. Even if it's not compressed, there are loads of infrastructure in and around the supposedly "plain" text. – Jongware Jan 31 '14 at 18:06

3 Answers3

2

this Code maybe help you

<?php
 $file = 'path/to/PDF/file.pdf';
 $filename = 'filename.pdf';
 header('Content-type: application/pdf');
 header('Content-Disposition: inline; filename="' . $filename . '"');
 header('Content-Transfer-Encoding: binary');
 header('Accept-Ranges: bytes');
 @readfile($file);

?>

be successfull

Ashouri
  • 906
  • 4
  • 19
1

If you want to read/alter the contents of the pdf file you have to use a library like FPDF

If you want to show the pdf you have to set the correct content type:

header('Content-type: application/pdf');
header('Content-Disposition: inline;');
echo file_get_contents('yourpdf.pdf');

(readfile is a better option though)

Jesper Blaase
  • 2,320
  • 16
  • 13
0

Try this: http://www.fpdf.org/

It's a library that has also been suggested in other questions identical to this.

Community
  • 1
  • 1
Albzi
  • 15,431
  • 6
  • 46
  • 63
  • "Let the browser know that a PDF file is coming." - what browser? He is trying to read the pdf file, not sending it to the client. – user4035 Jan 31 '14 at 14:21
  • Oh you're right I completely read this wrong! @user4035 I'll update answer to just the library. – Albzi Jan 31 '14 at 14:22