Hello I want to convert my doc file to pdf. In this code I changed newfile.docx to newfile.pdf but it won't work. How do I save the file as pdf?
$x = "Hello World!";
include_once('includes/tbszip.php');
$zip = new clsTbsZip();
// Open the document
$zip->Open('mydoc.docx');
$content = $zip->FileRead('word/document.xml');
$p = strpos($content, '</w:body>');
if ($p===false) exit("Tag </w:body> not found in document.");
// Add the text at the end
$content = substr_replace($content, '<w:p><w:r><w:t>'.$x.'</w:t></w:r></w:p>', $p, 0);
$zip->FileReplace('word/document.xml', $content, TBSZIP_STRING);
// Save as a new file
$zip->Flush(TBSZIP_FILE, 'newfile.pdf');
TbsZip can read (and write) a zip archive, such as a DOCX. But it cannot make file conversion.
A file conversion is not simply changing extension. It consists in converting all structured data. A DOCX is made of several XML sub-files, while a PDF is binary.
I don't know any PHP library that can convert DOCX to PDF.