Embed a Full HTML Document Inline Using Shadow DOM
James Moberg

James Moberg @gamesover

About: I’m a ColdFusion/CFML web application developer at SunStar Media located in Monterey, CA. I am a fan of technology, music and web development.

Location:
Monterey, CA
Joined:
Aug 18, 2017

Embed a Full HTML Document Inline Using Shadow DOM

Publish Date: Sep 18 '24
0 0

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

Comments 0 total

    Add comment