Liquid UI - Documentation - 16.01 Convert word to pdf

16.01 Convert word to pdf


Prerequisites


Purpose

It is necessary to convert word files into PDF to maintain the document format consistent on various systems. In this article, you will learn how to convert a word file into a PDF in SAP. To achieve this, we’ll guide you through the following.

  1. Load wsoffice.dll file
  2. Add a function to show the file selection dialog from the user system
  3. Add a pushbutton to initiate the conversion process
  4. Add a function to convert the content of a word file to PDF format
 

User Interface

//Create this file inside your script folder for customizing the SAP Easy Access screen: zguixt.e0100.sjs
//Now, let's start adding the script to the above file and save it.

  1. Load the wsoffice

    Firstly, load the wsoffice file inside your script folder. Use the load command to add the wsoffice.dll file to ESESSION.sjs; this allows you to access the functions included in it.

    // wsoffice.dll is required to be installed
    load('wsoffice');
  2. Add a function to show the file selection dialog from the user system.
     
    // Function to Show File Selection Dialog
    function selectFileDialog(szPrompt) {  
        if(szPrompt==void 0)
            szPrompt = 'Select Valid Word Documnet';
        var dialog = new ActiveXObject('MsComDlg.CommonDialog');  
        dialog.Filter='All Files(*.*)|*.*';  
        dialog.MaxFileSize=32767;  
        dialog.DialogTitle=szPrompt;
        dialog.Flags=0x200|0x80000|0x800|0x4|0x200000  
        dialog.ShowOpen();  
        var ret = dialog.FileName;
        dialog = void 0;
        return ret;
    }
     
  3. Add a pushbutton Convert Word to PDF, click on this pushbutton will open a File Selection Dialog, as shown in the below image.
     
    // create a pushbutton "Convert Word to PDF"
    pushbutton([1,1], 'Convert Word to PDF','?',{'process':convertWordToPDF});

     
  4. Add a function to convert the content of the word file to PDF format.
     
    // Function to convert contents of word file to PDF Format
    function wordToPDF(wordFile, pdfFile) {
        myWord = new ActiveXObject('Word.Application');
    //    myWord.Visible = true;
        myWord.DisplayAlerts = 0;
        
        myDoc = myWord.Documents.Open(wordFile);
        
        var pdfFormat = 17;
        myDoc.SaveAs(pdfFile,pdfFormat);
        
        myDoc.Close();
        myWord.Quit();
        delete myWord;
    }


SAP Process

  1. Logon to SAP, and navigate to ZGUIXT transaction. Click on the pushbutton Convert Word to PDF displays a selection file dialog. Now, choose the desired word document and click on the open button, as shown in the below image.
     
     
  2. After converting the word file to PDF, it displays a success message as Successfully converted to PDF file, as shown below.
     
     

Can't find the answers you're looking for?