I have an existing pdf that I am filling out dynamically in java. I have all the fields that require strings set up and working, but the fields that use int or date dont seem to work. Here is the relevant code:
response.setHeader(contentDisposition, "attachment; filename=" + officialFile);
reader = new PdfReader(this.getServletContext().getResource("/pdf/" + officialFile));
stamp = new PdfStamper(reader, response.getOutputStream());
form = stamp.getAcroFields();
// form.setField("date", currentDate); //This is a date, and will give me an error
form.setField("last_name", lName);
form.setField("first_name", fName);
form.setField("first_middle_last", fmlName);
form.setField("status", studentStatus);
// form.setField("HR's", hours); //This is an int, and will give me an error
// form.setField("CENSUS DATE", censusDate); //This is a date, and will give me an error
form.setField("term", term);
stamp.setFormFlattening(true);
stamp.close();
So the parts that are commented out are where my int’s and dates are supposed to be written on the pdf. I was wondering if there was a way to write them to this pdf without converting them to strings, and if there is no way…..then what would be the best way to convert them? Thanks in advance.
Convert them.
For the Date use the SimpleDateFormatter according to your requirements.