javascriptiosreact-nativepdf-generationpdfmake

Unable to generate PDF in react native iOS app


I inherited a legacy react-native legacy application that runs on iOS and Android. There is one section of code that generates the PDF report which I pasted below. The code works perfectly fine in Android but it hangs in iOS app. Import functions :

import pdfmake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
const generatePdf = (docDefinition) =>
    new Promise((resolve, reject) => {
        try {
            const pdfDocGenerator = pdfmake.createPdf(docDefinition);
            pdfDocGenerator.getBase64((pdfData) => {
                resolve({
                    pdfBase64Data: `data:application/pdf;base64,${pdfData}`,
                    onlyData: pdfData,
                });
            });
        } catch (error) {      
            reject(error);
        }
    });

Since it works correctly in Android, one can assume that docDefinition has the correct value.
I printed the pdfDocGenerator which prints the object appropriately. Issue is pdfDocGenerator.getBase64((pdfData) never returns and it does not resolve to next level This happens only in iOS

package.json has below line "pdfmake": "^0.2.6", and i can see it installs 0.2.7 version

Code/project was developed by another team and Now im responsible for continuation of the project. the release version code works perfectly fine in both platform. But I cant make it work in project environment. Highly doubt on environment set up/ somehow the pdfmake library is not getting bundled in iOS.

rm -rf package-lock.json node_modules
rm -rf android/app/build
rm ios/Pods ios/Podfile.lock 
rm -rf ~/Library/Developer/Xcode/DerivedData
npm install && cd ios && pod update && cd ..

Solution

  • I found a similar issue reported in Github. Accordingly changing the pdfmake version 0.1.72 version solved my issue. question is it an ideal way to deal with it!?