I loved your work. But I don't understand how can I use this properly.
I'm tryng to use this on react but I don't know how can I pass the div ID of what I want to save.
Can you help me ?
This is my code so far(I have a PDF converter too):
`import React, {Component} from 'react';
import { FormattedMessage } from 'react-intl';
import messages from './messages';
import NavBar from 'components/NavBar';
import VerticalNav from 'components/VerticalNav';
import htmlDocx from 'html-docx-js/dist/html-docx';
import { saveAs } from 'file-saver';
export default class PDF extends React.Component { // eslint-disable-line react/prefer-stateless-function
// HTML TO PDF
pdfToHTML(){
var pdf = new jsPDF('p', 'pt', 'letter');
var source = $('#HTMLtoPDF')[0];
var specialElementHandlers = {
'#bypassme': function(element, renderer) {
return true
}
};
var margins = {
top: 50,
left: 60,
width: 545
};
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.save('html2pdf.pdf');
}
)
}
//HTML TO DOCX
docxToHTML(){
var content = htmlDocx.asBlob(content)
saveAs(content, 'test.docx')
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam scelerisque porta velit vitae mattis. Curabitur vel lorem sed diam condimentum congue. Nulla et sapien enim.
Hi,
I loved your work. But I don't understand how can I use this properly.
I'm tryng to use this on react but I don't know how can I pass the div ID of what I want to save.
Can you help me ?
This is my code so far(I have a PDF converter too): `import React, {Component} from 'react'; import { FormattedMessage } from 'react-intl'; import messages from './messages'; import NavBar from 'components/NavBar'; import VerticalNav from 'components/VerticalNav'; import htmlDocx from 'html-docx-js/dist/html-docx'; import { saveAs } from 'file-saver';
export default class PDF extends React.Component { // eslint-disable-line react/prefer-stateless-function
constructor(props){ super(props); this.pdfToHTML = this.pdfToHTML.bind(this); this.docxToHTML = this.docxToHTML.bind(this); this.state = { } }
// HTML TO PDF pdfToHTML(){ var pdf = new jsPDF('p', 'pt', 'letter'); var source = $('#HTMLtoPDF')[0]; var specialElementHandlers = { '#bypassme': function(element, renderer) { return true } };
}
//HTML TO DOCX docxToHTML(){ var content = htmlDocx.asBlob(content) saveAs(content, 'test.docx') }
render() { return (
Versão A
Prova de Geografia 3º ano EF1
Nome: _____________________________________________
Turma: ______________
Data: ____________________________
Instruções:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam scelerisque porta velit vitae mattis. Curabitur vel lorem sed diam condimentum congue. Nulla et sapien enim.
Perguntas
Pergunta de teste
Alternativa 1
Alternativa 2
Alternativa 3
Alternativa 4
} } `