jsPDF
을 사용하여 HTML div를 pdf로 변환하려고합니다. 내 div에 나는 사용자가 직사각형, 선, 텍스트 등을 그릴 수있는 배경 이미지가있는 svg
파일을 가지고 있습니다. 드로잉에 d3.js
을 사용하고 있습니다. 지금은 PDF로 모든 도면과 함께 내 사업부를 저장하고 싶지만 단지 PDF로 내 텍스트를 변환. 내 JS 코드는SVG가있는 jsPDF를 통해 HTML Div를 PDF로 변환
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
);
}
이며, 그것은 밖으로 svg
드로잉 대신 내 image
및 텍스트의 PRINT AREA
를 인쇄 <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
CDN입니다.
그것은 내가 그것을 jsPDF
여부를 사용 가능한 위치를 지정 특정 informatin을하지 않았다 PDF 로 변환 할 내 샘플 사업부의 미리보기입니다.
이제 내 질문
는
jsPDF
또는 JS 다른 라이브러리를 사용하여 가능하다?가능하면 제게 제안 해주세요.
모든 종류의 도움을 받으실 수 있습니다. 감사.
해결 방법을 찾으셨습니까? –