Jump to content

UniHTMLFrame Print and export PDF


Alessandro

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...