I don't have any plan how can I convert an Word document, which I have as a string (blob) from my database, to a PDF via the PHPOffice library.
Concept:
- I fetch an existing word document as an string from the database
- Pass the string through an constructor or an function of PHPOffice library.
- Then get via another function the PDF as an string
- And last output the string with
Content-Type: application/pdf
to the user.
Nr. 1 and 4 I already implemented. But I don't know how to accomplish nr. 2 and 3. Can someone help me?
Code:
//DB-Connection, Composer autoload, ...
$id = htmlspecialchars(trim($_REQUEST["id"]));
$get_data = $con->query("SELECT * FROM word_documents WHERE id='$id'"); //Get the blob
$data = $get_data->fetch();
if ($get_data->rowCount() == 1) {
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=" . $data["name"]);
//TODO: Print the PDF as an string
} else {
echo "File not found";
}