1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php
$manifest = new DOMDocument('1.0', 'utf-8');
$XMLManifest = $manifest->createElement('manifest:manifest');
$XMLManifest->setAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$manifest->appendChild($XMLManifest);
$XMLFileEntry = $manifest->createElement('manifest:file-entry');
$XMLFileEntry->setAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$XMLFileEntry->setAttribute('manifest:full-path', '/');
$XMLManifest->appendChild($XMLFileEntry);
$XMLFileEntry = $manifest->createElement('manifest:file-entry');
$XMLFileEntry->setAttribute('manifest:media-type', 'text/xml');
$XMLFileEntry->setAttribute('manifest:full-path', 'content.xml');
$XMLManifest->appendChild($XMLFileEntry);
$content = new DOMDocument('1.0', 'utf-8');
$XMLDocumentContent = $content->createElement('office:document-content');
$XMLDocumentContent->setAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$XMLDocumentContent->setAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$XMLDocumentContent->setAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$XMLDocumentContent->setAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$content->appendChild($XMLDocumentContent);
$XMLAutomaticStyles = $content->createElement('office:automatic-styles');
$XMLDocumentContent->appendChild($XMLAutomaticStyles);
$XMLStyle = $content->createElement('style:style');
$XMLStyle->setAttribute('style:name', 'b');
$XMLStyle->setAttribute('style:family', 'text');
$XMLAutomaticStyles->appendChild($XMLStyle);
$XMLTextProperties = $content->createElement('style:text-properties');
$XMLTextProperties->setAttribute('fo:font-weight', 'bold');
$XMLTextProperties->setAttribute('style:font-weight-asian', 'bold');
$XMLTextProperties->setAttribute('style:font-weight-complex', 'bold');
$XMLStyle->appendChild($XMLTextProperties);
$XMLBody = $content->createElement('office:body');
$XMLDocumentContent->appendChild($XMLBody);
$XMLText = $content->createElement('office:text');
$XMLBody->appendChild($XMLText);
$XMLParagraph = $content->createElement('text:p');
$XMLText->appendChild($XMLParagraph);
$XMLText = $content->createTextNode(utf8_encode("Du texte "));
$XMLParagraph->appendChild($XMLText);
$XMLText = $content->createElement('text:span', utf8_encode("en gras"));
$XMLText->setAttribute('text:style-name', 'b');
$XMLParagraph->appendChild($XMLText);
$XMLText = $content->createTextNode(utf8_encode("."));
$XMLParagraph->appendChild($XMLText);
$document = new ZipArchive();
$document->open('hello-world.odt', ZIPARCHIVE::OVERWRITE);
$document->addFromString('META-INF/manifest.xml', $manifest->saveXML());
$document->addFromString('content.xml', $content->saveXML());
$document->close();
?> |
Partager