m2doc

Modify image format (from default jpg to another)


I'm trying to change the format of an image I want to export in Word.
According to the PictureType.java class, it seems possible but after a few tests it doesn't seem to be working properly.
I used this line:
{m: '[PAB] A. SIEG.4_UP-CTB (LTTBI).jpg'.asImage('emf')} but the file is still in the jpg format.
Is it possible to have further information as to how the conversion method "totype" works?
I don't have any messages of error and the image is well exported but in jpg format, so I can only assume there is a possible Exception raised but caught and therefore no trace as there is no message in the "catch" exception :

    try {
          res = valueOf(extension.toUpperCase());
    } catch (IllegalArgumentException ignored) {
      // Simply ignore this exception. It means that the
      // given extension is unknown.
      // JPG type will be returned by default.
    }

or more likely this one which appears further in the method :

    try {
       res = valueOf(type.substring(MIME_IMAGE_TYPE.length()).toUpperCase());
    } catch (IllegalArgumentException ignored) {
       // Simply ignore this exception. It means that the
       // given extension is unknown.
       // JPG type will be returned by default.
    }

Thanks in advance for your answers.


Solution

  • The type passed to the asImage() service is used to tell M2Doc the format of the image if it can't be computed from the file extension. It's not used to convert the image format. To do that, you can create a Java service and use javax.imageio.ImageIO for instance.