Liquid UI - WS Reference Library

Automatically convert word to PDF


Purpose

Liquid UI: Converting Word to PDF.


User Interface

Created a Convert Word to PDF pushbutton to initiate the process from SAP Transaction. You can view a File Selection Dialog: Select File for PDF Conversion.


Successful PDF Conversion after file selection.


Liquid UI Script

//ESESSION.sjs

// wsoffice.dll is required to be installed
load('wsoffice');

//zguixt.e0100.sjs

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Author: Synactive, Inc. [1065 E. Hillsdale Blvd, Foster City, CA, 94404, USA]
// Email: support@guixt.com; sales@guixt.com;
// Contact: 650.341.3310
// Version: 1.0.0.0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 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;
}  

// User Interface
pushbutton([1,1], 'Convert Word to PDF','?',{'process':convertWordToPDF});

// Convert Word Document to PDF User Interface
function convertWordToPDF() {

    if(myWord == void 0) {
        wordFileName = selectFileDialog('Select Word File for PDF Conversion');
        
        if(wordFileName.length) {
            var wordFilePath = wordFileName.substr(0, wordFileName.lastIndexOf('\\'));
            var wordFileNameWithExtension = wordFileName.substr(wordFileName.lastIndexOf('\\'),wordFileName.length);
            var wordFileNameWithoutExtension = wordFileNameWithExtension.substr(0, wordFileNameWithExtension.lastIndexOf('.'));

            var PDFFileName = wordFilePath + wordFileNameWithoutExtension + '.pdf';
    
            wordToPDF(wordFileName,PDFFileName);
            message('S: Successfully Converted to PDF File: ' + PDFFileName);
        }
    }
}

// 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;
}