Hi,
I am testing out the merge method in PDFUtils package. I search documents based on metadata, when there are 2 documents with the same property value, i merge them together using PDFUtils.merge(token,docid,dstpath).
The following is the results, somehow the files merged but without content.
Merged with no content.png (13.34 KiB) Viewed 32585 times
The following is my code
Code: Select all// Automation for PDF merging
package com.openkm.automation.action;
import java.util.Map;
import com.openkm.api.OKMRepository;
import com.openkm.util.PDFUtils;
import com.openkm.api.*;
import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.automation.AutomationUtils;
import com.openkm.dao.bean.Automation;
import com.openkm.automation.Action;
import net.xeoh.plugins.base.annotations.PluginImplementation;
String systemToken = DbSessionManager.getInstance().getSystemToken();
// Lookup for MRN, if same merge
String uuid = "52cc9baf-f981-4e87-add5-94115ad037e5";
String group = "okg:medicalrecord";
List pg = OKMPropertyGroup.getInstance().getProperties(systemToken,uuid,group);
for (Object x : pg) {
int y =1;
String pName ="okp:medicalrecord.mrn";
String gName ="okg:medicalrecord";
if(x.name.contains(pName)){
print(x.value);
searchResult = OKMSearch.getInstance().getDocumentsByPropertyValue(systemToken,gName,pName,x.value);
//print(searchResult);
List<String> docMerge = new ArrayList<String>();
if (searchResult !=null) {
for(Object doc : searchResult) {
print(doc.path);
docMerge.add(new String (doc.path));
}
print(docMerge.size());
Object lastDoc = searchResult.get(searchResult.size()-1);
if(docMerge.size()>1) {
//print("more than 1");
int endIndex = lastDoc.path.lastIndexOf("/");
if(endIndex != -1){
String folderPath = lastDoc.path.substring(0,endIndex);
//String newDocName = folderPath + lastDoc.path.substring(endIndex) + " Merged";
String newDocName = folderPath + docMerge.get(0).substring(endIndex) + " " + docMerge.get(1).substring(endIndex).replace("/","");
print(newDocName);
PDFUtils.merge(systemToken,docMerge,newDocName);
}
}
}
print(docMerge);
}
//Search for documents with the same MRN.
//get attachment
}
Am i using the merge() function wrong?