public static void main(String[] args) throws Exception { //String uri = System.getProperty("user.dir") + "/sample-docs/metafile-samples/gradient.emf"; String uri = System.getProperty("user.dir") + "/sample-docs/metafile-samples/freehand_picture_saveas.wmf"; System.out.println(uri); //String uri = "/tmp/img4448.img"; ImageInfo ii = getImageInfo(new URL(uri)); displayImageInfo(ii); }
try { try { info = getImageInfo(url); info = getImageInfo(new URL("file:/" + imageFile.getAbsolutePath())); } catch (java.io.FileNotFoundException fnfe) { info = getImageInfo(new URL("file://" + imageFile.getAbsolutePath()));
ImageSize size = imagePart.getImageInfo().getSize(); double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio);
ImageSize size = imagePart.getImageInfo().getSize(); double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio);
public static void main(String[] args) throws Exception { //String uri = System.getProperty("user.dir") + "/sample-docs/metafile-samples/gradient.emf"; String uri = System.getProperty("user.dir") + "/sample-docs/metafile-samples/freehand_picture_saveas.wmf"; System.out.println(uri); //String uri = "/tmp/img4448.img"; ImageInfo ii = getImageInfo(new URL(uri)); displayImageInfo(ii); }
try { try { info = getImageInfo(url); info = getImageInfo(new URL("file:/" + imageFile.getAbsolutePath())); } catch (java.io.FileNotFoundException fnfe) { info = getImageInfo(new URL("file://" + imageFile.getAbsolutePath()));
cx = imagePart.getImageInfo().getSize().getWidthPx() * (cy / imagePart.getImageInfo().getSize().getHeightPx()); cy = imagePart.getImageInfo().getSize().getHeightPx() * (cx / imagePart.getImageInfo().getSize().getWidthPx());
ImageSize size = imagePart.getImageInfo().getSize(); double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio);
@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); } }
ImageSize size = imagePart.getImageInfo().getSize(); double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio);
@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); } }