1

I created a function generated pdf that are using

   const pdfDocGenerator = pdfMake.createPdf(docDefinition);
    pdfDocGenerator.getBase64((pdfData) => {
      resolve({
        pdfData: `data:application/pdf;base64,${pdfData}`,
        onlyData: pdfData,
      });
    });

the code pdfDocGenerator.getBase64 saying its undefined but pdfDocGenerator is having a value.

my pdfDocGenerator console. enter image description here

can someone help with this Im using new promise inside of generatepdf file and there's an index file that calling the generatedpdf

enter image description here

added information enter image description here

what if I want created pdf and open with still not working blank enter image description here

CODE REPRODUCE: https://stackblitz.com/edit/react-gw7c3h?file=src%2FApp.js

9
  • what does createPdf look like? does it require an await? Commented Oct 27, 2021 at 4:06
  • I just follow the docs pdfmake.github.io/docs/0.1/getting-started/client-side/methods Commented Oct 27, 2021 at 4:17
  • I am suspecting if there is something wrong with the docDefinition object - perhaps it doesnt contain data expected by createPdf? you can try pdfmake.org/playground.html# to test simple code first as given in this example pdfmake.github.io/docs/0.1/getting-started/client-side/methods/… (using a sample docDefinition) and then replace with ur docDefinition (also, can u paste the text/JSON string of your docDefinition rather than the image (cant copy from the image) Commented Oct 27, 2021 at 4:35
  • Hi @gawkface I edit the information, I can send all the json file since that's to long content, But i try your suggestion still having the problem, I try to open the created pdf without doin the base 64 still having the problem. Commented Oct 27, 2021 at 4:53
  • 1
    I try pdfmake.org/playground.html# using the content, my data is right. will try to create a gist.github.com Commented Oct 27, 2021 at 4:59

1 Answer 1

2

I solved the problem by checking the console.logs error in that way you can check what is the content problem in my case I just import the

import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.vfs = pdfFonts.pdfMake.vfs;
Sign up to request clarification or add additional context in comments.

2 Comments

I kept seeing the Roboto fonts error too and that's why in my gist/playground you would see I included that too; but when you said you didnt see any console errors, I thought problem must have been something different. Anyway, its great that you finally solved it, you did well keeping at it for so long! You get to mark your own answer as the "Accepted solution"!
Thank you also @gawkface for getting solution done .. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.