<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ruben Ruvalcaba</title>
    <description>The latest articles on DEV Community by Ruben Ruvalcaba (@rubenruvalcabac).</description>
    <link>https://dev.to/rubenruvalcabac</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F470417%2F1ea7fd08-db22-43f0-81df-38f4cd2f22a6.jpeg</url>
      <title>DEV Community: Ruben Ruvalcaba</title>
      <link>https://dev.to/rubenruvalcabac</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rubenruvalcabac"/>
    <language>en</language>
    <item>
      <title>Printing to TM-T88VI from an Azure Static App</title>
      <dc:creator>Ruben Ruvalcaba</dc:creator>
      <pubDate>Thu, 22 Jul 2021 20:00:59 +0000</pubDate>
      <link>https://dev.to/rubenruvalcabac/printing-to-tm-t88vi-from-an-azure-static-app-coh</link>
      <guid>https://dev.to/rubenruvalcabac/printing-to-tm-t88vi-from-an-azure-static-app-coh</guid>
      <description>&lt;p&gt;In my &lt;a href="https://dev.to/rubenruvalcabac/printing-tickets-on-reactjs-ki6"&gt;previous post&lt;/a&gt; explained how to print from a ReactJS using Epson POS SDK for JavaScript.&lt;/p&gt;

&lt;p&gt;I implemented it into my React application, tested it in my local environment and everything went pretty well. The problem was when I published as a Static Web Application in Azure. From the Azure environment, it didn't print. I checked at the console and found out the following error message:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vu01UGYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u30dh3ugsscl6j0vx907.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vu01UGYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u30dh3ugsscl6j0vx907.png" alt="Mixed Content: The page was loaded over HTTPS, but requested an insecure XMLHttpRequest "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This error only doesn't happen on my local environment because my application was running over HTTP. Once it's published on Azure, now my application is loaded over HTTPS and the printer address call is through HTTP. This mixed content is not allowed by Chrome, nor any other modern browser (I tried on Safari, Edge and Firefox). &lt;/p&gt;

&lt;p&gt;Googling the error message I've found the post &lt;a href="https://stackoverflow.com/a/48700852/1167420"&gt;https://stackoverflow.com/a/48700852/1167420&lt;/a&gt; which suggest adding the following tag to the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"Content-Security-Policy"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"upgrade-insecure-requests"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This directive will replace any HTTP request into an HTTP URL. It make sense, so I added the directive in the &lt;code&gt;index.html&lt;/code&gt; file in the HEAD element:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jo9bGf5O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jszl91w5nb3807x3ejhz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jo9bGf5O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jszl91w5nb3807x3ejhz.png" alt="Content-Security-Policy in index.html"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I published again and it made it work, now the SDK url is through HTTPS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IFnpplr---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abj7zvllcjvgqirp32sy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IFnpplr---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abj7zvllcjvgqirp32sy.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the problem is the printer certificate (the factory default) is invalid:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fdo4lUKW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fz0ygxo3njntrby3ow0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fdo4lUKW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fz0ygxo3njntrby3ow0.png" alt="ERR_CERT_INVALID"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I needed to regenerate the certificate and install it on the printer.&lt;/p&gt;

&lt;p&gt;I've created the new certificate using the TM-T88VI Utility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Go to Network/Detailed Settings/Certificate.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deleted the current certificate.&lt;/li&gt;
&lt;li&gt;Click on "Self-signed certificate" button.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tIejOa9B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nrksu8wbmmqig3og42x8.png" alt="image"&gt;
Enter in "Common Name" field the printer IP (make sure the printer has a static IP address).
Click "Ok" then "Set", this will create the new self-signed certificate and push it to the printer.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to Network/Detailed Settings/SSL/TLS option and make sure to have the following settings:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B8evLi1N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0bo6i3s9lfdakb1y8bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B8evLi1N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0bo6i3s9lfdakb1y8bt.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have a valid certificate installed in the printer, you should be able to print, but as the browser still untrusts the certificate. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P414S3x9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amr7meig1bl67qf7f6hd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P414S3x9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amr7meig1bl67qf7f6hd.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can trust on certificate for this session, clicking on "Advanced" button, and continue:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dKJDepdG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgv0sagidyi3h58wmlrt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dKJDepdG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgv0sagidyi3h58wmlrt.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But for a permanent trust you'll need to install the certificate in your computer/device. To do so, you'll need to export the certificate, you can do this from the browser, clicking on the certificate window: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--836i2CcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eap145iu37c002pdgitn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--836i2CcZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eap145iu37c002pdgitn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In Windows, go to details tab and clic on "Copy to File..." button, select "DER encoded binary X.590 (.CER)" format and select the destination for the exported file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In MacOs, drag the certificate image to your desktop or any folder&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally needed to install the certificate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In windows, on start menu type "Manage computer certificates", select the "Trusted Root Certification Authorities" branch, then "All Tasks" and "Import..." and import the exported certificate.&lt;/li&gt;
&lt;li&gt;In MacOs double click on the downloaded certificate, and in the keychain manager clic on "Trust" button.&lt;/li&gt;
&lt;li&gt;In Android, copy the certificate to the device and open it. It'll ask for your credentials, type the printer's IP as the certificate name and select the "VPN and apps" option.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>azure</category>
      <category>react</category>
      <category>printing</category>
    </item>
    <item>
      <title>Printing tickets on ReactJS</title>
      <dc:creator>Ruben Ruvalcaba</dc:creator>
      <pubDate>Fri, 25 Jun 2021 19:01:19 +0000</pubDate>
      <link>https://dev.to/rubenruvalcabac/printing-tickets-on-reactjs-ki6</link>
      <guid>https://dev.to/rubenruvalcabac/printing-tickets-on-reactjs-ki6</guid>
      <description>&lt;h2&gt;
  
  
  Epson ePOS SDK with React JS
&lt;/h2&gt;

&lt;p&gt;Project repository: &lt;a href="https://github.com/rubenruvalcabac/epson-epos-sdk-react" rel="noopener noreferrer"&gt;https://github.com/rubenruvalcabac/epson-epos-sdk-react&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Printing from React JS in Epson thermal printer using the Epson ePOS SDK for Javascript.&lt;/p&gt;

&lt;p&gt;Printing from a web app looks pretty straight forward, just call the &lt;code&gt;window.print()&lt;/code&gt; method, and that's it. But that approach has some drawbacks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You'll require to create a view of what you want to print (and/or use some printing specific CSS to achieve a proper presentation)&lt;/li&gt;
&lt;li&gt;It will show the user a print dialog, which the user needs to complete in order to begin the printing&lt;/li&gt;
&lt;li&gt;The printing will be a graphical representation of the page&lt;/li&gt;
&lt;li&gt;The client device must have installed the printer drivers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For many scenarios, the above is not so bad. But in a high demand environment (like in a POS application) each one is a drawback that becomes a very important affection to performance and productivity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requiring a printer view, could distract the user or loose the current information they're working with.&lt;/li&gt;
&lt;li&gt;Showing the printer dialog demands user extra actions and slows the process of getting the printing.&lt;/li&gt;
&lt;li&gt;Printing graphical demands more network traffic, the printing is slower and doesn't get the maximum printer speed. Raw printing is what POS printers are build for max performance.&lt;/li&gt;
&lt;li&gt;Requiring an installed driver on the client device, is a huge challenge for mobile users and limits application adoption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, the &lt;strong&gt;goals&lt;/strong&gt; for this project are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Print without changing what the users is looking at. Print on background, automatically and without showing any dialog.&lt;/li&gt;
&lt;li&gt;Print raw to reach the maximum printer performance and reduce network traffic.&lt;/li&gt;
&lt;li&gt;Don't need any installed printer driver, and use network connection to the printer, so don't need to phisically connect the device to the printer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Epson ePOS SDK for JavaScript
&lt;/h2&gt;

&lt;p&gt;This SDK provides a communication solution between JS and the printer, for a wide number of POS printers models. My solution is based on using this SDK.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download the SDK: &lt;a href="https://download.epson-biz.com/modules/pos/index.php?page=single_soft&amp;amp;cid=6679&amp;amp;scat=57&amp;amp;pcat=52" rel="noopener noreferrer"&gt;https://download.epson-biz.com/modules/pos/index.php?page=single_soft&amp;amp;cid=6679&amp;amp;scat=57&amp;amp;pcat=52&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unzip the SDK and copy the &lt;code&gt;epos-2.17.0.js&lt;/code&gt; file to your project under the &lt;code&gt;public&lt;/code&gt; folder.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiy55udce1lnwz3zw3wg5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiy55udce1lnwz3zw3wg5.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reference the script&lt;br&gt;
As the SDK is not designed to be used on strict mode, to be included in a React app, need to be referenced on &lt;code&gt;public/index.html&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fykkmxw6nqlzzjrawdzhd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fykkmxw6nqlzzjrawdzhd.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Printing
&lt;/h2&gt;

&lt;p&gt;Printing to a network printer is like anyother communication processs, connect to the device and send the requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect to the printer
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;connect&lt;/code&gt; function opens the connection with the printer and keeps it open for further printing.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ePosDev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;epson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ePOSDevice&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br&gt;
&lt;span class="nx"&gt;ePosDevice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ePosDev&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="nx"&gt;ePosDev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;printerIPAddress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;printerPort&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="nx"&gt;ePosDev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createDevice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;local_printer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
      &lt;span class="nx"&gt;ePosDev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DEVICE_TYPE_PRINTER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;devobj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;retcode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;retcode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
          &lt;span class="nx"&gt;printer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;devobj&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
          &lt;span class="nf"&gt;setConnectionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;STATUS_CONNECTED&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
          &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;retcode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;br&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;});&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Send information to the printer&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Once the connection to the printer is open, just have to send what you want to print. The &lt;code&gt;print&lt;/code&gt; function does it:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;print&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;prn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;printer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Not connected to printer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addFeedLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addCut&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CUT_FEED&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="nx"&gt;prn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;};&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Design your ticket&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;The SDK provides a lot of methods (&lt;code&gt;addText&lt;/code&gt;, &lt;code&gt;addFeedLine&lt;/code&gt;, etc.) to print and use the printer capabilities. &lt;a href="https://reference.epson-biz.com/modules/ref_epos_sdk_js_en/index.php?content_id=1#BHIDAHEE" rel="noopener noreferrer"&gt;Here you can check the available SDK methods &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The easier way to design your ticket is using the SDK included designer. In the SDK folder just navigate to the &lt;code&gt;/ReceiptDesigner/index.en.html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe55qxhblsjosk55fdmfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe55qxhblsjosk55fdmfs.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the 'Edit' tab you can add commands to build your format, and on the 'API' tab you'll get the code to print the format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi8993afcuze7t4s009h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi8993afcuze7t4s009h.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can get the code from the &lt;code&gt;print()&lt;/code&gt; method.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>printing</category>
      <category>pos</category>
    </item>
  </channel>
</rss>
