在JSPDF中添加JS生成脚本

时间:2018-06-21 15:51:52

标签: javascript php html puzzle words

您好,stackoverflow的亲爱的成员。 首先,我要感谢您有可能在最大的技术网站上提问! 直截了当,我的问题与在PDF中添加Javascript单词拼图游戏的可能性有关。我的目标是将脚本包含在PDF中,以便用户下载并打印。

JAVASCRIPT代码为:

 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <script type="text/javascript" src="wordfind.js"></script> 
    <script type="text/javascript" src="wordfindgame.js"></script> 
    <script>
    /* Example words setup */
    [
        'testa',
        'testb',
        'testc',
        'testd',
        'teste',
    ].map(word => WordFindGame.insertWordBefore($('#add-word').parent(), word));
    $('#secret-word').val('LAETITIA');

    /* Init */
    function recreate() {
        $('#result-message').removeClass();
        var fillBlanks, game;
        if ($('#extra-letters').val() === 'none') {
            fillBlanks = false;
        } else if ($('#extra-letters').val().startsWith('secret-word')) {
            fillBlanks = $('#secret-word').val();
        }
        try {
            game = new WordFindGame('#puzzle', {
                allowedMissingWords: +$('#allowed-missing-words').val(),
                maxGridGrowth: +$('#max-grid-growth').val(),
                fillBlanks: fillBlanks,
                allowExtraBlanks: ['none', 'secret-word-plus-blanks'].includes($('#extra-letters').val()),
                maxAttempts: 100,
            });
        } catch (error) {
            $('#result-message').text(`😞 ${error}, try to specify less ones`).css({color: 'red'});
            return;
        }
        wordfind.print(game);
        if (window.game) {
            var emptySquaresCount = WordFindGame.emptySquaresCount();
            $('#result-message').text(`😃 ${emptySquaresCount ? 'but there are empty squares' : ''}`).css({color: ''});
        }
        window.game = game;
    }
    recreate();

    /* Event listeners */
    $('#extra-letters').change((evt) => $('#secret-word').prop('disabled', !evt.target.value.startsWith('secret-word')));

    $('#add-word').click( () => WordFindGame.insertWordBefore($('#add-word').parent()));

    $('#create-grid').click(recreate);

    $('#solve').click(() => game.solve());
    </script>

JSPDF脚本是:

<script>
function script() {
    // Default export is a4 paper, portrait, using milimeters for units
var doc = new jsPDF()
var imgData ='data:image/png;base64,here goes the base64 link but it's too long and it doesn't make any sense to show it.'
<?Php
?>
doc.setFont("helvetica");
doc.setFontType("bold");
doc.addImage(imgData, 'PNG', 5, 5, 100, 50);
doc.setFont("times");
doc.setFontType("normal");
doc.text(200, 35, 'text text text text', null, null, 'right');
doc.text(200, 42, 'text text text text', null, null, 'right');
doc.save('<?php echo ''.strftime('%F').''; echo ''.$_SESSION['username'].'';?>.pdf')

};

document.getElementById('link').onclick = function () {
    script();
};

快速说明:我想使用JSPDF在pdf中显示生成的单词拼图。

感谢您对我的帮助!

0 个答案:

没有答案