Merge PDF

Nous essayons de faire OpenKM aussi intuitif que possible, mais tout avis est bienvenu.

Moderator: dedisoft

Forum rules
Avant de poser une question, merci de regarder la documentation du wiki ou d'utiliser la fonction recherche du forum. Et rappelez vous que nous n'avons ni boule de cristal ni possibilité de lire dans les pensées, aussi pensez à spécifier quelle version d'OpenKM vous utilisez ainsi que la version du navigateur web et du système d'exploitation. Pour de plus amples informations lisez Comment reporter un bug efficacement (anglais).
Post Reply
jimac
Expert Boarder
Expert Boarder
Posts: 89
Joined: Thu Dec 01, 2016 4:01 am

Merge PDF

Post by jimac » Tue Feb 07, 2017 6:28 am

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

jllort
Moderator
Moderator
Posts: 10078
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Merge PDF

Post by jllort » Thu Feb 09, 2017 7:33 pm

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

jimac
Expert Boarder
Expert Boarder
Posts: 89
Joined: Thu Dec 01, 2016 4:01 am

Re: Merge PDF

Post by jimac » Fri Feb 10, 2017 8:29 am

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.
Attachments
33.png

jllort
Moderator
Moderator
Posts: 10078
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Merge PDF

Post by jllort » Sat Feb 11, 2017 4:53 pm

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.

jimac
Expert Boarder
Expert Boarder
Posts: 89
Joined: Thu Dec 01, 2016 4:01 am

Re: Merge PDF

Post by jimac » Wed Feb 15, 2017 1:36 am

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?

jllort
Moderator
Moderator
Posts: 10078
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Merge PDF

Post by jllort » Fri Feb 17, 2017 11:09 am

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.

jorseng
Junior Boarder
Junior Boarder
Posts: 21
Joined: Tue Jan 16, 2018 2:22 pm

Re: Merge PDF

Post by jorseng » Wed May 23, 2018 2:47 pm

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?

jllort
Moderator
Moderator
Posts: 10078
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Merge PDF

Post by jllort » Thu May 24, 2018 7:59 am

Should take a look at PDFUtils.class to use the merge method.
https://github.com/openkm/document-mana ... .java#L145

jorseng
Junior Boarder
Junior Boarder
Posts: 21
Joined: Tue Jan 16, 2018 2:22 pm

Re: Merge PDF

Post by jorseng » Fri May 25, 2018 3:29 am

Dear jllort,

Noted with Thanks! :lol:

jorseng
Junior Boarder
Junior Boarder
Posts: 21
Joined: Tue Jan 16, 2018 2:22 pm

Re: Merge PDF

Post by jorseng » Tue Jun 05, 2018 7:44 am

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?

jorseng
Junior Boarder
Junior Boarder
Posts: 21
Joined: Tue Jan 16, 2018 2:22 pm

Re: Merge PDF

Post by jorseng » Tue Jun 05, 2018 8:44 am

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.

jllort
Moderator
Moderator
Posts: 10078
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Merge PDF

Post by jllort » Wed Jun 06, 2018 11:18 am

The dstPath variable of the method merge ends with .pdf ? might be this is the reason why is not working

jorseng
Junior Boarder
Junior Boarder
Posts: 21
Joined: Tue Jan 16, 2018 2:22 pm

Re: Merge PDF

Post by jorseng » Thu Jun 07, 2018 1:15 am

Yup you are right!
I added .pdf to the filename, it is working now.
Thanks a lot jllort!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest