在Android中使用iText将图像添加到特定位置
我想在Android中使用iText将图像添加到PDF文件中的特定位置。这是一个可填充的表单,我添加了文本框,它是图像的占位符,我想做的是像这样将文本框和图像添加到它在Android中使用iText将图像添加到特定位置,android,itext,Android,Itext,我想在Android中使用iText将图像添加到PDF文件中的特定位置。这是一个可填充的表单,我添加了文本框,它是图像的占位符,我想做的是像这样将文本框和图像添加到它 public class FormFill { public static void fill(AcroFields form, Person person) throws IOException, DocumentException{ form.setField("firstname", person.g
public class FormFill {
public static void fill(AcroFields form, Person person) throws IOException, DocumentException{
form.setField("firstname", person.getFirstName());
form.setField("lastname", person.getLastName());
form.setField("imagetextbox", "???");
}
我有这样的图像uri
Uri imageUri = Uri.parse(person.getImagePath());
任何帮助都将不胜感激。试试这个。
我已使用此功能在文档中添加图像
public void addLogo(Document document) throws DocumentException {
try { // Get user Settings GeneralSettings getUserSettings =
Rectangle rectDoc = document.getPageSize();
float width = rectDoc.getWidth();
float height = rectDoc.getHeight();
float imageStartX = width - document.rightMargin() - 315f;
float imageStartY = height - document.topMargin() - 80f;
System.gc();
InputStream ims = getAssets().open("splashscreen.jpg");
Bitmap bmp = BitmapFactory.decodeStream(ims);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 50, stream);
byte[] byteArray = stream.toByteArray();
// PdfImage img = new PdfImage(arg0, arg1, arg2)
// Converting byte array into image Image img =
Image img = Image.getInstance(byteArray); // img.scalePercent(50);
img.setAlignment(Image.TEXTWRAP);
img.scaleAbsolute(200f, 50f);
img.setAbsolutePosition(imageStartX, imageStartY); // Adding Image
document.add(img);
} catch (Exception e) {
e.printStackTrace();
}
}
我结束了这样添加图像
Image image = Image.getInstance(stream.toByteArray());
PdfContentByte overContent = stamper.getOverContent(1);
overContent.addImage(image);
这里有一个很好的例子:Bruno非常感谢,但是由于某些原因,我无法让这个例子发挥作用,我最终使用了PdfContentByteWow,这个解决方案看起来很棒,我希望我能让它发挥作用,我没有文档的实例,我有一个母版的实例。我会试着看看我是否能使它工作。