首页 > 解决方案 > Unable to open dataurl using utils.openUrl()

问题描述

For Nativescript, I created a pdf using pdfmake on the client side. Now using its dataUrl, I want to display it in a browser. But while trying to open it using utils.openUrl(dataUrl), it gives error Error in OpenURL

pdfMake.createPdf(docDefinition)
  .getDataUrl((dataUrl) => {
      utils.openUrl(dataUrl);
  });

But if I paste dataUrl directly into browser address, it opens.

标签: nativescript

解决方案


getDataUrl(callback) returns a base64 data link which can not be handled by utils.openUrl(...). Moreover Android doesn't have the capability to open PDF in Browser.

The alternative is to write the PDF to a file and use nativescript-share-file for preview. This plugin gives user a list of options user could choose from to view / share the given file.


推荐阅读