Instead of calling PictureParameter1.setContents(), try using the storeFileDocumentContent() method in the Core API.
Hope this helps
Hi Matthias,
Were you ever able to complete the Java-action? This is exactly what I need for a client of mine.
Hi Yordee,
the answer is yes and no. So I was able to handover a string and generate the picture. (actually a empty picture which is handed into the java action is filled with data). However, we never used the solution because we also wanted to hand over some picture as base64. But none of the java html renderer libaries I found was able to do the base64 rendering.
But here is the coded we used (i think we played around wiht different html java liberaies but I have forgoten wich the others were….)
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package siedoc_2.actions;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
import gui.ava.html.image.generator.HtmlImageGenerator;
import java.awt.*;
import java.awt.image.RenderedImage;
import java.io.*;
import javax.imageio.ImageIO;
import com.mendix.core.*;
import java.awt.image.BufferedImage;
import javax.imageio.stream.*;
public class Test_Java_call3 extends CustomJavaAction<java.lang.Boolean>
{
private java.lang.String Html_String;
private IMendixObject __PictureParameter1;
private siedoc_2.proxies.TestImage PictureParameter1;
public Test_Java_call3(IContext context, java.lang.String Html_String, IMendixObject PictureParameter1)
{
super(context);
this.Html_String = Html_String;
this.__PictureParameter1 = PictureParameter1;
}
@java.lang.Override
public java.lang.Boolean executeAction() throws Exception
{
this.PictureParameter1 = this.__PictureParameter1 == null ? null : siedoc_2.proxies.TestImage.initialize(getContext(), __PictureParameter1);
// BEGIN USER CODE
HtmlImageGenerator hig = new HtmlImageGenerator();
hig.loadHtml(Html_String);
BufferedImage image = hig.getBufferedImage();
BufferedImage bufferedImageToWrite = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
bufferedImageToWrite.createGraphics().drawImage(image, 0, 0, Color.WHITE, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImageToWrite, "png", baos);
byte[] bytes = baos.toByteArray();
//ImageInputStream targetStream = ImageIO.createImageInputStream(bufferedImageToWrite);
//long l = targetStream.length();
//int laenge = (int)l;
//byte[] temp = new byte[laenge];
//targetStream.read(temp);
InputStream targetStream1 = new ByteArrayInputStream(bytes);
//hig.saveAsImage("hello-world.png");
//File imageFile = new File("hello-world.png");
//InputStream targetStream = new FileInputStream(imageFile);
Core.storeFileDocumentContent( getContext(), PictureParameter1.getMendixObject(), targetStream1 );
//PictureParameter1.setContents( getContext(), targetStream, imageFile.length());
return true;
// END USER CODE
}
/**
* Returns a string representation of this action
* @return a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "Test_Java_call3";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}