[英]How to print an specific div?
I'm currently working on a project using tools from ESRI, specifically with WebAppBuilder https://doc.arcgis.com/es/web-appbuilder/ .我目前正在使用 ESRI 的工具开展一个项目,特别是 WebAppBuilder https://doc.arcgis.com/es/web-appbuilder/ 。 We have some sort of dashboard already made, this is how it looks like:我们已经制作了某种仪表板,它是这样的:
I need to make a report of what's currently in the dashboard, so i have to take the panels and the map, and rearrange it to make a pdf file out of it.我需要报告仪表板中当前的内容,因此我必须取出面板和地图,然后重新排列以制作一个 pdf 文件。
I've already try using a css class but it doesn't work because i have little control over what's on the dashboard, so I can't assign a class to what i want to print or rearrange it.我已经尝试使用 css 类,但它不起作用,因为我对仪表板上的内容几乎没有控制,所以我无法将一个类分配给我想要打印或重新排列的内容。
I've try to select the element with something like我尝试用类似的东西选择元素
const printContent = document.getElementById("report-container").outerHTML;
const originalContent = document.body.innerHTML;
document.body.innerHTML = printContent;
window.print();
document.body.innerHTML = originalContent;
But it doesn't work either, it doesn't show the panels and when i came back the dashboard goes crazy.但它也不起作用,它不显示面板,当我回来时,仪表板发疯了。
So, I'm out of ideas.所以,我没有想法。 I need someway to grab the div, rearrange them and print them.我需要某种方式来抓取 div,重新排列它们并打印它们。
If there is a class that is shared among every panel, you can use document.querySelectorAll(".{whatever panel class name is}")
如果有一个在每个面板之间共享的类,您可以使用document.querySelectorAll(".{whatever panel class name is}")
if such class exists, this will give you NodeList with all the elements that have that class name.如果存在这样的类,这将为您提供包含具有该类名称的所有元素的 NodeList。
You can assign the display:none
css property temporarily to remove the elements from the print result and after reset the display property to the original value您可以临时分配display:none
css 属性以从打印结果中删除元素,然后将 display 属性重置为原始值
es document.getElementById(ID).style.display = “none”;
es document.getElementById(ID).style.display = “none”;
If you need to print the elements in different position you need to create the appropriate html and make it visibile only for print by @media print
media query如果您需要在不同的位置打印元素,您需要创建适当的 html 并使其仅在@media print
媒体查询时可见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.