ARTICLES > Lotus notes

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(){
      var url="server_path/printVoucher";   // Agent name     
      var param="?OpenAgent&unid=_DOCUMENT_ID_";
      param=encodeURI(param);"GET", url+param, true);
      xmlHttp.onreadystatechange = callback_printVoucher;
function callback_printVoucher() {
     // Setting popup window
     // Set popup as center screen
     LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
     TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    if (xmlHttp.readyState == 4) {
           if (xmlHttp.status == 200) {
                  if (!myWindow.opener) {
                           myWindow.opener = self;

Step 2:
Create agent command script on Lotus notes

Option Public
Option Declare
Use "WEB Utility Library"
Use "Reimbursement Library"
Sub Initialize
Dim s As New NotesSession
Dim cdoc As NotesDocument
Set cdoc = s.Documentcontext
Dim form_sp,form_sp1 As Variant
'get QueryString
'get document ID from path
Dim db As NotesDatabase
Set db = s.Currentdatabase
Dim v As NotesView
'Notes View document lists
Set v = db.Getview("DOCBYUNIVERSALID")
Dim doc As NotesDocument
Set doc = v.Getdocumentbykey(form_sp1(1))
Dim Itemdc As NotesDocumentCollection
Set Itemdc = GetItemListInDoc(doc)
Dim i As Integer
Dim ErrorText As String
Dim NName As NotesName
Dim allDetail() As ExpenseData
Dim j As Integer, k As Integer, m As Integer
Dim advanceno As String, payee As String, logo As string
Dim Total As Double,Vat As Double,WHT As Double,GrandTotal As Double
Dim edoc As NotesDocument
Set edoc = Itemdc.GetFirstDocument
i = 1
j = 0
Total = 0
Vat = 0 
WHT = 0 
Grandtotal = 0
Print "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 tyle="text/css" media="print">
'Style sheet for printing
<!--[if lt IE 9]>
    <script src=""></script>
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+1
i = i+1
Set edoc = Itemdc.GetNextDocument(edoc)
Print "</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>
Print |</div></body></html>|
doc.IsPrinted = "1"
Exit Sub
ErrorText = "Error On Initialize In Print error:" + Error() + " On Code Line = " & CStr(Erl)
Print ErrorText
Exit Sub
End Sub
Step 3:
Testing and Enjoy work
Turn Back