Я пытаюсь преобразовать html div в pdf, используя jsPDF
. В моем div у меня есть файл svg
с фоновым изображением, где пользователь может рисовать прямоугольник, линию, текст и т. Д. Я использую d3.js
для рисования. Теперь я хочу сохранить свой div со всеми чертежами в pdf, но это только преобразование моего текста в pdf. Мой JS кодПреобразование HTML Div в PDF через jsPDF с SVG
function htmlToPdf() {
console.log("--------------- with in 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 = $('svg.plancontainer')[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.autoPrint();
pdf.output('dataurlnewwindow');
}, margins
);
}
и является CDN <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
Он печати PRINT AREA
вместо моего image
и текст с из svg
рисунка.
Это предварительный мой образец DIV, что я хочу, чтобы преобразовать в PDF я не получил каких-либо конкретных informatin, задающие, где можно с помощью jsPDF
или нет.
Теперь мои вопросы
Можно ли с помощью
jsPDF
или любой другой JS библиотеки?Если возможно, не могли бы вы предложить мне?
Любые виды помощи приветствуются. Благодарю.
У вас есть решение на это? –