2017-03-03 10 views
1

jspdfとautotable.src.jsを使用してボタンをクリックするとPDFを生成するスクリプトに現在の日付を追加します。私は....日付を追加する必要があります

<script> 

    function generate() { 
    // header 

    var doc = new jsPDF('l', 'pt'); 

    <?php include 'imgData.php';?> 

    doc.addImage(imgData, 'JPEG', 40, 20, 60, 60); 
     // xy coords width height 

    doc.text(107, 58, "Movies"); 

    // ADD DATE HERE 

    var m_names = new Array("January", "February", "March", 
          "April", "May", "June", "July", 
          "August", "September", 
          "October", "November", "December"); 

    var today = new Date(); 
    var curr_date = today.getDate(); 
    var curr_month = today.getMonth(); 
    var curr_year = today.getFullYear(); 

    today = m_names[curr_month] + " " + curr_date + ", " + curr_year; 
    var newdat = today; 

    doc.setFontType("italic"); 
    doc.setFontSize(10); 

    doc.text(107, 74, newdat); 

    // DATE END 

    // data 
    var res = doc.autoTableHtmlToJson(document.getElementById("movie")); 

    // footer 
    var totalPagesExp = "{total_pages_count_string}"; 

    var footer = function (data) { 
    var str = "Page " + data.pageCount; 

    if (typeof doc.putTotalPages === 'function') { 
     str = str + " of " + totalPagesExp + " - The Movie Connection (LTD) "; 
    } 
    doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 30); 
    }; 

    // options 
    var options = { 
     headerStyles: { 
     //fillColor: [104, 163, 194], 
     valign: 'middle', 
     rowHeight: 28, 
     fontSize: 11 
     }, 

     bodyStyles: { 
     overflow: 'linebreak', // visible, hidden, ellipsize or linebreak 
     columnWidth: 300, 
     rowHeight: 24 
     }, 

     afterPageContent: footer, 

     margin: { 
     top: 90 
     } 
    }; 

    doc.autoTable(res.columns, res.data, options); 

    // Total page number plugin only available in jspdf v1.0+ 
    if (typeof doc.putTotalPages === 'function') { 
    doc.putTotalPages(totalPagesExp); 
    } 

    doc.save("movies.pdf"); 
}; 

任意のアイデア右文書のタイトルの下に日付を追加したいですか?

+0

は私達にあなたの実際の問題が何であるかの詳細を与えることができますか? – sgelb

+0

jspdfによって作成されたpdfに現在の日付を追加する正解を持っています – Ronald

答えて

1

これをお試しください: -

var today = new Date(); 
var newdat = "Date Printed : "+ today; 
doc.text(107,68,newdat); 
+1

これは素晴らしい仕事でした - 私はスタイリングをいくつか追加しましたが、 – Ronald

関連する問題