List of usage examples for com.lowagie.text.pdf AcroFields getFieldPositions
public float[] getFieldPositions(String name)
From source file:androidGLUESigner.pdf.PDFSigExtractor.java
License:Open Source License
/** * extracts the signature field for previewing. * @throws IOException /*from ww w . j av a 2s .c om*/ */ public static ArrayList<SignatureInfo> getSignatureInfo(String inputPath) { PdfReader reader; try { reader = new PdfReader(inputPath); } catch (IOException e) { return new ArrayList<SignatureInfo>(); } AcroFields af = reader.getAcroFields(); ArrayList names = af.getSignatureNames(); ArrayList<SignatureInfo> signatures = new ArrayList<SignatureInfo>(); // For every signature : for (int k = 0; k < names.size(); ++k) { String name = (String) names.get(k); SignatureInfo sigInfo = new SignatureInfo(); // get coordinates float[] position = af.getFieldPositions(name); // page number float page = position[0]; // left float llx = position[1]; // bottom float lly = position[2]; // right float urx = position[3]; // top float ury = position[4]; // get size of pdf page Rectangle size = reader.getPageSize((int) page); float height = size.getHeight(); // subtract height to translate to Android canvas coordinate system lly = height - lly; ury = height - ury; float ulx = llx; // create a Rectangle from obtained signature field coordinates Rect sigRect = new Rect((int) ulx, (int) ury, (int) urx, (int) lly); sigInfo.setGraphicRect(sigRect, 1.0f); // obtain additional information like reason, location, ... PdfDictionary sig = af.getSignatureDictionary(name); sigInfo.setSignatureName(sig.getAsString(PdfName.NAME).toString()); sigInfo.setSignatureLocation(sig.getAsString(PdfName.LOCATION).toString()); sigInfo.setSignatureReason(sig.getAsString(PdfName.REASON).toString()); sigInfo.setSignatureType(SignatureType.NORMAL); sigInfo.setPageNumber((int) page); // add new signature information to signatures signatures.add(sigInfo); } return signatures; }
From source file:buckley.extract.Extractor.java
License:Apache License
public Document extract(InputStream input) { Document document = new Document(); PdfReader pdfReader = pdfReaderFactory.build(input); AcroFields acroFields = pdfReader.getAcroFields(); if (acroFields == null) throw new IllegalStateException("No form found on pdf"); HashMap fields = acroFields.getFields(); for (Object key : fields.keySet()) { String fieldName = (String) key; int[] pageNumbers = pageNumberEvaluator.getPages(acroFields.getFieldPositions(fieldName)); int fieldCount = 0; for (int pageNumber : pageNumbers) { Field field = fieldFactory.build(acroFields.getFieldType(fieldName)); field.setName(fieldName);/*from w w w. j a v a 2 s.c om*/ Page page = document.getPage(pageNumber); if (page == null) { page = new Page(pageNumber); document.addPage(page); } for (ITextFieldExtractor fieldExtractor : fieldExtractors) { if (fieldExtractor.canExtract(field)) { fieldExtractor.extract(fieldCount, field, fieldName, acroFields); } } page.addField(field); fieldCount++; } } return document; }
From source file:buckley.extract.LocationAndSizeExtractor.java
License:Apache License
public void extract(int sameFieldNameCount, Field field, String fieldName, AcroFields fields) { float[] positions = fields.getFieldPositions(fieldName); int offset = sameFieldNameCount * 5; field.setX(positions[1 + offset]);// w w w.j a v a2 s . c om field.setY(positions[3 + offset]); field.setWidth(positions[3 + offset] - positions[1 + offset]); field.setHeight(positions[4 + offset] - positions[2 + offset]); }
From source file:classroom.filmfestival_c.Movies25.java
public static byte[] createPdf(FilmTitle movie) throws IOException, DocumentException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfReader reader = new PdfReader(TEMPLATE); PdfStamper stamper = new PdfStamper(reader, baos); AcroFields form = stamper.getAcroFields(); File file = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (file.exists()) { PushbuttonField bt = form.getNewPushbuttonFromField(POSTER); bt.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); bt.setProportionalIcon(true);/*from w w w. ja va 2 s . c o m*/ bt.setImage(Image.getInstance(file.getPath())); form.replacePushbuttonField(POSTER, bt.getField()); } String s = createHtml(movie); PdfContentByte canvas = stamper.getOverContent(1); float size = 12; float[] f = form.getFieldPositions(TEXT); while (addText(s, canvas, f, size, true) && size > 6) { size -= 0.2; } addText(s, canvas, f, size, false); form.setField(YEAR, String.valueOf(movie.getYear())); stamper.setFormFlattening(true); stamper.close(); return baos.toByteArray(); }
From source file:classroom.newspaper_b.Newspaper11.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {//from w ww . j av a 2 s . c o m PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fill(); addTextField(stamper, new Rectangle(LLX1, LLY1, URX1, URY1), "field1", 1); addTextField(stamper, new Rectangle(LLX2, LLY2, URX2, URY2), "field2", 1); stamper.close(); reader = new PdfReader(RESULT); AcroFields fields = reader.getAcroFields(); Set<String> fieldnames = fields.getFields().keySet(); for (String fieldname : fieldnames) { System.out.print(fieldname); System.out.print(": page "); float[] positions = fields.getFieldPositions(fieldname); System.out.print(positions[0]); System.out.print(" [ "); System.out.print(positions[1]); System.out.print(", "); System.out.print(positions[2]); System.out.print(", "); System.out.print(positions[3]); System.out.print(", "); System.out.print(positions[4]); System.out.println("]"); } } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper12.java
public static void main(String[] args) { Newspaper11.main(args);/*from w w w. j a va 2 s. com*/ try { PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); AcroFields fields = stamper.getAcroFields(); fields.setField("field1", "Advertissement 1"); float[] positions1 = fields.getFieldPositions("field1"); putImage(stamper.getOverContent((int) positions1[0]), IMG1, positions1); fields.setField("field2", "Advertissement 2"); float[] positions2 = fields.getFieldPositions("field2"); putImage(stamper.getOverContent((int) positions2[0]), IMG2, positions2); stamper.setFormFlattening(true); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:corner.orm.tapestry.pdf.PdfTemplateParser.java
License:Apache License
/** * reader??pdf.//w ww . j a va 2 s .co m * * @param reader * pdf reader */ void parse() { AcroFields form = reader.getAcroFields(); HashMap fields = form.getFields(); for (Iterator i = fields.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); switch (form.getFieldType(key)) { case AcroFields.FIELD_TYPE_TEXT: // TextField? if (PAGE_CLASS_DEFINE_FIELD_NAME.equals(key)) { this.pageClass = form.getField(key); break; } float[] p = form.getFieldPositions(key); int step = 5; int num = p.length / step; for (int j = 0; j < num; j++) { //??? PdfBlock block = new PdfBlock();// createBlockByName(key); if (block == null) { break; } block.setPosition(new float[] { p[j * step], p[j * step + 1], p[j * step + 2], p[j * step + 3], p[j * step + 4] }); block.setName(key); block.setValue(form.getField(key)); int pageNum = block.getPageNum(); List<PdfBlock> pagefs = pageFields.get(pageNum); if (pagefs == null) { pagefs = new ArrayList<PdfBlock>(); pageFields.put(pageNum, pagefs); } pagefs.add(block); } break; default: break; } } }
From source file:hornet.framework.export.fdf.FDF.java
License:CeCILL license
/** * Fusion d'un champ FDF./*from w w w .j a v a 2s . c om*/ * * @param data * the data * @param stamper * the stamper * @param res * the res * @param form * the form * @param nomField * the nom field * @throws IOException * Signals that an I/O exception has occurred. * @throws DocumentException * the document exception */ private static void fusionChamp(final Object data, final PdfStamper stamper, final FDFRes res, final AcroFields form, final Object nomField) throws IOException, DocumentException { // utilisation du ":" comme sparateur d'accs. // le "." tant remplac par "_" par openoffice lors // de la conversion PDF. final String nomFieldStr = nomField.toString().replace(':', '.'); Object value = null; try { value = PropertyUtils.getProperty(data, nomFieldStr); } catch (final Exception ex) { res.getUnmerged().add(nomFieldStr); } String valueStr; if (value == null) { valueStr = ""; // itext n'accepte pas les valeurs // nulles form.setField(nomField.toString(), valueStr); } else if (value instanceof FDFImage) { final FDFImage imValue = (FDFImage) value; final float[] positions = form.getFieldPositions(nomField.toString()); final PdfContentByte content = stamper.getOverContent(1); final Image im = Image.getInstance(imValue.getData()); if (imValue.isFit()) { content.addImage(im, positions[FieldBoxPositions.URX.ordinal()] - positions[FieldBoxPositions.LLX.ordinal()], 0, 0, positions[FieldBoxPositions.URY.ordinal()] - positions[FieldBoxPositions.LLY.ordinal()], positions[FieldBoxPositions.LLX.ordinal()], positions[FieldBoxPositions.LLY.ordinal()]); } else { content.addImage(im, im.getWidth(), 0, 0, im.getHeight(), positions[1], positions[2]); } } else if (value instanceof Date) { // format par dfaut date valueStr = DateFormat.getDateInstance(DateFormat.SHORT).format(value); form.setField(nomField.toString(), valueStr); } else if (value instanceof Boolean) { // format par spcial pour Checkbox if (Boolean.TRUE.equals(value)) { valueStr = "Yes"; } else { valueStr = "No"; } form.setField(nomField.toString(), valueStr); } else { // format par dfaut valueStr = value.toString(); form.setField(nomField.toString(), valueStr); } }
From source file:org.apache.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** * */// w w w . j ava 2 s . c o m public static Map<String, Object> buildSurveyFromPdf(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); String surveyId = null; try { String surveyName = (String) context.get("surveyName"); ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader pdfReader = new PdfReader(byteBuffer.array()); PdfStamper pdfStamper = new PdfStamper(pdfReader, os); AcroFields acroFields = pdfStamper.getAcroFields(); Map<String, Object> acroFieldMap = UtilGenerics.checkMap(acroFields.getFields()); String contentId = (String) context.get("contentId"); GenericValue survey = null; surveyId = (String) context.get("surveyId"); if (UtilValidate.isEmpty(surveyId)) { survey = delegator.makeValue("Survey", UtilMisc.toMap("surveyName", surveyName)); survey.set("surveyId", surveyId); survey.set("allowMultiple", "Y"); survey.set("allowUpdate", "Y"); survey = delegator.createSetNextSeqId(survey); surveyId = survey.getString("surveyId"); } // create a SurveyQuestionCategory to put the questions in Map<String, Object> createCategoryResultMap = dispatcher.runSync("createSurveyQuestionCategory", UtilMisc.<String, Object>toMap("description", "From AcroForm in Content [" + contentId + "] for Survey [" + surveyId + "]", "userLogin", userLogin)); String surveyQuestionCategoryId = (String) createCategoryResultMap.get("surveyQuestionCategoryId"); pdfStamper.setFormFlattening(true); for (String fieldName : acroFieldMap.keySet()) { AcroFields.Item item = acroFields.getFieldItem(fieldName); int type = acroFields.getFieldType(fieldName); String value = acroFields.getField(fieldName); Debug.logInfo("fieldName:" + fieldName + "; item: " + item + "; value: " + value, module); GenericValue surveyQuestion = delegator.makeValue("SurveyQuestion", UtilMisc.toMap("question", fieldName)); String surveyQuestionId = delegator.getNextSeqId("SurveyQuestion"); surveyQuestion.set("surveyQuestionId", surveyQuestionId); surveyQuestion.set("surveyQuestionCategoryId", surveyQuestionCategoryId); if (type == AcroFields.FIELD_TYPE_TEXT) { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); } else if (type == AcroFields.FIELD_TYPE_RADIOBUTTON) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); } else if (type == AcroFields.FIELD_TYPE_LIST || type == AcroFields.FIELD_TYPE_COMBO) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); // TODO: handle these specially with the acroFields.getListOptionDisplay (and getListOptionExport?) } else { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); Debug.logWarning("Building Survey from PDF, fieldName=[" + fieldName + "]: don't know how to handle field type: " + type + "; defaulting to short text", module); } // ==== create a good sequenceNum based on tab order or if no tab order then the page location Integer tabPage = item.getPage(0); Integer tabOrder = item.getTabOrder(0); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder, module); //array of float multiple of 5. For each of this groups the values are: [page, llx, lly, urx, ury] float[] fieldPositions = acroFields.getFieldPositions(fieldName); float fieldPage = fieldPositions[0]; float fieldLlx = fieldPositions[1]; float fieldLly = fieldPositions[2]; float fieldUrx = fieldPositions[3]; float fieldUry = fieldPositions[4]; Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry, module); Long sequenceNum = null; if (tabPage != null && tabOrder != null) { sequenceNum = Long.valueOf(tabPage.intValue() * 1000 + tabOrder.intValue()); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder + ", sequenceNum=" + sequenceNum, module); } else if (fieldPositions.length > 0) { sequenceNum = Long.valueOf((long) fieldPage * 10000 + (long) fieldLly * 1000 + (long) fieldLlx); Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry + ", sequenceNum=" + sequenceNum, module); } // TODO: need to find something better to put into these fields... String annotation = null; for (int k = 0; k < item.size(); ++k) { PdfDictionary dict = item.getWidget(k); // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation PdfObject typeValue = null; PdfObject tuValue = null; Set<PdfName> dictKeys = UtilGenerics.checkSet(dict.getKeys()); for (PdfName dictKeyName : dictKeys) { PdfObject dictObject = dict.get(dictKeyName); if ("/Type".equals(dictKeyName.toString())) { typeValue = dictObject; } else if ("/TU".equals(dictKeyName.toString())) { tuValue = dictObject; } } if (tuValue != null && typeValue != null && "/Annot".equals(typeValue.toString())) { annotation = tuValue.toString(); } } surveyQuestion.set("description", fieldName); if (UtilValidate.isNotEmpty(annotation)) { surveyQuestion.set("question", annotation); } else { surveyQuestion.set("question", fieldName); } GenericValue surveyQuestionAppl = delegator.makeValue("SurveyQuestionAppl", UtilMisc.toMap("surveyId", surveyId, "surveyQuestionId", surveyQuestionId)); surveyQuestionAppl.set("fromDate", nowTimestamp); surveyQuestionAppl.set("externalFieldRef", fieldName); if (sequenceNum != null) { surveyQuestionAppl.set("sequenceNum", sequenceNum); } surveyQuestion.create(); surveyQuestionAppl.create(); } pdfStamper.close(); if (UtilValidate.isNotEmpty(contentId)) { survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne(); survey.set("acroFormContentId", contentId); survey.store(); } } catch (GenericEntityException e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (GeneralException e) { Debug.logError(e, "Error generating PDF: " + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } catch (Exception e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("surveyId", surveyId); return results; }
From source file:org.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** * *//*from w w w . j av a 2 s . c o m*/ public static Map<String, Object> buildSurveyFromPdf(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); String surveyId = null; try { String surveyName = (String) context.get("surveyName"); ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader pdfReader = new PdfReader(byteBuffer.array()); PdfStamper pdfStamper = new PdfStamper(pdfReader, os); AcroFields acroFields = pdfStamper.getAcroFields(); Map<String, Object> acroFieldMap = UtilGenerics.checkMap(acroFields.getFields()); String contentId = (String) context.get("contentId"); GenericValue survey = null; surveyId = (String) context.get("surveyId"); if (UtilValidate.isEmpty(surveyId)) { survey = delegator.makeValue("Survey", UtilMisc.toMap("surveyName", surveyName)); survey.set("surveyId", surveyId); survey.set("allowMultiple", "Y"); survey.set("allowUpdate", "Y"); survey = delegator.createSetNextSeqId(survey); surveyId = survey.getString("surveyId"); } // create a SurveyQuestionCategory to put the questions in Map<String, Object> createCategoryResultMap = dispatcher.runSync("createSurveyQuestionCategory", UtilMisc.<String, Object>toMap("description", "From AcroForm in Content [" + contentId + "] for Survey [" + surveyId + "]", "userLogin", userLogin)); String surveyQuestionCategoryId = (String) createCategoryResultMap.get("surveyQuestionCategoryId"); pdfStamper.setFormFlattening(true); for (String fieldName : acroFieldMap.keySet()) { AcroFields.Item item = acroFields.getFieldItem(fieldName); int type = acroFields.getFieldType(fieldName); String value = acroFields.getField(fieldName); Debug.logInfo("fieldName:" + fieldName + "; item: " + item + "; value: " + value, module); GenericValue surveyQuestion = delegator.makeValue("SurveyQuestion", UtilMisc.toMap("question", fieldName)); String surveyQuestionId = delegator.getNextSeqId("SurveyQuestion"); surveyQuestion.set("surveyQuestionId", surveyQuestionId); surveyQuestion.set("surveyQuestionCategoryId", surveyQuestionCategoryId); if (type == AcroFields.FIELD_TYPE_TEXT) { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); } else if (type == AcroFields.FIELD_TYPE_RADIOBUTTON) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); } else if (type == AcroFields.FIELD_TYPE_LIST || type == AcroFields.FIELD_TYPE_COMBO) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); // TODO: handle these specially with the acroFields.getListOptionDisplay (and getListOptionExport?) /*String[] listOptionDisplayArray = acroFields.getListOptionDisplay(fieldName); String[] listOptionExportArray = acroFields.getListOptionExport(fieldName); Debug.logInfo("listOptionDisplayArray: " + listOptionDisplayArray + "; listOptionExportArray: " + listOptionExportArray, module);*/ } else { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); Debug.logWarning("Building Survey from PDF, fieldName=[" + fieldName + "]: don't know how to handle field type: " + type + "; defaulting to short text", module); } // ==== create a good sequenceNum based on tab order or if no tab order then the page location Integer tabPage = item.getPage(0); Integer tabOrder = item.getTabOrder(0); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder, module); //array of float multiple of 5. For each of this groups the values are: [page, llx, lly, urx, ury] float[] fieldPositions = acroFields.getFieldPositions(fieldName); float fieldPage = fieldPositions[0]; float fieldLlx = fieldPositions[1]; float fieldLly = fieldPositions[2]; float fieldUrx = fieldPositions[3]; float fieldUry = fieldPositions[4]; Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry, module); Long sequenceNum = null; if (tabPage != null && tabOrder != null) { sequenceNum = Long.valueOf(tabPage.intValue() * 1000 + tabOrder.intValue()); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder + ", sequenceNum=" + sequenceNum, module); } else if (fieldPositions.length > 0) { sequenceNum = Long.valueOf((long) fieldPage * 10000 + (long) fieldLly * 1000 + (long) fieldLlx); Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry + ", sequenceNum=" + sequenceNum, module); } // TODO: need to find something better to put into these fields... String annotation = null; for (int k = 0; k < item.size(); ++k) { PdfDictionary dict = item.getWidget(k); // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation /* Interesting... this doesn't work, I guess we have to iterate to find the stuff... PdfObject typeValue = dict.get(new PdfName("/Type")); if (typeValue != null && "/Annot".equals(typeValue.toString())) { PdfObject tuValue = dict.get(new PdfName("/TU")); annotation = tuValue.toString(); } */ PdfObject typeValue = null; PdfObject tuValue = null; Set<PdfName> dictKeys = UtilGenerics.checkSet(dict.getKeys()); for (PdfName dictKeyName : dictKeys) { PdfObject dictObject = dict.get(dictKeyName); if ("/Type".equals(dictKeyName.toString())) { typeValue = dictObject; } else if ("/TU".equals(dictKeyName.toString())) { tuValue = dictObject; } //Debug.logInfo("AcroForm widget fieldName[" + fieldName + "] dictKey[" + dictKeyName.toString() + "] dictValue[" + dictObject.toString() + "]", module); } if (tuValue != null && typeValue != null && "/Annot".equals(typeValue.toString())) { annotation = tuValue.toString(); } } surveyQuestion.set("description", fieldName); if (UtilValidate.isNotEmpty(annotation)) { surveyQuestion.set("question", annotation); } else { surveyQuestion.set("question", fieldName); } GenericValue surveyQuestionAppl = delegator.makeValue("SurveyQuestionAppl", UtilMisc.toMap("surveyId", surveyId, "surveyQuestionId", surveyQuestionId)); surveyQuestionAppl.set("fromDate", nowTimestamp); surveyQuestionAppl.set("externalFieldRef", fieldName); if (sequenceNum != null) { surveyQuestionAppl.set("sequenceNum", sequenceNum); } surveyQuestion.create(); surveyQuestionAppl.create(); } pdfStamper.close(); if (UtilValidate.isNotEmpty(contentId)) { survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne(); survey.set("acroFormContentId", contentId); survey.store(); } } catch (GenericEntityException e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (GeneralException e) { Debug.logError(e, "Error generating PDF: " + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } catch (Exception e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("surveyId", surveyId); return results; }