How to apply print CSS styles only for certain page/scene?

if someone is interested, here is the code that works:

$(document).on('knack-scene-render.any', function(event, scene) {
  try{
 document.getElementById("dynamicCSS").remove();
  }
  catch(err)
  {}
 if(scene.key=="scene_123")
 {
 var styles ='@media print {@page {size: 50mm 75mm;margin: 0;};#view_xxx .kn-detail-body {font-size:13px !important;padding-top:1em !important;}}';
 var styleSheet = document.createElement("style");
  styleSheet.id="dynamicCSS";
  styleSheet.textContent = styles
  document.head.appendChild(styleSheet)
 }
});
2 Likes