我正在创建一份PDF文档,并希望在其中添加一个JPanel。使用PdfContentByte和PdfGraphics2D,我能够将其添加到文档中,但是:
1. 如何将其定位到左边距而不是左边缘? 2. 如何防止它显示在其他元素上方? 3. 换句话说:如何将其放入段落中?
代码片段:
1. 如何将其定位到左边距而不是左边缘? 2. 如何防止它显示在其他元素上方? 3. 换句话说:如何将其放入段落中?
代码片段:
// multiple Paragraphs
// ...
JPanel myPanel = ...
PdfContentByte canvas = writer.getDirectContent();
int origWidth = myPanel.getWidth();
int origHeight = myPanel.getHeight();
float width = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin();
double scale = width / origWidth;
Graphics2D g2 = new PdfGraphics2D(canvas, origWidth, origHeight);
g2.scale(scale, scale);
myPanel.paint(g2);
g2.dispose();
// even more Paragraphs
//...