在Android中使用iText将图像添加到特定位置 [英] Add image to a specific location using iText in Android
本文介绍了在Android中使用iText将图像添加到特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android中使用iText将图像添加到PDF文件中的特定位置.这是一个可填写的表单,我添加了文本框,该框是图像的占位符,我想要做的就是像这样将文本框和图像添加到其中.
I want to add image to a specific location in a PDF file using iText in Android. This is a fillable form and I have added textbox that is a place holder for the image and what I want to do is to get that textbox and image to it like this.
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
I have the image uri like so
Uri imageUri = Uri.parse(person.getImagePath());
任何帮助将不胜感激.
推荐答案
尝试一下. 我已使用此功能在文档中添加图像.
try this. i have used this function for add image in document.
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();
}
}
这篇关于在Android中使用iText将图像添加到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文