/** 加入图片 */ protected void processImage(Element parent, CharacterRun cr) { if (this.picstab.hasPicture(cr)) { Picture pic = picstab.extractPicture(cr, false); String fileName = pic.suggestFullFileName(); OutputStream out = null; try { // TWIPS_PER_INCH/ out = new FileOutputStream(new File(output.concat(File.separator).concat(fileName))); pic.writeImageContent(out); Element img = htmlDocumentFacade.getDocument().createElement("img"); String uri = fileName.concat("image").concat(File.separator).concat(fileName); img.setAttribute("src", uri); if (pic.getWidth() > 600) img.setAttribute("style", "width: 600px;"); Element imgBlock = htmlDocumentFacade.createBlock(); this.htmlDocumentFacade.addStyleClass(imgBlock, "imgs", "text-align:center;"); imgBlock.appendChild(img); parent.appendChild(imgBlock); } catch (Exception e) { e.printStackTrace(); } finally { if (out != null) try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } } // 图片END
protected void processSection(HWPFDocument wordDocument, Section section, int sectionCounter) { // TODO 解析章节 Element div = htmlDocumentFacade.createBlock(); htmlDocumentFacade.addStyleClass(div, "d", getSectionStyle(section)); // htmlDocumentFacade.body.appendChild( div ); pageContainer.appendChild(div); processParagraphes(wordDocument, div, section, Integer.MIN_VALUE); }
protected void processNoteAutonumbered( HWPFDocument doc, String type, int noteIndex, Element block, Range noteTextRange) { final String textIndex = String.valueOf(noteIndex + 1); final String textIndexClass = htmlDocumentFacade.getOrCreateCssClass("a", "vertical-align:super;font-size:smaller;"); final String forwardNoteLink = type + "note_" + textIndex; final String backwardNoteLink = type + "note_back_" + textIndex; Element anchor = htmlDocumentFacade.createHyperlink("#" + forwardNoteLink); anchor.setAttribute("name", backwardNoteLink); anchor.setAttribute("class", textIndexClass + " " + type + "noteanchor"); anchor.setTextContent(textIndex); block.appendChild(anchor); if (notes == null) { notes = htmlDocumentFacade.createBlock(); notes.setAttribute("class", "notes"); } Element note = htmlDocumentFacade.createBlock(); note.setAttribute("class", type + "note"); notes.appendChild(note); Element bookmark = htmlDocumentFacade.createBookmark(forwardNoteLink); bookmark.setAttribute("href", "#" + backwardNoteLink); bookmark.setTextContent(textIndex); bookmark.setAttribute("class", textIndexClass + " " + type + "noteindex"); note.appendChild(bookmark); note.appendChild(htmlDocumentFacade.createText(" ")); Element span = htmlDocumentFacade.getDocument().createElement("span"); span.setAttribute("class", type + "notetext"); note.appendChild(span); this.blocksProperies.add(new BlockProperies("", -1)); try { processCharacters(doc, Integer.MIN_VALUE, noteTextRange, span); } finally { this.blocksProperies.pop(); } }
@SuppressWarnings("deprecation") protected void processImage( Element currentBlock, boolean inlined, Picture picture, String imageSourcePath) { final int aspectRatioX = picture.getHorizontalScalingFactor(); final int aspectRatioY = picture.getVerticalScalingFactor(); StringBuilder style = new StringBuilder(); final float imageWidth; final float imageHeight; final float cropTop; final float cropBottom; final float cropLeft; final float cropRight; if (aspectRatioX > 0) { imageWidth = picture.getDxaGoal() * aspectRatioX / 1000 / TWIPS_PER_INCH; cropRight = picture.getDxaCropRight() * aspectRatioX / 1000 / TWIPS_PER_INCH; cropLeft = picture.getDxaCropLeft() * aspectRatioX / 1000 / TWIPS_PER_INCH; } else { imageWidth = picture.getDxaGoal() / TWIPS_PER_INCH; cropRight = picture.getDxaCropRight() / TWIPS_PER_INCH; cropLeft = picture.getDxaCropLeft() / TWIPS_PER_INCH; } if (aspectRatioY > 0) { imageHeight = picture.getDyaGoal() * aspectRatioY / 1000 / TWIPS_PER_INCH; cropTop = picture.getDyaCropTop() * aspectRatioY / 1000 / TWIPS_PER_INCH; cropBottom = picture.getDyaCropBottom() * aspectRatioY / 1000 / TWIPS_PER_INCH; } else { imageHeight = picture.getDyaGoal() / TWIPS_PER_INCH; cropTop = picture.getDyaCropTop() / TWIPS_PER_INCH; cropBottom = picture.getDyaCropBottom() / TWIPS_PER_INCH; } Element root; if (cropTop != 0 || cropRight != 0 || cropBottom != 0 || cropLeft != 0) { float visibleWidth = Math.max(0, imageWidth - cropLeft - cropRight); float visibleHeight = Math.max(0, imageHeight - cropTop - cropBottom); root = htmlDocumentFacade.createBlock(); htmlDocumentFacade.addStyleClass( root, "d", "vertical-align:text-bottom;width:" + visibleWidth + "in;height:" + visibleHeight + "in;"); // complex Element inner = htmlDocumentFacade.createBlock(); htmlDocumentFacade.addStyleClass( inner, "d", "position:relative;width:" + visibleWidth + "in;height:" + visibleHeight + "in;overflow:hidden;"); root.appendChild(inner); Element image = htmlDocumentFacade.createImage(imageSourcePath); htmlDocumentFacade.addStyleClass( image, "i", "position:absolute;left:-" + cropLeft + ";top:-" + cropTop + ";width:" + imageWidth + "in;height:" + imageHeight + "in;"); inner.appendChild(image); style.append("overflow:hidden;"); } else { root = htmlDocumentFacade.createImage(imageSourcePath); root.setAttribute( "style", "width:" + imageWidth + "in;height:" + imageHeight + "in;vertical-align:text-bottom;"); } currentBlock.appendChild(root); }