Page 1 of 1

Merge PDF

Posted: Tue Feb 07, 2017 6:28 am
by jimac
Hello Jllort, :D

Is this possible?? :

When 2 documents have a specific property group assigned, can the property group be also taken when the 2 documents is merged?
wherein when the 2 document is merged, the property group is automatically taken. (therefore the merged pdf will have 2 property group assigned)

Thanks

Re: Merge PDF

Posted: Thu Feb 09, 2017 7:33 pm
by jllort
First of all, the merge PDF feature is only available at professional version. About inherit metadata, can be done something in the direction you propose, but is necessary create an specific logic for your case. Here are the cases
A and B have not metadata
A and B have both metadata ( something to thinking about )
A or B have metadata -> then can inherit directly

Re: Merge PDF

Posted: Fri Feb 10, 2017 8:29 am
by jimac
jllort wrote:First of all, the merge PDF feature is only available at professional version. About inherit metadata, can be done something in the direction you propose, but is necessary create an specific logic for your case. Here are the cases
A and B have not metadata
A and B have both metadata ( something to thinking about )
A or B have metadata -> then can inherit directly
Yep, that are the possible cases.
Is it possible..
--
I have merge PDF even though Im using openKM community..
Please see the attached picture.

Re: Merge PDF

Posted: Sat Feb 11, 2017 4:53 pm
by jllort
The best option will be create an event for it ( automation ) and link in the event the logic. If you want I can guide you in the changes should be done in source code.

Re: Merge PDF

Posted: Wed Feb 15, 2017 1:36 am
by jimac
jllort wrote:The best option will be create an event for it ( automation ) and link in the event the logic. If you want I can guide you in the changes should be done in source code.
In changing the source code, I need to download openKM dev and configure it?
That means, I will be using a new openkm right?

Re: Merge PDF

Posted: Fri Feb 17, 2017 11:09 am
by jllort
You will use an OpenKM with small modification. If you share with us the modification and we think is general purpose one, we will introduce in the main code. But althought we do not doing it, you can periodicaly update your local code with remote code changes and be updated.

Re: Merge PDF

Posted: Wed May 23, 2018 2:47 pm
by jorseng
Hi jllort,
I am very much interested in automation to merge pdf based on the property group and then remove the files which has been merged to reduce duplicate. Can you guide me to make the necessary changes in the source code?

Re: Merge PDF

Posted: Thu May 24, 2018 7:59 am
by jllort
Should take a look at PDFUtils.class to use the merge method.
https://github.com/openkm/document-mana ... .java#L145

Re: Merge PDF

Posted: Fri May 25, 2018 3:29 am
by jorseng
Dear jllort,

Noted with Thanks! :lol:

Re: Merge PDF

Posted: Tue Jun 05, 2018 7:44 am
by jorseng
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
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?

Re: Merge PDF

Posted: Tue Jun 05, 2018 8:44 am
by jorseng
It seems that after merging, the file extension becomes octet-stream instead of pdf using the merge() function.
I tried changing the new document name with extension .pdf seems to not affect any changes on the MIME-type.
I suspect the preview isn't working for the pdf simply because of the extension.

In the merge() code, has this line

Code: Select all

docOut = FileUtils.createTempFileFromMime(MimeTypeConfig.MIME_PDF);
but resulting file doesn't seem to follow this.

Re: Merge PDF

Posted: Wed Jun 06, 2018 11:18 am
by jllort
The dstPath variable of the method merge ends with .pdf ? might be this is the reason why is not working

Re: Merge PDF

Posted: Thu Jun 07, 2018 1:15 am
by jorseng
Yup you are right!
I added .pdf to the filename, it is working now.
Thanks a lot jllort!