HEScript PrintPDF prints the whole page - print only from frame

Hi, I want to use the HEScript function PrintPDF, but it generates PDF of the whole webpage.


I want to use it to generate PDF of a specific iFrame on my webpage.

Basically, I am developing an application that has some settings on the left side and as the user changes them, the content in the right side iframe changes accordingly.

And finally the user can click “Save” and the script should generate PDF from only the iframe contents.

I tried running it from the iframe window like this:


But it still prints the whole page. I want contents from just the frame.

I also tried opening a new popup window:

var mywin = window.open(“https://heserver/files/preview.php”);

But is still prints the content from the main window, and not from the popup.

Also, I tried using standard print function:


This prints the contents from only target window as expected, but it has some issues:

  • It opens the "Select a printer" dialog, and then the "Save file" dialog.
  • I want to show only the Save file dialog, because I always generate PDF.
  • Moreover, when I select "Microsoft Print To PDF" as printer, the text in generated PDF is not select-able.
  • It is like I have generated the PDF from an image or something - the mouse pointer always shows the arrow and not the I as we see in the select-able text.

The PDF generated by HEScript’s PrintPDF works great for this - it correctly shows text as text, and I can select the text from PDF as expected.

I would really like to use HEScript PrintPDF function to generate PDF from a specified window.

Also I would avoid using external libraries such as fpdf etc., because my preview page has very complex HTML/CSS design that would be very difficult to use in external libraries.

Please help me on this as quickly as possible. Thanks.

In the incoming release, we’ve added better support for popups and there is a possibility to define which window you want to print.

Great to know that!
While I wait for the new version, I moved everything from preview.php into the main file and used some css hacks with media queries to hide the unwanted elements while printing.

Just for your info. The next release will offer a simple JavaScript command to export to PDF directly:
window.exportPDF(“path to file”)
Any popup or window will be able to be exported to PDF.

Nice, I hope this is in addition to window.exeoutput.RunHEScriptCode('PrintPDF'); because I need to show the Save File Dialog so that user can save the Current Window PDF wherever they like.

Sure, you can use HEScript to ask for a filename and then pass the filename to window.exportPDF