PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.25k stars 2.69k forks source link

HTML writer error #285

Open gaf09 opened 10 years ago

gaf09 commented 10 years ago

Hi,

Several hours ago I'm trying to find out why not working the HTML Writer, more specifically with the element Image of HTML Writer.

The error happens when i save a Word file that generates the HTML file, works with all elements excellently, but not work with the images. That is, it generates all the code less the "img" tag.

I hope they know what's going, Thanks and sorry for the bad English :)

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/2755703-html-writer-error?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github).
Progi1984 commented 10 years ago

Hi @gaf09, Could you give us a sample code ?

gaf09 commented 10 years ago

Yes, I put the code here:

$PHPWord = new \PhpOffice\PhpWord\PhpWord();

// Load template
$template = $PHPWord->loadTemplate($WordFile);

// File name & directory
$tempFile = '../temp/' . time();

// Save template has new Word file
$template->saveAs($tempFile . ".docx");

// Load generated Word
$PHPWordLoad = \PhpOffice\PhpWord\IOFactory::load($tempFile . ".docx");

// Save generated word in HTML
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWordLoad, 'HTML');
$objWriter->save($tempFile . ".html");

I have also tried exporting to PDF but the same error with images. (because to save to PDF the system using HTML anyway).

PD: The template includes images

Progi1984 commented 10 years ago

Could you give us your $WordFile for testing ?

gaf09 commented 10 years ago

Yes of course, here's my docx: https://www.dropbox.com/s/pyvkzi7prln6m2j/WordExample.docx

Here I also added the HTML generated by the sample code

<!DOCTYPE html>
<!-- Generated by PHPWord -->
<html>
<head>
<meta charset="UTF-8" />
<title>PHPWord</title>
<style>
* {font-family: Arial; font-size: 10pt;}
a.NoteRef {text-decoration: none;}
hr {height: 1px; padding: 0; margin: 1em 0; border: 0; border-top: 1px solid #CCC;}
.Normal {font-size: 12pt;}
.Hyperlink {text-decoration: underline ;}
.Cabecera y pie {font-family: 'Helvetica'; font-size: 12pt; color: #000000; font-weight: bold; font-style: italic; text-decoration: line-through ;}
.Cuerpo A {font-family: 'Helvetica'; font-size: 11pt; color: #000000; font-weight: bold; font-style: italic; text-decoration: line-through ;}
</style>
</head>
<body>
<p style="text-align: center;"><span style="font-size: 14pt; font-weight: bold;">C</span><span style="font-size: 14pt; font-weight: bold;">ó</span><span style="font-size: 14pt; font-weight: bold;">digo:</span><span style="font-size: 14pt;"> ${code}</span></p>
<p>&nbsp;</p>
<p style="text-align: center;"><span style="font-size: 14pt;">ASD :)</span></p>
<p>&nbsp;</p>
<p><span style="font-size: 14pt;">Otros datos:</span></p>
<p><span style="font-size: 14pt;">${message}</span></p>
<p><span style="font-family: 'Helvetica';">                   </span></p>
<p style="text-align: right;"></p>
</body>
</html>
gaf09 commented 10 years ago

Hi @Progi1984 could have any idea why this error is happening ? Thanks!!

Progi1984 commented 10 years ago

No for the moment, but we have all informations.

shawlz commented 9 years ago

Hello, has anyone been able to resolve this? If yes, could you kindly provide details on how to go about it. Thank you.

shawlz commented 9 years ago

Hello, I found out that DrawingML Objects (w:drawing) are not being parsed by the Word2007 Reader and also not supported by the HTML writer. Had to modify PHPWord to extract these and convert any WMF files into PNGs using Imagick since Browsers don't support WMFs.

laue commented 8 years ago

The reader only interprets w:pict images, not w:drawing images in the MSWord XML. As a consequence, you need to drag and drop images into your word file for the conversion to work. Images that are copy pasted, or inserted using the menu will be ignored by phpword.

Hope this can serve as a workaround.

Progi1984 commented 7 years ago

Some helps for which one who want to create a PR :

http://officeopenxml.com/drwPicInWord.php http://officeopenxml.com/drwPicInline.php http://officeopenxml.com/drwPicFloating.php