Printing on Lotus notes web agent Turn Back
2016-09-08 16:55:06
This is a technique used for printing documents on the browser for Lotusnotes Web application platform.
It uses javascript in through ajax function to run commands on lotusnotes script and return by print plain text with a Html header.
This may not be the best way. But it can be really easy.
Step 1:
Create a button for call the print function on your web page.
<button type="button" onclick="printVoucher()"> Print This Page </button>
Then press it. Run below function.
function createXMLHttpRequest() {if (window.ActiveXObject) {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}else if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest();}}function printVoucher(){createXMLHttpRequest();var url="server_path/printVoucher"; // Agent namevar param="?OpenAgent&unid=_DOCUMENT_ID_";param+="&rand="+Math.random(1);param=encodeURI(param);xmlHttp.open("GET", url+param, true);xmlHttp.onreadystatechange = callback_printVoucher;xmlHttp.send(null);}function callback_printVoucher() {// Setting popup windoww=960;h=600;// Set popup as center screenLeftPosition = (screen.width) ? (screen.width-w)/2 : 0;TopPosition = (screen.height) ? (screen.height-h)/2 : 0;if (xmlHttp.readyState == 4) {if (xmlHttp.status == 200) {var myWindow=window.open('','windowPrint','left='+LeftPosition+',top='+TopPosition+',width='+w+',height='+h+',scrollbars=yes,resizable=1');if (!myWindow.opener) {myWindow.opener = self;myWindow.focus();}myWindow.document.write(xmlHttp.responseText);myWindow.document.close();myWindow.print();}}}
Step 2:
Create agent command script on Lotus notes
Option PublicOption DeclareUse "WEB Utility Library"Use "Reimbursement Library"Sub InitializeDim s As New NotesSessionDim cdoc As NotesDocumentSet cdoc = s.DocumentcontextDim form_sp,form_sp1 As Variant'get QueryStringform_sp=Split(cdoc.Query_String_Decoded(0),"&")'get document ID from pathform_sp1=Split(form_sp(1),"=")Dim db As NotesDatabaseSet db = s.CurrentdatabaseDim v As NotesView'Notes View document listsSet v = db.Getview("DOCBYUNIVERSALID")Dim doc As NotesDocumentSet doc = v.Getdocumentbykey(form_sp1(1))Dim Itemdc As NotesDocumentCollectionSet Itemdc = GetItemListInDoc(doc)Dim i As IntegerDim ErrorText As StringDim NName As NotesNameDim allDetail() As ExpenseDataDim j As Integer, k As Integer, m As IntegerDim advanceno As String, payee As String, logo As stringDim Total As Double,Vat As Double,WHT As Double,GrandTotal As DoubleDim edoc As NotesDocumentSet edoc = Itemdc.GetFirstDocumenti = 1j = 0Total = 0Vat = 0WHT = 0Grandtotal = 0Print "Content-Type:text/plain"Print "Content-Type:text/html"Print |<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style tyle="text/css" media="all">'Style sheet for all</style><style tyle="text/css" media="print">'Style sheet for printing</style><!--[if lt IE 9]><script src="http://html5shiv-printshiv.googlecode.com/svn/trunk/html5shiv-printshiv.js"></script><![endif]-->|Print |</head>|Print |<body><div id="wrap">|Print "<h1>Riembursement</center></h1><h2>Payment Request Voucher</h2>"'Dim var As Variant'var = Evaluate(|@Text(@Year(@TextToTime(|+CStr(doc.DocNoDate(0))+|)))|,doc)Dim dt As New NotesDateTime(doc.DocNoDate(0))Print |<table class="tbMain" border="1" width="100%"><thead>|Print "<tr>"Print |<th width="8%">Index</th>|Print "<th>Partcular</th>"print |<th width="10%">Tax Invoice</th>|Print |<th width="10%">Currenty<br/>Total</th>|Print |<th width="10%">Vat</th>|Print |<th width="10%">Tax</th>|Print |<th width="10%">Net Amount</th>|Print "</tr></thead><tbody>"Do While Not(edoc Is Nothing)ReDim Preserve allDetail(j)Print |<tr valign="top">|Print "<td align=center>"+CStr(i)+"</td>"Print "<td>"+CStr(edoc.Description(0))+"</td>"Print |<td align=center>|+edoc.InvoiceNo(0)+|</td>|Print "<td align=right>"+CStr(Format(edoc.Total(0), "#,#0.00"))+"</td>"Print "<td align=right>"+CStr(Format(edoc.Vat(0), "#,#0.00"))+"</td>"Print "<td align=right>"+CStr(Format(edoc.WHT(0), "#,#0.00"))+"</td>"Print "<td align=right>"+CStr(Format(edoc.Grandtotal(0), "#,#0.00"))+"</td>"Print "</tr>"Total = Total + edoc.Total(0)Vat = Vat + edoc.Vat(0)WHT = WHT + edoc.WHT(0)Grandtotal = Grandtotal + edoc.Grandtotal(0)j = j+1i = i+1Set edoc = Itemdc.GetNextDocument(edoc)LoopPrint "</tbody></table>"Print |<center class="no-print"><button type="button" class="btn btn-success" onclick="window.print();">Print Report</button><button type="button" class="btn btn-danger" onClick="window.close()" >Close</button></center>|Print |</div></body></html>|doc.IsPrinted = "1"Call doc.save(True,True)Exit SubErrorHandler:ErrorText = "Error On Initialize In Print error:" + Error() + " On Code Line = " & CStr(Erl)Print ErrorTextExit SubEnd Sub
Step 3:
Testing and Enjoy work