Skip to Content
Technical Articles
Author's profile photo Ming Kho

Use NPM JavaScript library to generate PDF in MDK app

As an app developer, we always look to make use of vast collection of existing JavaScript libraries to enhance our application. So, I want to use this blog post to help you to achieve that with SAP Mobile Development Kit app.

SAP Mobile Development Kit, which is using NativeScript framework, supports basically any JavaScript library which is based on CommonJS spec. But because NativeScript framework is not DOM based and does not support any browser-APIs, for those JavaScript libraries that have DOM dependencies or any other browser-API dependencies, we need to do additional work to get these libraries to work with MDK app.

To guide you on this, we have now added a new MDK Showcase app: PDF Generation App, which will demonstrate how you can include NPM Javascript library into your application and then consume and use them in your MDK application via JavaScript rule.

In this showcase app, we will include and use pdfmake library to generate PDF document based on the data that user selected in the app.

Here is what the generated PDF looks like:

In Android:

Android PDF Screenshot

In iOS:

iOS PDF Screenshot


Do note that this showcase app is currently only meant for mobile platform, however, we will look into enhance it to support web in the future.

With this showcase app, you will learn how to include and use a CommonJS based JavaScript Library via NPM in your MDK app.

We will create more blog posts like this to introduce showcase app that helps you learn to make the best use of MDK to develop your app.

If you have any feedback or thoughts, please do add them in the comment section.

If you have any questions about MDK in general, please do check out the Q&A in the mobile development kit SAP Community and post any questions.

This app is made available under the SAP Sample Code license, which essentially means it is provided as-is, no warranties. Feel free to grab and reuse the portions of the app that seem useful to you.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Francisco José Carrasco Valverde
      Francisco José Carrasco Valverde

      Ming Kho Is it possible create my own client with Cloud Build Service in order to use the NPM plugin to generate the PDF ?

      I have created a client wtih Could Build Service type Customised Mobile Development Kit Client and include the following line in MDKProject.json in MDK Project ZIP file this:

      "Externals": ["pdfmake/build/pdfmake"],

      However, my feeling is this is not enough because my app is not working when I deploy my app with this line in a rule:

      import * as pdfMake from "pdfmake/build/pdfmake";



      Author's profile photo Francisco José Carrasco Valverde
      Francisco José Carrasco Valverde

      I got the answer :