Node.js: добавление SVG к определенной странице PDF от pdfmake - PullRequest
0 голосов
/ 10 сентября 2018

Я пытаюсь создать PDF-контент pdfmake . Тем не менее, pdfmake не поддерживает добавление SVG на v0.1.38. Поэтому я использую SVG-to-PDFKit для достижения этой цели. Вот мой код:

var printer = new pdfMakePrinter(fontDescriptors);

var doc = printer.createPdfKitDocument(pdfDoc);

SVGtoPDF(doc, s.data, s.x, s.y, s.options); // add this line for SVG-to-PDFKit to insert SVG while s contain SVG data

var chunks = [];
var result;

doc.on('data', function(chunk) {
    chunks.push(chunk);
});
doc.on('end', function() {
    result = Buffer.concat(chunks);
    resolve(result);
});
doc.end();

SVG успешно добавлен на последнюю страницу. Как добавить SVG на определенную страницу?

1 Ответ

0 голосов
/ 10 сентября 2018

После прочтения исходного кода и документа , добавление { bufferPages: true } полностью удовлетворит ваши потребности.

var printer = new pdfMakePrinter(fontDescriptors);

var doc = printer.createPdfKitDocument(pdfDoc, { bufferPages: true }); // magic here!
doc.switchToPage(x); // to page x, where x start from 0

SVGtoPDF(doc, s.data, s.x, s.y, s.options); // add this line for SVG-to-PDFKit to insert SVG while s contain SVG data

var chunks = [];
var result;

doc.on('data', function(chunk) {
    chunks.push(chunk);
});
doc.on('end', function() {
    result = Buffer.concat(chunks);
    resolve(result);
});
doc.end();
...