Skip to Content

Extract CLM contract documents (PDF) from SAP CLM

Hi,

We are trying to download the contract document in Sourcing server from a Master agreement using the toolbar script. All the contract documents are in .pdf format. The below program was able to download the CLM contract document in sourcing server path "/sourcing/inbound/materials/upload/"but unable to open the PDF document. I have attached the toolbar script screenshot, the program and corrupted PDF document. I am getting an error as "The file is damaged and could not be repaired". We are on CLM verison: 9.0.07.

I think the issue is with the below code. Can someone please check and help me to fix the below code.

d = new DataInputStream(new FileInputStream(fileData));

out = new DataOutputStream(new FileOutputStream(file));

corrupted-pdf-document-error.png

import com.sap.eso.api.contracts.ContractIBeanHomeIfc;  
import com.sap.eso.api.contracts.ContractIBeanIfc;  
import com.sap.odp.api.common.types.AttachmentIfc;  
import com.sap.odp.api.comp.attachments.AttachmentSubIBeanIfc;  
import com.sap.odp.api.ibean.OrderedSubordinateCollectionIfc;  
import com.sap.odp.api.ibean.SubordinateCollectionIfc; 
import com.sap.eso.api.common.types.ObjectReferenceIfc;
import com.sap.eso.api.common.types.TypeFactory;
import com.sap.eso.api.contracts.ContractIBeanIfc.*;
import com.sap.eso.common.db.PersistentBo;
import com.sap.eso.api.doc.collaboration.*; 
import com.sap.eso.api.common.log.Logger;
import java.math.BigDecimal;
import java.util.*;
import com.sap.eso.api.doccommon.masterdata.*;
import com.sap.eso.api.common.exception.*;
import com.sap.eso.api.ibean.IBeanIfc;
import com.sap.eso.api.ibean.IBeanHomeIfc;
import com.sap.eso.api.doccommon.doc.contract.ContractDocumentIBeanIfc;
import com.sap.eso.api.contracts.*;
import com.sap.eso.api.usermgmt.masterdata.*;
import com.sap.eso.api.common.types.*;
import com.sap.eso.api.ibean.*;
import java.text.SimpleDateFormat; 
import com.sap.eso.api.doccommon.masterdata.ValueListValueIBeanIfc.*;
import com.sap.odp.api.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.File;
import java.net.*;
import com.sap.eso.api.doccommon.doc.contract.ContractDocumentIBeanIfc;
import com.sap.eso.api.common.platform.IapiSessionContextIfc;
import com.sap.eso.api.common.platform.IapiDbHandleIfc;
import com.sap.eso.api.common.types.SimpleObjectReferenceIfc;
import com.sap.eso.api.common.types.*;
import com.sap.odp.api.common.log.Logger;


// Logger


logMsg = Logger.createLogMessage(session);


import com.sap.api.common.types.AttachmentIfc; 
import com.sap.odp.common.types.Attachment;


//import com.sap.eso.api.common.types.AttachmentIfc; 
//import com.sap.eso.odp.common.types.Attachment;


import com.sap.eso.api.doccommon.doc.contract.DocumentVersionIBeanIfc;
import com.sap.eso.api.common.platform.IapiDbHandleIfc;
import java.io.*;
import java.io.File;
import com.sap.eso.api.ibean.AssociativeCollectionIfc;
File file = null;
BufferedWriter output = null;


try
{
contractsColl=doc.getContractDocuments();
for(Iterator iterator1 = contractsColl.iterator(); iterator1.hasNext();)
{
ContractDocumentIBeanIfc contractDocument = (ContractDocumentIBeanIfc)iterator1.next();
docVersions = contractDocument.getDocVersions();
topDocVersion = docVersions.get(0);
attachment = topDocVersion.getDoc();//type AttachmentIfc
displayName = attachment.getDisplayName();
fileData = attachment.getFileData(session);


canonicalFilename = "/sourcing/inbound/materials/upload/"+displayName;
file = new File (canonicalFilename); 
logMsg.setLogMessage("downloaded_file" + canonicalFilename);




d = new DataInputStream(new FileInputStream(fileData));
out = new DataOutputStream(new FileOutputStream(file));


String count;
while((count = d.readLine()) != null){
System.out.println(count);
out.writeBytes(count);
}
d.close();
out.close();


}


}
catch (Exception e)
{
String err = e.toString();
System.out.println("File ERROR *** "+err);
logMsg.setLogMessage("Error_while_downloading_file" + err);


}
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • May 02 at 07:13 AM

    I think that first of all you use readline into a string to read the file but you write as bytes? You should be consistent with this. A pdf or ms word file should be considered as a binary file not a text file.

    Add comment
    10|10000 characters needed characters exceeded

  • May 02 at 05:48 PM

    Hi Erik,

    Thank you for your response. Can you tell me how to use string in the above code? Please modify this code and send it to me back.

    Add comment
    10|10000 characters needed characters exceeded