当我尝试多次使用 setClip (...)时收到错误消息“ java.lang.RuntimeException:Unbalanced save / restore state Operators ”在使用Graphics2对象进行绘制时,我从iText的cb.createGraphics(..)获取。
其他信息:
有人知道这个问题的解决方案,还是有提示? 此错误是否也出现在第5版......中? (在我购买第5版许可证之前; - )
谢谢!
FileOutputStream fos = new FileOutputStream("c:\\temp\\test.pdf");
Document document = null;
Rectangle rect=PageSize.A3.rotate();
document = new Document(rect);
PdfWriter writer=PdfWriter.getInstance(document, fos);
document.open();
PdfContentByte cb = writer.getDirectContent();
Graphics2D g =cb.createGraphics(rect.getWidth(), rect.getHeight());
int x[]={10,1000,1000,10};
int y[]={10,10,1000,1000};
Polygon po=new Polygon();
for (int i=0; i<4; i++)
po.addPoint(x[i],y[i]);
g.clip(po);
g.setClip(null);
document.newPage();
g.clip(po);
g.setClip(null);