protected void removeUnnecessaryTexts() { for (Text text : textsToRemove) { Object parent = XmlUtils.unwrap(text.getParent()); if (parent instanceof R) { ((R) parent).getContent().remove(text); } } }
protected void removeUnnecessaryTexts() { for (Text text : textsToRemove) { Object parent = XmlUtils.unwrap(text.getParent()); if (parent instanceof R) { ((R) parent).getContent().remove(text); } } }
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher matcher) { try { R run = (R) text.getParent(); wordPackage.getContentTypeManager().addDefaultContentType("xhtml", "text/xhtml"); MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart(); mainDocumentPart.addAltChunk(AltChunkType.Xhtml, paramValue.toString().getBytes(), run); text.setValue(""); } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting html to docx file", e); } }
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher matcher) { try { R run = (R) text.getParent(); wordPackage.getContentTypeManager().addDefaultContentType("xhtml", "text/xhtml"); MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart(); mainDocumentPart.addAltChunk(AltChunkType.Xhtml, paramValue.toString().getBytes(), run); text.setValue(""); } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting html to docx file", e); } }
@Override public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { Part part = resolveTextPartForDOCX(text, wordPackage); BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, part, image.imageContent); int originalWidth = imagePart.getImageInfo().getSize().getWidthPx(); int originalHeight = imagePart.getImageInfo().getSize().getHeightPx(); double widthScale = (double) image.width / (double) originalWidth; double heightScale = (double) image.height / (double) originalHeight; double actualScale = Math.min(widthScale, heightScale); long targetWidth = Math.round(originalWidth * actualScale); long targetHeight = Math.round(originalHeight * actualScale); Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, XlsxUtils.convertPxToEmu(targetWidth), XlsxUtils.convertPxToEmu(targetHeight), false); org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing(); R run = (R) text.getParent(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); text.setValue(""); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e); } }
@Override public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, resolveTextPartForDOCX(text, wordPackage), image.imageContent); Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, false); ImageSize oldSize = imagePart.getImageInfo().getSize(); double widthExtent = (double) image.width / oldSize.getWidthPx(); double heightExtent = (double) image.height / oldSize.getHeightPx(); inline.getExtent().setCx((long) (inline.getExtent().getCx() * widthExtent)); inline.getExtent().setCy((long) (inline.getExtent().getCy() * heightExtent)); org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing(); R run = (R) text.getParent(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); text.setValue(""); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e); } }