如何将Jspdf文件保存到特定文件夹中

问题描述 投票:0回答:1

我正在使用jspdf生成pdf。它可以工作,但是文件已下载到“下载”文件夹。但是我想下载特定的文件夹,例如((localhost / ccs / ccs / invoice“)文件夹路径,以保存生成的文件pdf。如何解决更改我的代码的问题。我的示例代码是

<div class="invoice" id="customers"  ng-repeat="aim in input">
<div align="right"><h1 align="right"><b>INVOICE</b> </h1></div>
<table>
    <tr>
        <td>
            Hello
        </td>
        <td>
            Hi
        </td>
    </tr>
</table>
</div>
 <button onclick="javascript:demoFromHTML();">PDF</button>

我的脚本代码是

<script>
function demoFromHTML() {
    var pdf = new jsPDF('p', 'pt', 'letter');
    // source can be HTML-formatted string, or a reference
    // to an actual DOM element from which the text will be scraped.       
    source = $('#customers')[0];

    // we support special element handlers. Register them with jQuery-style 
    // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
    // There is no support for any other type of selectors 
    // (class, of compound) at this time.
    specialElementHandlers = {
        // element with id of "bypass" - jQuery style selector
        '#bypassme': function (element, renderer) {
            // true = "handled elsewhere, bypass text extraction"
            return true
        }
    };

    margins = {
        top: 80,
        bottom: 60,
        left: 40,
        width: 522
    };
    // all coords and widths are in jsPDF instance's declared units
    // 'inches' in this case
    pdf.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, {// y coord
                'width': margins.width, // max width of content on PDF
                'elementHandlers': specialElementHandlers
            },
    function (dispose) {
        // dispose: object with X, Y of the last line add to the PDF 
        //          this allow the insertion of new lines after html
        pdf.save('Invoice.pdf');
    }, margins);
}
</script>
<script type="text/javascript" src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js">   </script>

谢谢。

jspdf
1个回答
0
投票

您可以将'FileSaver.js'与jspdf.js一起使用,它将帮助您将pdf保存到特定的文件夹中,无论您喜欢什么。

var pdf =  new jsPDF();

// your code here to write something in to pdf.

pdf.save(fileName);
© www.soinside.com 2019 - 2024. All rights reserved.