我正在使用jspdf库生成pdf文件,并且出现错误“未定义jspdf". [英] I am generating a pdf file using jspdf library and I am getting the error "jspdf is not defined"

查看:2333
本文介绍了我正在使用jspdf库生成pdf文件,并且出现错误“未定义jspdf".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试创建一个pdf文件,但收到错误消息未定义jspdf"

I am just trying to create a pdf file and I am getting the error "jspdf is not defined"

这是我的代码

<?php

        $doc = JFactory::getDocument();
        $doc->addScript(JUri::base() .'js/jquery-1.7.1.min.js',true);
        $doc->addScript(JUri::base() .'js/jspdf.debug.js',true);
        $doc->addScript(JUri::base() .'js/basic.js',true);
        $doc->addScript(JUri::base() .'js/png.js',true);
        $doc->addScript(JUri::base() .'js/png_support.js',true);
        $doc->addScript(JUri::base() .'js/zlib.js',true);
        $doc->addScript(JUri::base() .'js/FileSaver.js',true);
        $doc->addScript(JUri::base() .'js/tableExport.js',true);
        $doc->addScript(JUri::base() .'js/jquery.base64.js',true);
        $doc->addScript(JUri::base() .'js/html2canvas.js',true);
        $doc->addScript(JUri::base() .'js/standard_fonts_metrics.js',true);
        $doc->addScript(JUri::base() .'js/split_text_to_size.js',true);
        $doc->addScript(JUri::base() .'js/from_html.js',true);
    $script = "function loadtable(){
    var doc = new jsPDF();
    doc.text(20, 20, 'Hello world.');
    doc.save('Test.pdf');}";
    $doc->addScriptDeclaration($script);
    echo "<button id='buttonMU' class='gen_btn' onclick='loadtable()'>Load Pdf</button>";
    ?>

但是我确实在我的php代码中包含了javscript. 请告知.

But I do have the javscript included in my php code. Please advise.

推荐答案

检查输出页面的源代码.您可能在DOM完成加载之前就调用了javascript函数.

Check the source code of your output page. You're probably calling your javascript function before the DOM has finished loading.

尝试确保您的代码在页面加载后运行;

Try ensuring your code runs after the page has loaded;

object.onload=function(){myScript};

$script = "window.onload = function(){
    function loadtable(){
    var doc = new jsPDF();
    doc.text(20, 20, 'Hello world.');
    doc.save('Test.pdf');
}";

这篇关于我正在使用jspdf库生成pdf文件,并且出现错误“未定义jspdf".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆