How can I print to PDF from an html document?
I would like to know if anyone can help me with the following:
I need to print in PDF format from an html document (it is being done for mobile device and for desktop). With Phonegap
or cordova
and ionic
The one I'm going to show here is by desktop with electron
This is the code I'm testing:
$scope.generar_pdf = function(){
html = $compile(angular.element('#cuerpocorreo'))($scope);
print_win = new BrowserWindow();
print_win.loadURL("data:text/html;charset=utf-8," + encodeURI(html[0].innerHTML));
print_win.webContents.on('did-finish-load', function() {
print_win.webContents.print();
});
print_win.on('closed', function() {
print_win = null;
});
$scope.borrar_historial();
}
This is how it should look:
What comes out when implementing the above code:
In advance I thank the help that they can give me.
3
2 answers
An alternative could be to use mPDF, which I used.
I have here an example of how to implement it using PHP.
Update:
Searching the internet I found this similar question in English: https://stackoverflow.com/questions/9818093/how-to-print-html-to-pdf
Where they suggest another 2 options:
1
Author: Jorgesys, 2017-05-23 12:39:20