Я пытаюсь конвертировать несколько HTML-страниц в PDF с помощью jsPDF. Вот пример кода,
pageOne.html
<body>
<div id="pageOneContent">
<h1> Welcome to page one</h1>
<p>
Discussion of a war memorial for Northampton began shortly after
the armistice in 1918, and from July 1919 a temporary wooden cenotaph
stood on Abington Street in the town centre. The Northamptonshire War
Memorial Committee commissioned Lutyens to design a permanent memorial.
The monument's design was completed and approved quickly, but its
installation was delayed by six years until the site could be purchased
from the Church of England, which required a faculty from the local
diocese. The memorial was finally unveiled on 11 November 1926 after
a service and a parade including local schoolchildren and civic
leaders.
</p>
<button onclick="secondPage.html">Next</button>
</div>
secondPage.html
<body>
<div id="pageTwoContent">
<h1> Welcome to second page</h1>
<p>
Northampton's memorial is one of the more elaborate town memorials in
England. It uses three features characteristic of Lutyens's war
memorials: a pair of obelisks, the Stone of Remembrance (which Lutyens
designed for the Imperial War Graves Commission), and painted stone
flags on the obelisks, which were rejected for his Cenotaph in London
but feature on several of his other memorials. Today it is a Grade I
listed building; it was upgraded from Grade II in 2015 when Lutyens's
war memorials were declared a "national collection" and all were
granted listed building status or had their listing renewed.
</p>
<button onclick="generatePDF();">Generate PDF</button>
</div>
script
function generatePDF(){
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
doc.fromHTML($("#pageOneContent").get(0), 15, 15, {
"width":170,
"elementHandlers": specialElementHandlers
});
doc.addPage()
doc.fromHTML($("#pageTwoContent").get(0), 15, 15, {
"width":170,
"elementHandlers": specialElementHandlers
});
doc.save("multiPagePDF.pdf");
}
Я попытался с примером кода, но когда я пытаюсь сгенерировать две страницы, генерируется только вторая страница, а первая страница пуста. Есть ли способ захватить обе страницы и создать в одном PDF. Существуют ли другие инструменты для создания PDF, кроме jsPDF, потому что я буду работать над более чем 40 HTML-страницами, которые нужно конвертировать в PDF.