Forum


Replies: 1   Views: 1162
Transformdocument
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by bas225522  · 26-01-2021 - 09:58

Hi,

I have a little problem. i have a script to transform .docx to .pdf easy to do with phpdocx... but!

i can't rename the file while transforming the .docx to .pdf

This is the script that i use:

<?php

// Phpdocx inladen.
require_once '../../plugins/phpdocx/classes/CreateDocx.php';

$bestand          = $obj2->bestand; // Get's from db like document.docx
$bestandslocatie  = "documenten/".$obj2->pat_id."/documenten/"; // this is the location where the file is stored
$bestandsnaam     = "output.pdf";

$docx = new CreateDocx();

$docx->transformDocument($bestandslocatie.$bestand, $bestandsnaam, 'libreoffice', array('homeFolder' => '/var/www/html/', 'debug' => true));

?>

than the debug output ( I deleted the save location for security reasons ) 
convert /document.docx -> /document.pdf using filter : writer_pdf_Export

I expect output.pdf but i get document.pdf.
Can anyone tell me what i'm doing wrong?

Posted by admin  · 26-01-2021 - 10:43

Hello,

LibreOffice generates a PDF output with the same name than the source document and PDF as extension. phpdocx renames it to the new name ($target value) using rename PHP function (if you open TransformDocAdvLibreOffice.php you can find the following line:

rename($newDocumentPath, $target);

As the target may depend on the target folder too, maybe you need to set the destination folder in the path too (if the script that does the transformation isn't in the same folder as the DOCX or it doesn't have rw access to move the file to the new destination):

$docx->transformDocument('/path/document.docx', '/path/document.pdf');

We recommend you to print both variables in TransformDocAdvLibreOffice.php (rename($newDocumentPath, $target); line). Or you can generate the PDF and then rename/move it to the new destination using rename in your code.

Regards.