I am trying to open a standard PDF form from a legacy application in Android, overlay form fields using iText and pass to Adobe Reader on Android to fill out the form.
I have been able to create the TextFields manually but I would prefer to have a pdf file as a template to speed up the process and better control quality.
Here is the code I have so far, this follows the itext examples.
AssetFileDescriptor descriptor = getAssets().openFd("standardWO_Template_v1_fo.pdf");
File templateFile = new File(descriptor.getFileDescriptor().toString());
PdfReader reader = new PdfReader(intent.getData().getPath());
reader.selectPages("1");
PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath());
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file));
// Stamp the template onto the document
PdfImportedPage page = stamper.getImportedPage(templateReader, 1);
PdfContentByte cb = stamper.getOverContent(1);
cb.addTemplate(page, 0, 0);
The issue I am having is on the last line. cb.addTemplate(page, 0,0);
Eclipse reports the following error. The type java.awt.geom.AffineTransform cannot be resolved. It is indirectly referenced from required .class files
From what I have been able to tell java.awt.geom.AffineTransform will not work in Android only Java.
Is there a different way to accomplish my task or get AffineTransform to work in Android?
After some more searching I found this method. First I had to change from using the iText5.3.1 library in my android project to the droidText library.
Once I installed the droidText library was able to use the following code. (and a ctrl-o in eclipse)
File templateFile = new File(dir.getAbsolutePath() + "/templates/standardWO.pdf");
// Read the incoming file
PdfReader reader = new PdfReader(intent.getData().getPath());
// Read the template form information
PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath());
// Create the stamper from the incoming file.
PdfStamper stamper = new PdfStamper(templateReader, new FileOutputStream(file));
// Import the template information
PdfImportedPage iPage = stamper.getImportedPage(reader, 1);
// get the direct content
PdfContentByte cb = stamper.getUnderContent(1);
// Add the imported page to the content
cb.addTemplate(iPage, 0, 0);
stamper.close();
Log.v(TAG, "Opening file in adobe reader: " + file.getAbsolutePath());
loadDocInReader(file);