我想使用 Android 中的 iText 将图像添加到 PDF 文件中的特定位置。这是一个可填写的表单,我添加了作为图像占位符的文本框,我想要做的就是像这样获取该文本框和图像。
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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)