Print a pop-up as PDF

2126
2
Jump to solution
11-23-2021 04:18 PM
RyanBohan
Occasional Contributor III

I am working on a simple webpage to allow the printing of a pop up as a pdf.  Currently loading an existing webmap as we have many existing projects we would like to add printing to.  I am new to javascript so I am sure there is are better ways.

Currently I am using the following to get the pop-up information
var popUpTitle = document.querySelector(".esri-popup__header-container--button").innerHTML
var popUpContents = document.querySelector(".esri-popup__content").innerHTML

And passing that to a new window, it works pretty well only I am losing the colored bands to help keep everything to read.  Which is not huge but someone will want it.

RyanBohan_0-1637712240124.png

RyanBohan_1-1637712274486.png

To view my code in code pen https://codepen.io/rbohan/pen/mdMZbdp

0 Kudos
1 Solution

Accepted Solutions
IhabHassan
Esri Contributor

Hi @RyanBohan 

you will need to inject the required styling to the constructed HTML code. I would suggest not to use ESRI css file, because it will be huge for just a print page for the popup.

sample code to inject the css file link:

 document.getElementById("of head/body tag")
.innerHTML += '<link rel="stylesheet" type="text/css" href="style.css">';
Regards
Ihab

View solution in original post

2 Replies
IhabHassan
Esri Contributor

Hi @RyanBohan 

you will need to inject the required styling to the constructed HTML code. I would suggest not to use ESRI css file, because it will be huge for just a print page for the popup.

sample code to inject the css file link:

 document.getElementById("of head/body tag")
.innerHTML += '<link rel="stylesheet" type="text/css" href="style.css">';
Regards
Ihab
RyanBohan
Occasional Contributor III

Always great to be able to click the accept as solutions button.  Thank you @IhabHassan I think this is what I needed.  I am sure your correct that is likely overkill to use esri css file, we are still exploring how this will be used.  

//doc.write(divText);
doc.write(divText + '<link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css" />'); 

RyanBohan_0-1637780924789.png