Help with iText code
honestly, know little itext , how use it. i'm novice @ cf. have been searching way change image of button in existing pdf file. found code sample, it's on head.
if can me work in cf, appreciate it:
pdfreader pdf = new pdfreader("in.pdf");
pdfstamper stp = new pdfstamper(pdf, new fileoutputstream("out.pdf"));
pdfwriter writer = stp.getwriter();
image img = image.getinstance("image.png");
acrofields af = stp.getacrofields();
acrofields.item item = af.getfielditem("button1");
pdfdictionary dic = (pdfdictionary)item.widgets.get(0);
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.ap));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.n));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.resources));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.xobject));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.frm));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.resources));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.xobject));
pdfobject obj = dic.get((pdfname)dic.getkeys().iterator().next());
if (obj.isindirect()) {
pdfdictionary tg = (pdfdictionary)pdfreader.getpdfobject(obj);
pdfname type =
(pdfname)pdfreader.getpdfobject(tg.get(pdfname.subtype));
if (pdfname.image.equals(type)) {
pdfreader.killindirect(obj);
image maskimage = img.getimagemask();
if (maskimage != null)
writer.adddirectimagesimple(maskimage);
writer.adddirectimagesimple(img, (prindirectreference)obj);
}
}
stp.close();
if can me work in cf, appreciate it:
pdfreader pdf = new pdfreader("in.pdf");
pdfstamper stp = new pdfstamper(pdf, new fileoutputstream("out.pdf"));
pdfwriter writer = stp.getwriter();
image img = image.getinstance("image.png");
acrofields af = stp.getacrofields();
acrofields.item item = af.getfielditem("button1");
pdfdictionary dic = (pdfdictionary)item.widgets.get(0);
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.ap));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.n));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.resources));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.xobject));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.frm));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.resources));
dic = (pdfdictionary)pdfreader.getpdfobject(dic.get(pdfname.xobject));
pdfobject obj = dic.get((pdfname)dic.getkeys().iterator().next());
if (obj.isindirect()) {
pdfdictionary tg = (pdfdictionary)pdfreader.getpdfobject(obj);
pdfname type =
(pdfname)pdfreader.getpdfobject(tg.get(pdfname.subtype));
if (pdfname.image.equals(type)) {
pdfreader.killindirect(obj);
image maskimage = img.getimagemask();
if (maskimage != null)
writer.adddirectimagesimple(maskimage);
writer.adddirectimagesimple(img, (prindirectreference)obj);
}
}
stp.close();
More discussions in Advanced Techniques
adobe
Comments
Post a Comment