Client-side printing

This topic explains the sample implementation of a print service that you can set up using the Applications Manager.

The following image and the procedure describe how to implement a print service:
Print Service
  1. Create a service definition to accept input from the user interface when the user chooses to print a document, say a receipt.
  2. Pass the input to an XSL translator to convert the input to an XML format such that it can be provided as input to an API. The sample code for the XSL translator is as follows:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:template match="Order">
    	 <Page PageNumber="1"  PageSize="4" PaginationStrategy="GENERIC" Refresh="Y" >
               <API  Name="getOrderList" >
    		<Input>
    		   <Order>
    		   <xsl:attribute name="CallingOrganizationCode">
    							<xsl:value-of select="@OrganizationCode" />
    						</xsl:attribute>
                        </Order>
    		 </Input>  
    		   <Template>
    		     <OrderList>
    			   <Order OrderNo='' >
    			     <OverallTotals GrandTotal=''/>
    				</Order> 
    			 </OrderList>
    		   </Template>
    		 </API> 
             </Page>		 
     </xsl:template>
    </xsl:stylesheet> 
    In this sample code, the output of XSL translator is passed to the getPage API, which internally calls the getOrderList API.
  3. Pass the output of the API to an XSL translator to convert the output to HTML format. The sample code for the translator is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" encoding="UTF-8" indent="yes"></xsl:output>
    	<xsl:template match="/">
    	 <html>
    	  <Strong>Order List For Matrix</Strong>
    	    <body>
    	    <style>
    		table, th, td {
    		    border: 1px solid black;
    		}
    		th, td {
    		    padding: 5px;
    		    text-align: left;
    		}
    		</style>
    		</body>
    
    	    <xsl:apply-templates select="Page/Output/OrderList" />
    	     <xsl:apply-templates select="Page/Output/OrderList/Order" />
    	     </html>
    	    </xsl:template>
    
    	     <xsl:template match="Page/Output/OrderList"> 
    		    <table>
    			<thead>
    				<tr>
    					<th>OrderNo</th>
    					<th>Order Price</th>
    				</tr>
    			</thead>
    			<xsl:for-each select="Order">
                    <tr>
    				    <td class="header-font">
    					<xsl:value-of select="@OrderNo" />
    				    </td>
    					<td>
    						<xsl:value-of select="OverallTotals/@GrandTotal" />
    					</td>
    				</tr>
    				</xsl:for-each>
    				</table>
    		    </xsl:template>
    </xsl:stylesheet>
  4. Pass the HTML output to an XSL translator to convert it into a format accepted by the iscPrint service, to show the print preview dialog on the browser.

Sample implementation

You can refer the sample files in <wscdev.war>/ngstore/store/views/samples/ folder for better understanding of the iscPrint service.