In the scenario of a syntax highlighter that offers the option to save highlighted code as a PDF, maintaining the CSS styling is crucial to preserve the aesthetics and functionality of the highlighted code.
To save a pre element as a PDF while maintaining its CSS styles, consider the following approach:
$("#save").click(function() {
var text = $("#output")[0].outerHTML;
// retrieve and append `style` element, or define inline styling
var styles = $("style")[0].outerHTML;
var popup = window.open("", "popup");
popup.document.body.innerHTML = text styles;
popup.focus();
popup.print();
});
By implementing these techniques, you can effectively save pre elements as PDFs while preserving their CSS styling, allowing users to easily share and archive the highlighted code with accurate presentation.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3