Search code examples
javascripthtmlimagebmppdfmake

PDFmake "unknown image format" error


I'm trying to put a BMP image (encoded as a base64 string) into a PDF, however it is failing with the error Uncaught Error: Unknown image format. I know the image is formatted correctly because it loads in pure HTML correctly like so:

<img src="data:image/bmp;base64,THEIMAGEINBASE64">

JSFiddle of the HTML-only image here

But when loading into pdfmake like so:

var docDefinition = {
    content: [{
        image: 'data:image/bmp;base64,THEIMAGEINBASE64'
    }]
};
pdfMake.createPdf(docDefinition).download('my.pdf');

...it fails (JSFiddle here).


Solution

  • PDFMake only accepts JPEG and PNG