How to bring image to the front(of the text/image) or send the image to the back((of the text/image)) in IText7 using java?

无人久伴 提交于 2019-12-02 00:19:04

The error is the same as in your earlier question: You use a throw-away resources object, so the image resource is missing in the result.

You can fix this by using the actual page resources. Simply replace

PdfCanvas under = new PdfCanvas(pdfDoc.getFirstPage().newContentStreamBefore(), new PdfResources(), pdfDoc);

by

PdfCanvas under = new PdfCanvas(pdfDoc.getFirstPage().newContentStreamBefore(), pdfDoc.getFirstPage().getResources(), pdfDoc);

Furthermore, drop the

under.saveState();

line as saveState only makes sense if you later use a matching restoreState.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!