Thanks for the response. Here is the complete code. It’s working for xfdf but not for fdf. here is the method.
private void merge(IDfSession session, String parentId, List<String> childIds) {
LOGGER.debug(ENTER + " merge()");
try {
//tmp stores pdf to work on
String tmp = "tmp\\";
File file = new File(tmp);
if(!file.exists()) {
file.mkdir();
}
appendToReport("Current parent id: " + parentId + " - child ids: " + childIds.toString());
//get pdf document from docbase
IDfSysObject pdfDoc = (IDfSysObject) session.getObject(new DfId(parentId));
String docFileName = getDocFile(pdfDoc, tmp, "pdf");
if(docFileName == null) {
return;
}
PdfAnnotationEditor editor = null;
Form formEditor = null;
boolean successfulImport, containsSuccess=false;
String successfulImports = "";
List<String[]> errors = new ArrayList<String[]>();
IDfSysObject note;
for(String id : childIds) {
//get note from docbase
note = (IDfSysObject) session.getObject(new DfId(id));
String contentType = note.getString("a_content_type");
String noteFile = getDocFile(note, tmp, contentType);
if(noteFile != null) {
try {
successfulImport = false;
switch(contentType) {
case "xfdf":
editor = new PdfAnnotationEditor();
appendToReport("Importing xfdf - " + noteFile);
editor.bindPdf(tmp + docFileName);
try {
editor.importAnnotationFromXfdf(tmp + noteFile);
}catch(Exception e) {
formEditor = new Form();
formEditor.bindPdf(tmp+docFileName);
FileInputStream xfdfInputStream = new FileInputStream(tmp + noteFile);
formEditor.importXfdf(xfdfInputStream);
xfdfInputStream.close();
}
successfulImport = true;
break;
case "fdf":
appendToReport("Importing fdf - " + noteFile);
formEditor = new Form();
formEditor.bindPdf(tmp + docFileName);
FileInputStream fdfInputStream = new FileInputStream(tmp + noteFile);
formEditor.importFdf(fdfInputStream);
fdfInputStream.close();
successfulImport = true;
break;
default:
break;
}
if(successfulImport) {
editor.save(tmp + docFileName);
containsSuccess = true;
appendToReport("File imported to " + docFileName + ": parentId - " + parentId + " childId - " + id);
successfulImports += (id + "-" + noteFile + "|");
}
else {
errors.add(new String[] {docFileName, noteFile, "Unsuccessful Import!"});
appendToReport("Import failed: parentId - " + parentId + " childId - " + id );
}
}catch(Exception ex) {
LOGGER.error("Error importing note - " + noteFile + ": " + ex.toString());
appendToReport("Error importing note - " + noteFile);
errors.add(new String[] {docFileName, noteFile, ex.toString()});
}
finally {
if(editor != null) {
editor.close();
}
}
}
if(containsSuccess) {
pdfDoc.addRenditionEx2(new File(tmp+docFileName).getAbsolutePath(), "pdf", 0, page_mod, null, false, false, false);
pdfDoc.save();
writeToCSVFile(parentId, docFileName, successfulImports);
}
for(String[] e : errors) {
report.writeToErrorCSV(e[0], e[1], e[2]);
}
}
}catch(DfException e) {
LOGGER.error("Exception processing query!", e);
appendToReport("!!ERROR!! There was an error during processing. For additional information please check the log files");
}
}
private String getDocFile(IDfSysObject docObj, String dest, String ext) {
appendToReport("Getting document from docbase...");
String fileName = null;
try {
appendToReport("Doc extension - " + docObj.getContentType());
if(docObj.getContentType().toString().equals(ext)) {
fileName = docObj.getObjectName()+"."+ext;
docObj.getFileEx(dest+fileName, ext, 0, false);
}
} catch (DfException e) {
appendToReport("Could not get file.: " + e.getMessage());
LOGGER.debug("!!ERROR!!Could not get file docName!");
}
appendToReport("Got document - " + fileName);
return fileName;
}