print.html 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <!-- Include nbinteract for interactive widgets -->
  2. <script src="https://printjs-4de6.kxcdn.com/print.min.js" async></script>
  3. <script>
  4. printContent = () => {
  5. // MathJax displays a second version of any math for assistive devices etc.
  6. // This prevents double-rendering in the PDF output.
  7. var ignoreAssistList = [];
  8. assistives = document.querySelectorAll('.MathJax_Display span.MJX_Assistive_MathML').forEach((element, index) => {
  9. var thisId = 'MathJax-assistive-' + index.toString();
  10. element.setAttribute('id', thisId);
  11. ignoreAssistList.push(thisId)
  12. });
  13. // Print the actual content object
  14. printJS({
  15. printable: 'textbook_content',
  16. type: 'html',
  17. css: "{{ site.css_url | relative_url }}/styles.css",
  18. scanStyles: false,
  19. targetStyles: ["*"],
  20. ignoreElements: ignoreAssistList
  21. })
  22. };
  23. initPrint = () => {
  24. document.querySelector('#interact-button-print').addEventListener('click', printContent)
  25. }
  26. initFunction(initPrint)
  27. </script>