Home >Web Front-end >CSS Tutorial >How to Preserve CSS Styling When Saving Syntax Highlighter Pre Element as a PDF?
How to Save a Syntax-Highlighter Pre Element as a PDF Preserving CSS Styling
To save a syntax highlighter pre element as a PDF while maintaining the CSS, consider this alternative approach:
Solution:
jQuery Implementation:
<code class="javascript">$("#save").click(function() { var text = $("#output")[0].outerHTML; var styles = $("style")[0].outerHTML; var popup = window.open("", "popup"); popup.document.body.innerHTML = text + styles; popup.focus(); popup.print(); });</code>
Demonstration:
You can see this solution in action at the following jsfiddle: http://jsfiddle.net/tn04Ldka/2/
The above is the detailed content of How to Preserve CSS Styling When Saving Syntax Highlighter Pre Element as a PDF?. For more information, please follow other related articles on the PHP Chinese website!