8

私はこのjsコードを持っています:

var doc = new jsPDF();

$('#pdf_new').click(function(){
    var html=$(".wrap_all").html();
    doc.fromHTML(html,200,200, {
        'width': 500,
    });
    doc.save("Test.pdf");
});

htmlには、次のようなコードがあります:

<div class = 'wrap_all'>
    <div id = 'wrap_odd'> <div id = ''>....</div> </div>

    <div id = 'wrap_even'> <div id = ''>....</div> </div>
</div>

何も機能しません...コンソールが私に戻ります:

#wrap_odd未定義のプロパティを読み取れません"

(PS私の英語でごめんなさい)

4

3 に答える 3

13

「fromHTML」を使用して、JSPDF を使用して作成している PDF の HTML からテキストを取得する場合、不要な< div >をレンダリングするelementHandler関数が必要です。

JSPDF@GitHubのに示されているのと同じパターンに従ってみてください。

最終コードは次のようになります。

var doc = 新しい jsPDF();

    var specialElementHandlers = {
      'レンダリングされる DIV ': function(element, renderer){
       true を返します。
    }
    };


    $('#pdf_new').click(関数(){
      var html=$(".wrap_all").html();
         doc.fromHTML(html,200,200, {
            '幅': 500,
            「elementHandlers」: specialElementHandlers
         });
      doc.save("Test.pdf");
    });
于 2014-04-10T15:13:27.867 に答える
4

これを確認してください..これはコンテンツ全体を表示します

     <head>
        <script src="https://code.jquery.com/jquery-git.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>
<script type="text/javascript">
        $(window).on('load', function () {
            var doc = new jsPDF();
            var specialElementHandlers = {
                '#editor': function (element, renderer) {
                    return true;
                }
            };
            $('#pdfview').click(function () {
                doc.fromHTML($('#pdfdiv').html(), 15, 15, {
                    'width': 100,
                    'elementHandlers': specialElementHandlers
                });
                doc.save('file.pdf');
            });
        });
    </script>
    </head>
     <div id="pdfdiv">
                <h3 style="color:green;">WWW.SANWEBCORNER.COM</h3>
                <img src="404.png">
                <p>A newspaper acts an important medium to control corruption and scams. The chief topics of general interest in newspaper includes politics, social issues, sports, economy, movies, and share market.

    Newspaper is a mode of mass communication. It is very helpful in creating social awareness. Newspaper raises voices against social issues such as child labor, dowry system, etc. They urge the common people to act and behave in a rational manner.

    We get the information of the forthcoming movies and television shows through a newspaper. It also contains a list of multiplexes with time-schedule for the movies.

    A wide coverage of information is obtained at low cost though newspaper. It also influences the habit of thinking in men. It has also seen that illiterate adults are taking up education to read newspaper.

    There are such dailies that trade on such dirty tricks for survival. Being politically left or right, they misrepresent strikes and lockouts. Events like bank robbery and train accident or similar untoward events are distorted or exaggerated. They deliberately make their news sensational because it appeals to the less educated and less cultured more directly.

    The dignity and reputation of a newspaper rests on the degree of their fidelity to truth and fearless reporting. It is our cheapest and most powerful weapon in the last analysis.</p>
            </div>
            <div id="editor"></div>
            <button id="pdfview">Download PDF</button>
于 2016-08-12T06:37:46.750 に答える
0

注意点:印刷可能な要素コンテナ内の要素の配置に注意してください!

jsPDF は、要素が適切であることに非常に敏感であるかのようです。これには画像とリンクが含まれます。

于 2016-11-11T01:10:29.693 に答える