Reputation: 207
I have some code where I take some text in html format, put it in a JEditorPane and create an image from it, as below:
String text = getMyText();
int height = getContentHeight(text);
int width = 850;
image = new BufferedImage(WIDTH, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
JEditorPane jep = new JEditorPane();
jep.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
jep.setContentType("text/html");
jep.setFont(new Font(myFont));
jep.setSize(width, height);
jep.setText(text);
jep.print(graphics);
graphics.dispose();
String fileName = "myFileName" + ".extension";
File outputfile = new File(myPath + "/" + fileName );
ImageIO.write(image, "png", outputfile);
This works wonderfully until the point I have some element in my html text with some fixed width (i.e. a div, or a table etc)
Since my original width is fixed at 850 pixels, if the width of that element is greater than that, what is happening is that the image looks like is being cut, meaning you cannot read certain text.
Is there a way so the text won't go over my fixed width? Or is it just a matter of making sure the width is within the limits beforehand?
Thanks for any help
Upvotes: 0
Views: 145