Pdfmake: open pdfmake blob in pdf.js

Created on 17 Dec 2017  路  3Comments  路  Source: bpampuch/pdfmake

I want to display my generated pdf in pdf.js page , which I added to my project .
I use blob url of generated pdf to display it . but it has some troubles with IE .

can I have a better way to do that ?
I mean using some thing like this Data :

# option 1
var data;
pdfMake.createPdf(docDefinition).getDataUrl(function(dataURL) {
    data = dataURL;
});

# option 2 
var data;
pdfMake.createPdf(docDefinition).getBase64(function(encodedString) {
    data = encodedString;
});

# option 3
var data;
pdfMake.createPdf(docDefinition).getBuffer(function(buffer) {
    // turn buffer into blob
    data = buffer;
});

All 3 comments

You can use any of methods:

Depends on type/format that requires pdf.js for pdf file.

we have getDocument function in pdf.js which has src input :

function getDocument(src) {
  var task = new PDFDocumentLoadingTask();
  var source;
  if (typeof src === 'string') {
    source = { url: src };
  } else if ((0, _util.isArrayBuffer)(src)) {
    source = { data: src };
  } else if (src instanceof PDFDataRangeTransport) {
    source = { range: src };
  } else {
    if ((typeof src === 'undefined' ? 'undefined' : _typeof(src)) !== 'object') {
      throw new Error('Invalid parameter in getDocument, ' + 'need either Uint8Array, string or a parameter object');
    }
    if (!src.url && !src.data && !src.range) {
      throw new Error('Invalid parameter object: need either .data, .range or .url');
    }
    source = src;
  }
...
}

I think we can use getBuffer pdfmake method with getDocument pdf.js function and it will be do the job

I don't know. Is not related to pdfmake. Look at pdf.js documentation or ask pdf.js support.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CharlyPoppins picture CharlyPoppins  路  3Comments

MathLavallee picture MathLavallee  路  3Comments

imoum007 picture imoum007  路  3Comments

einfallstoll picture einfallstoll  路  3Comments

dgrice picture dgrice  路  3Comments