Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert Docx to PDF and generate a new contract document version

Hi Experts,

     We try to convert the final contract document docx type conversion become pdf type,and then upload the file to generate a new contract document version.But we encountered the following problems:

     1.We use Jacob to do the type conversion,but the program at the time of new ActiveXComponent is not error termination,but in a server directly use Java operation is no problem.We do not konw the reason.

ActiveXComponent app = null;

        try {

           debugMessage = "Debug:chengxi4:start" ;

             logMsg(debugMessage);

            app = new ActiveXComponent("Word.Application");

           debugMessage = "Debug:chengxi4:new ActiveXComponent" ;

             logMsg(debugMessage);

            app.setProperty("Visible", false);

            Dispatch docs = app.getProperty("Documents").toDispatch();

            Dispatch doc = Dispatch.call(docs,//

                    "Open", //

                    docFilename,// FileName

                    false,// ConfirmConversions

                    true // ReadOnly

                    ).toDispatch();

     2.We use the following code to generate a new contract document version,but did not success.

public void addAtta(){

//1. get document version

        DocumentVersionIBeanImpl docVersionBean = (DocumentVersionIBeanImpl)doc.getDocVersions().get(0);

        //DocumentVersionIBeanImpl docVersionBean = null;

        //AssociativeCollectionIfc colli = doc.getDocVersions();

        //docVersionBean = (DocumentVersionIBeanImpl) colli.create();

//        AttachmentIfc attachment = docVersionBean.getDoc();

        //2.create empty New Attachment

        AttachmentIfc newAttachment= TypeFactory.createAttachment();

        //3. read file to inputstream

        InputStream is = null;

        try {

            is = new FileInputStream("E:\\usr\\sap\\deve_file\\0000449270.pdf");

        } catch (FileNotFoundException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        //4. get ParentObjectReference

        ParentObjectReferenceIfc parentRef = TypeFactory.createParentObjectReference(doc);

        //5. set context for new attachment

        newAttachment.setFileData("chengxi.pdf", is, parentRef, session);

        //6. set new version

        docVersionBean.setDoc(newAttachment);

    }

addAtta();

It only covers the last version of the file,and can not save this change.

Please help to answer the following code what the lack or what is wrong,and how to generate a new version of document in clm(SAP Sourcing) system and save.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question