Prerequisites
- Products: Liquid UI WS, Liquid UI Server or Local DLL, Client Software
- Commands: pushbutton(), load(), message()
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.
- Load wsoffice.dll file
- Add a function to show the file selection dialog from the user system
- Add a pushbutton to initiate the conversion process
- 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.
- 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'); - 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;
} - 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}); - 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
- 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.
- After converting the word file to PDF, it displays a success message as Successfully converted to PDF file, as shown below.