I am currently generating multiple .docx files using PHPWord. I need to find a way to combine these docx files and save them as 1 pdf file. Is there a way that this can be done?
# Answer 1
Open the generated docx with PHPDOCX http://www.phpdocx.com/
require_once 'phpdocx_pro/classes/TransformDoc.inc';
$docx = new TransformDoc();
$docx->setStrFile('document.docx');
$docx->generateXHTML();
$html = $docx->getStrXHTML();
Also, you can export the docx to PDF with
$docx->generatePDF();
Note this is not a free library
# Answer 2
You can look at http://www.phplivedocx.org/, they support docx and through the zend framework also the generation of pdfs.
# Answer 3
require_once dirname(__FILE__) .'/phpdocx/classes/TransformDoc.inc.php';
require_once dirname(__FILE__) .'/phpdocx/classes/CreateDocx.inc.php';
$docx = new TransformDoc();
$docx->setStrFile('document.docx');
$docx->generatePDF();
==> Its seems work but... where is the generated PDF ? How I can get PDF file ?
# Answer 4
/**
* return the pdf stream as a string returned from the function
*/
function output($debug = false) {
...
}
so just write the result of 'generatePDF()' to a file.
for example:
$content = $docx->generatePDF();
$myfile = fopen("newfile.pdf", "w");
fwrite($myfile, $content);
fclose($myfile);