相关文章推荐
坚强的伤疤  ·  python xlwings ...·  1 年前    · 
贪玩的西瓜  ·  javascript - How to ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have searched for a long time but nothing helps. I have two files header.php and other.php.

My header.php it looks like this:

..... </head> <header> ..... <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.0.0/jspdf.umd.min.js"></script> </header>

I require the header.php in other.php and want to use jsPDF in this file:

require "header.php";
</body>
<script>
    function createInvoice(final){
      const doc = new jsPDF();
      doc.text("Hello world!", 10, 10);
      doc.save("a4.pdf");
</script>

I tried with the script to include jsPDF in the body tag, in the head tag and over the script tag with the function, but every time I am getting the following error :

Uncaught ReferenceError: jsPDF is not defined

Can someone help me? Thank you in advance

In the new release, they changed the name of the global variable -> const { jsPDF } = window.jspdf.

<script>
    window.jsPDF = window.jspdf.jsPDF; // add this line of code
    function createInvoice(final){
        const doc = new jsPDF();
        doc.text("Hello world!", 10, 10);
        doc.save("a4.pdf");
</script>
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.