Embed a Full HTML Document Inline Using Shadow DOM

James Moberg - Sep 18 - - Dev Community

We use ColdFusion/CFML to generate valid HTML documents for PDF generation using jsoup & WKHTMLTOPDF. If the generated HTML content is simply outputted onto an existing webpage, the webpage becomes invalid (due to double DOCTYPE "inception") and the website's global CSS styles will polluting the preview.

In order to view the final result correctly, the HTML document would have to be viewed independently within a new tab (using window.open or target="_blank") or embedded in an iFrame.

Another approach that we've been experimenting with uses the browser's shadow DOM. This has worked well for our needs so far, but is pretty specific... it generates a standalone shadow DOM and populates it with the content within an existing webpage so it can be more faithfully rendered without any interactivity. Our PDF & email previews are now rendered inline and are much easier to review.

Source Code

https://gist.github.com/JamoCA/0774f707e8b18b61bc95b5f2c39b1f9f

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player