java - JEditorPane 和内容宽度
问题描述
我有一些代码,我在其中获取一些 html 格式的文本,将其放入 JEditorPane 并从中创建图像,如下所示:
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);
这非常有效,直到我的 html 文本中有一些具有固定宽度的元素(即 div 或表格等)
由于我的原始宽度固定为 850 像素,如果该元素的宽度大于该宽度,则会发生图像被剪切的情况,这意味着您无法阅读某些文本。
有没有办法让文字不会超过我的固定宽度?还是只是事先确保宽度在限制范围内?
谢谢你的帮助
解决方案
推荐阅读
- php - 如何授予限制从谷歌驱动器下载文件的权限?
- angular - Angular 启动服务工厂永远不会被调用
- python - AttributeError:“numpy.ndarray”对象没有属性“find_peaks_cwt”过程
- java - 如何将属性文件读取到硒中的预期数据
- r - 单个图中的多个列
- python - 如何在两个数字之间输入一个数字,以便在之后写入文本
- java - 为什么不能在变量声明行中放置调试断点?
- java - Java - 如何创建一副纸牌(专注于静态数组)?- AP计算机科学项目
- c++11 - 如何制作 std::function
编译,当 typename Arg = void? - c# - JSON 反现实化问题