This topic is locked

Convert HTML to PDFmake.js format in PHP event

1/29/2021 9:24:29 AM
PHPRunner General questions
mbintex author

There is a Javascript module to convert HTML to the format of PDFmake.js here https://github.com/Aymkdn/html-to-pdfmake
I would need something similar, but for PHP. My current homebrew solution looks like this:

function HTMLconvert($html) {

return str_replace(

array("<p><img alt=\"\" src=\"data:image/png;base64,","\" /></p>",

"<p>&nbsp;</p>","<p>","</p>","<br />","
",

"<ol>","</ol>",

"<ul>","</ul>",

"<li>","</li>",

"<i>","</i>",

"<em>","</em>",

"<b>","</b>",

"<strong>","</strong>",

"<u>","</u>",

"'","&nbsp;",

"&Auml;","&Ouml;","&Uuml;",

"&auml;","&ouml;","&uuml;","&szlig;",

"&euro;","&lt;","&gt;",

"&amp;","&sect;","&sup2;","&sup3;"),

array(

"']},{image: 'data:image/png;base64,",

"'},{text: ['",

"\\n\\n']},{style:'standard', text: [' ",

"",

"\\n']},{style:'standard', text: ['",

"\\n']},{style:'standard', text: ['",

"\\n']},{style:'standard', text: ['",

"']},{ol:[",

"]},{text: ['",

"']},{ul:[",

"]},{text: ['",

"'",

"',",

"',{text: '",

"', italics: true},'",

"',{text: '",

"', italics: true},'",

"',{text: '",

"', bold: true},'",

"',{text: '",

"', bold: true},'",

"',{text: '",

"', decoration: 'underline'},'",

"\"",

" ",

"Ä",

"Ö",

"Ü",

"ä",

"ö",

"ü",

"ss",

"Euro",

"<",

">",

"&",

"§",

"²",

"³"

),$html);

}


But I guess the pros could do much better. Especially I have no solution for font sizes with varying sizes, font colors and inline styles like width and height for images. All spans are ignored too.
Could anybody help?