0

I need to convert Pdf file to byte array conversion in php. I am looking for like this result.

This result have byte conversation of Pdf file.

What id did:

$file = file_get_contents("pdf.pdf");
$fileData = base64_encode($file);
echo $fileData;

It does not works for me. how to convert PDf file to byte array?

Rajkumar .E
  • 1,440
  • 3
  • 20
  • 34

1 Answers1

0

This will get you the whole file into a string:

$fileContents = file_get_contents($file);

If you want an array of one-character strings, you can do this:

$byteArray = str_split($fileContents);

If you want an array of integer ASCII values, you can do this:

$byteArray = unpack('C*', $fileContents);
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98