1

The image showing in docx file is not visible in pdf when converted using unoconv where the image is displayed using

$document = new \PhpOffice\PhpWord1\TemplateProcessor($docx_temp_file_path);
$imagePath = '/abc.png';
if (file_exists($imagePath)) {
    $document->setImageValue($key, $imagePath);
}

Here is the unoconv code

public function docxToPdf( $docx_file_path, $pdf_file_path )
{
    $pythonPath = '/usr/bin/python';
    $unoconvPath = '/usr/bin/unoconv';
    $command = sprintf(
        '"%s" "%s" -f pdf "%s" 2>&1', 
        $pythonPath,
        $unoconvPath,
        $docx_file_path
    );

    exec($command, $output, $return);
    //
    if (is_array($output) && !empty($output[0])) {
        throw new Exception(json_encode(implode('; ', $output), true));
    }
    return true;
}

Here am attaching sample link of docx filedocx file

9
  • If you open the generated Word file with LibreOffice, do you see the image? Commented Jan 14 at 7:48
  • @Olivier No but when i open through Microsoft word i can see the image Commented Jan 14 at 12:08
  • Have you tried running unoconv in terminal? unoconv -f pdf "GeneratedDocument.docx" 2>&1 Commented Jan 14 at 12:31
  • @shirshak007 yes it looks same Commented Jan 15 at 4:37
  • Can you share the Word file (it can be a simple test file, not the real one)? Commented Jan 15 at 8:18

1 Answer 1

7
+50

Your generated Word document contains 3 images in the page footer. The footer1.xml file contains this:

<w:pict><v:shape type="#_x0000_t75" style="width:;height:70px" stroked="f"><v:imagedata r:id="rId1" o:title=""/></v:shape></w:pict>
<w:pict><v:shape type="#_x0000_t75" style="width:;height:70px" stroked="f"><v:imagedata r:id="rId3" o:title=""/></v:shape></w:pict>
<w:pict><v:shape type="#_x0000_t75" style="width:;height:70px" stroked="f"><v:imagedata r:id="rId2" o:title=""/></v:shape></w:pict>

All images have this style:

width:;height:70px

As you can see, the width is missing. In that case, Word uses a default value, but LibreOffice doesn't show the image. Since unoconv uses LibreOffice to convert to PDF, the images are missing in the resulting document.

I could reproduce the issue by specifying this in the template:

${key::70:false}

You can fix it either by specifying the width:

${key:70:70:false}

or by removing the ratio parameter:

${key::70}
Sign up to request clarification or add additional context in comments.

1 Comment

You saved my day thanks a lot and I can't express my happiness you did a great job

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.