Changeset 558 for trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
- Timestamp:
- 10/22/08 17:18:02 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
r557 r558 242 242 } 243 243 244 /** Create an html version of the document, using CSS font family245 * stacks. This is appropriate if the HTML is intended for246 * viewing in a web browser, rather than an intermediate step247 * on the way to generating PDF output.248 *249 * @param result250 * The javax.xml.transform.Result object to transform into251 *252 * */253 public void html(javax.xml.transform.Result result) throws Exception {254 255 html(result, true);256 }257 258 public void html(javax.xml.transform.Result result, boolean fontFamilyStack) throws Exception {259 260 // Prep parameters261 HtmlSettings htmlSettings = new HtmlSettings();262 htmlSettings.setFontFamilyStack(fontFamilyStack);263 264 html(result, htmlSettings);265 }266 267 /** Create an html version of the document.268 *269 * @param result270 * The javax.xml.transform.Result object to transform into271 *272 * */273 public void html(javax.xml.transform.Result result, HtmlSettings htmlSettings) throws Exception {274 275 /*276 * Given that word2html.xsl is freely available, use a277 * version of it adapted to process the278 * pck:package/pck:part stuff emitted by Word 2007.279 *280 */281 XmlPackage worker = new XmlPackage(this);282 org.docx4j.xmlPackage.Package pkg = worker.get();283 284 JAXBContext jc = Context.jcXmlPackage;285 Marshaller marshaller=jc.createMarshaller();286 org.w3c.dom.Document doc = org.docx4j.XmlUtils.neww3cDomDocument();287 288 marshaller.marshal(pkg, doc);289 290 log.info("wordDocument created for PDF rendering!");291 292 293 // Get the xslt file - Works in Eclipse - note absence of leading '/'294 java.io.InputStream xslt = org.docx4j.utils.ResourceUtils.getResource("org/docx4j/openpackaging/packages/wordml2html-2007.xslt");295 296 // Prep parameters297 if (htmlSettings==null) {298 htmlSettings = new HtmlSettings();299 // ..Ensure that the font names in the XHTML have been mapped to these matches300 // possibly via an extension function in the XSLT301 }302 303 if (htmlSettings.getFontSubstituter()==null) {304 if (fontSubstituter==null) {305 log.debug("Creating new Substituter.");306 setFontSubstituter(new Substituter());307 } else {308 log.debug("Using existing Substituter.");309 }310 htmlSettings.setFontSubstituter(fontSubstituter);311 }312 313 // Now do the transformation314 org.docx4j.XmlUtils.transform(doc, xslt, htmlSettings.getSettings(), result);315 316 log.info("wordDocument transformed to xhtml ..");317 318 }319 320 244 321 245 … … 346 270 } 347 271 348 private Substituter fontSubstituter; 272 public Substituter getFontSubstituter() { 273 return fontSubstituter; 274 } 275 276 private Substituter fontSubstituter; 349 277 350 278 /** Create a pdf version of the document. … … 376 304 org.w3c.dom.Document xhtmlDoc = org.docx4j.XmlUtils.neww3cDomDocument(); 377 305 javax.xml.transform.dom.DOMResult result = new javax.xml.transform.dom.DOMResult(xhtmlDoc); 378 html(result, false); // false -> don't use HTML fonts.306 org.docx4j.convert.out.html.HtmlExporter.html(this, result, false); // false -> don't use HTML fonts. 379 307 380 308 // Now render the XHTML … … 386 314 org.xhtmlrenderer.extend.FontResolver resolver = renderer.getFontResolver(); 387 315 388 Map fontMappings = fontSubstituter.getFontMappings();316 Map fontMappings = getFontSubstituter().getFontMappings(); 389 317 Map fontsInUse = this.getMainDocumentPart().fontsInUse(); 390 318 Iterator fontMappingsIterator = fontsInUse.entrySet().iterator(); … … 571 499 } 572 500 573 public static class HtmlSettings {574 575 Boolean fontFamilyStack = Boolean.FALSE;576 public void setFontFamilyStack(boolean val) {577 fontFamilyStack = new Boolean(val);578 }579 580 String docxWiki = null; // edit | open581 public void setDocxWiki(String docxWiki) {582 this.docxWiki = docxWiki;583 }584 585 String docxWikiSdtID = null;586 public void setDocxWikiSdtID(String docxWikiSdtID) {587 this.docxWikiSdtID = docxWikiSdtID;588 }589 590 String docID = null;591 public void setDocID(String docID) {592 this.docID = docID;593 }594 595 596 Substituter fontSubstituter = null;597 public void setFontSubstituter(Substituter fontSubstituter) {598 this.fontSubstituter = fontSubstituter;599 }600 public Substituter getFontSubstituter() {601 return fontSubstituter;602 }603 604 605 Map<String, Object> getSettings() {606 Map<String, Object> settings = new java.util.HashMap<String, Object>();607 608 settings.put("fontFamilyStack", fontFamilyStack);609 settings.put("docxWiki", docxWiki);610 settings.put("docxWikiSdtID", docxWikiSdtID);611 settings.put("docID", docID);612 settings.put("substituterInstance", fontSubstituter);613 614 return settings;615 }616 617 }618 501 619 502 }
Note: See TracChangeset
for help on using the changeset viewer.
