Jump to content

UniHTMLFrame Print and export PDF


Alessandro

Recommended Posts

I have a procedure, and I create a run-time report using HTML and tags. When finish, I send into a uniHTMLFrame.

I want print the result of this frame, just that.

I know, can save HTML, but I want to print, and mainly export to PDF this content.

Link to comment
Share on other sites

Generate HTML code and write it into a temporary file inside ServerModule.LocalCache folder so UniGui will clear it out when session closes. Make sure to generate unique name if user are going to print several times during session. Then show user a link to the file with "target=_blank" parameter so it would open in a new browser tab. After that user can print html page himself, or you can insert javascript code inside generated html to call printing dialog automatically.

  • Upvote 1
Link to comment
Share on other sites

Add this to mainform.Script 

function PrintMe(DivID)
{
   var disp_setting="toolbar=yes,location=no,";
   disp_setting+="directories=yes,menubar=yes,";
   disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";
   var content_vlue = document.getElementById(DivID).innerHTML;
   var docprint=window.open("","",disp_setting);
  
   docprint.document.open();
   docprint.document.write('<!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Strict/EN"');
   docprint.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
   docprint.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">');
   docprint.document.write('<head><title>My Title</title>');
   docprint.document.write('<style type="text/css">body{ margin:0px;');
   docprint.document.write('font-family:verdana,Arial;color:#000;');
   docprint.document.write('font-family:Verdana, Geneva, sans-serif; font-size:12px;}');
   docprint.document.write('a{color:#000;text-decoration:none;} </style>');
   docprint.document.write('</head><body onLoad="self.print()"><center>');
   docprint.document.write(content_vlue);
   docprint.document.write('</center></body></html>');
   docprint.document.close();
   docprint.focus();
}

To print execute this code 

UniSession.AddJS('PrintMe('''+unihtmlframe1.jsname+'_id'')');
  • Upvote 1
Link to comment
Share on other sites

"window.open" is blocked in a lot of browsers, it is very unreliable in the modern web from my experience of dealing with users and their systems. That's why I prefer to show them a link which they click to open a new tab, this always works regardless of browser and device.

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...