I have an generated a html page as a string which is stored in a variable (let's call it var htmlPage) I want to convert it to a pdf which I can later download
var htmlPage = '<!DOCTYPE html>\n'+
'<html lang="en" dir="ltr">\n'+
'<head>\n'+
'<meta charset="utf-8">\n'+
'<title></title>\n'+
'<style>\n'+
'.hyperlink{\n'+
'color: blue;\n'+
'cursor: pointer;\n'+
'}\n'+
'</style>\n'+
'</head>\n'+
'<body>\n'+
'<h1>Hello world!</h1>\n'+
'</body>\n'+
'</html>';
The way you want it is actually not possible. Alternate way is to write it in a div and hide the div, once the user clicks print, display the div and hide everything else before printing. Doing so the div you want to print will get printed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.