itext 如何让图片放在最上面
答案:2 悬赏:40 手机版
解决时间 2021-03-15 23:33
- 提问者网友:niaiwoma
- 2021-03-15 17:24
原先pdf里有一个图片,我想放一个图片在原先图片的上面,怎么做!
最佳答案
- 五星知识达人网友:白昼之月
- 2021-03-15 18:47
Image img = Image.getInstance("watermark.jpg");
PdfReader reader = new PdfReader(filename);
PdfStamper stamp = new PdfStamper(reader,
new FileOutputStream(newFilename));
PdfContentByte under;
int numPages = reader.getNumberOfPages();
int count = 0;
while (count < numPages)
{
count++;
under = stamp.getOverContent(count);
under.addImage(img);
}
stamp.close();
PdfReader reader = new PdfReader(filename);
PdfStamper stamp = new PdfStamper(reader,
new FileOutputStream(newFilename));
PdfContentByte under;
int numPages = reader.getNumberOfPages();
int count = 0;
while (count < numPages)
{
count++;
under = stamp.getOverContent(count);
under.addImage(img);
}
stamp.close();
全部回答
- 1楼网友:撞了怀
- 2021-03-15 20:06
插入文本时样式可以用font来定义:
document doc = new document();
doc.open();
paragraph text = new paragraph("your text", new font(font.getfamily("times_roman"), 18, font.bold));
text.setalignment(element.align_center);
doc.add(text);
以前插入过pdf文档,是用pdfreader读取然后用pdfwriter插入。插入图片应该是一样的原理:
pdfwriter.getimportedpage(new pdfreader(bufferdinputstream), pagenumber);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯