保存pdf回复

时间:2016-05-09 12:33:39

标签: javascript jquery ajax node.js node-pdfkit

我正在尝试保存node.js服务器发送的pdf文件。 Pdf是用pdfkit创建的。 这是回复的日志:

    {"readyState":4,"responseText":"%PDF-1.3\n%����\n5 0 obj\n<<\n/Type /Page\n/Parent 1 0 R\n/MediaBox [0 0 612 792]\n/Contents 3 0 R\n/Resources 4 0 R\n>>\nendobj\n4 0 obj\n<<\n/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n>>\nendobj\n10 0 obj\n<<\n/Type /ExtGState\n/ca 1\n>>\nendobj\n8 0 obj\n<<\n/Type /Page\n/Parent 1 0 R\n/MediaBox [0 0 612 792]\n/Contents 6 0 R\n/Resources 7 0 R\n>>\nendobj\n7 0 obj\n<<\n/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n/Font <<\n/F1 9 0 R\n>>\n/ExtGState <<\n/Gs1 10 0 R\n>>\n>>\nendobj\n14 0 obj\n<<\n/S /URI\n/URI (http://google.com/)\n>>\nendobj\n15 0 obj\n<<\n/Subtype /Link\n/A 14 0 R\n/Type /Annot\n/Rect [100 665 260 692]\n/Border [0 0 0]\n>>\nendobj\n13 0 obj\n<<\n/Type /Page\n/Parent 1 0 R\n/MediaBox [0 0 612 792]\n/Contents 11 0 R\n/Resources 12 0 R\n/Annots [15 0 R]\n>>\nendobj\n12 0 obj\n<<\n/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]\n/ExtGState <<\n/Gs1 10 0 R\n>>\n/Font <<\n/F1 9 0 R\n>>\n>>\nendobj\n16 0 obj\n<<\n/Producer (PDFKit)\n/Creator (PDFKit)\n/CreationDate (D:20160409123048Z)\n>>\nendobj\n9 0 obj\n<<\n/Type /Font\n/BaseFont /Helvetica\n/Subtype /Type1\n/Encoding /WinAnsiEncoding\n>>\nendobj\n2 0 obj\n<<\n/Type /Catalog\n/Pages 1 0 R\n>>\nendobj\n1 0 obj\n<<\n/Type /Pages\n/Count 3\n/Kids [5 0 R 8 0 R 13 0 R]\n>>\nendobj\n3 0 obj\n<<\n/Length 23\n/Filter /FlateDecode\n>>\nstream\nx�3T0\u0000B]C ani����\u0005\u0000\u001dI\u0003\\\nendstream\nendobj\n11 0 obj\n<<\n/Length 117\n/Filter /FlateDecode\n>>\nstream\nx�e�A\n\u00021\u0010\u0004�����f&n&\u0006d\u000f��g%/p����\u0004|��Y�.\n�\u0016b�J\u001c�D�\u0017¾}\u001e���D��[��-\bs\u0017�w�!��B�I���D��p\u0014�n7솭�\u001c5E֒7N��\u0016mz�2R}�Pq�\u0017Zg\u001ep\nendstream\nendobj\n6 0 obj\n<<\n/Length 152\n/Filter /FlateDecode\n>>\nstream\nx�e�A\n�@\fE�9E.`�d:�\u0005qQԮ����#�\u0015���͸p#\u001f��O�Frm؇��y�\u0017��7$`\"T�\u001a��&hO��T`�m5�h\u0014�ނ�\u0005-:��T�\u0006봘�����t���A��=�;\u001c\u0013�k�Gp$\\�$N\u000f�\u001f���}��e\u001c0��c#^p�OhǕ��B�\u000f-�,�\nendstream\nendobj\nxref\n0 17\n0000000000 65535 f \n0000001091 00000 n \n0000001042 00000 n \n0000001161 00000 n \n0000000119 00000 n \n0000000015 00000 n \n0000001445 00000 n \n0000000335 00000 n \n0000000231 00000 n \n0000000945 00000 n \n0000000186 00000 n \n0000001255 00000 n \n0000000733 00000 n \n0000000609 00000 n \n0000000453 00000 n \n0000000509 00000 n \n0000000852 00000 n \ntrailer\n<<\n/Size 17\n/Root 2 0 R\n/Info 16 0 R\n>>\nstartxref\n1669\n%%EOF\n","status":200,"statusText":"OK"}

这是我的客户代码:

var data = {};
data.azione = "getEtichettaProdotto";

//Scarico i dati anagrafica
$.ajax({
    type: 'POST',
    data: JSON.stringify(data),
    contentType: 'application/json',
    url: 'http://46.101.209.16/endpoint',                       
    complete : function(etichettas) {
        console.log(JSON.stringify(etichettas));

        var blob = new Blob([etichettas.responseText], {type: "application/pdf"});
        saveAs(blob, "Label.pdf");
    }//SUCCESS
});

和我的node.js代码:

    PDFDocument = require('pdfkit');

function creaEtichetta(req, res){
    doc = new PDFDocument
        size: 'a4'
        bufferPages: true


    doc.pipe(res);
    doc.addPage().fontSize(25).text('Here is some vector graphics...', 100, 100);

    doc.save()
   .moveTo(100, 150)
   .lineTo(100, 250)
   .lineTo(200, 250)
   .fill("#FF3300");

   doc.addPage().fillColor("blue").text('Here is a link!', 100, 100).link(100, 100, 160, 27, 'http://google.com/')

    doc.end();
}
exports.creaEtichetta = creaEtic
请帮忙,我试了一个星期。 抱歉英语不好,我是意大利人。

0 个答案:

没有答案