test.ashx
<%@ WebHandler Language="C#" Class="API20261030090400" %>
// 注意,檔案編碼必須為 UTF-8-BOM
using System;
using System.Collections.Generic; // Dictionary
using System.IO;
using System.Web;
using System.Web.Script.Serialization; // JavaScriptSerializer
public class API20261030090400 : IHttpHandler
{
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType="application/json; charset=utf-8";
JavaScriptSerializer oJSS=new JavaScriptSerializer();
Dictionary<string, object> oOutput=new Dictionary<string, object>();
oOutput["booSuccess"]=true;
oOutput["strErrorMessage"]="";
try
{
string strInput="";
using (StreamReader oSR=new StreamReader(context.Request.InputStream)) { strInput=oSR.ReadToEnd(); }
Dictionary<string, object> oInput=oJSS.Deserialize<Dictionary<string, object>>(strInput);
oOutput["oInput"]=oInput;
string[] straFullPath=Directory.GetFiles(context.Server.MapPath("~/text"));
Array.Sort(straFullPath);
Array.Reverse(straFullPath);
List<string> lstFile=new List<string>();
List<string> lstContent=new List<string>();
for(int i=0; i<straFullPath.Length; i++)
{
string strFullPath=straFullPath[i];
lstFile.Add(Path.GetFileName(strFullPath));
lstContent.Add(File.ReadAllText(strFullPath));
}
string[] straFile=lstFile.ToArray();
string[] straContent=lstContent.ToArray();
oOutput["straFile"]=straFile;
oOutput["straContent"]=straContent;
}
catch (Exception oE)
{
context.Response.StatusCode=500;
oOutput["booSuccess"]=false;
oOutput["strErrorMessage"]=HttpUtility.JavaScriptStringEncode(oE.Message);
}
finally
{
string strOutput=oJSS.Serialize(oOutput);
context.Response.Write(strOutput);
}
}
}
// 若要偵錯時,記得在網站根目錄的 web.config 加入 system.web 區塊
//
// <?xml version="1.0" encoding="UTF-8"?>
// <configuration>
//
// <system.web>
// <customErrors mode="Off" />
// <compilation debug="true" />
// </system.web>
//
// <system.webServer>
// <httpErrors>
// <remove statusCode="404" subStatusCode="-1" />
// <error statusCode="404" prefixLanguageFilePath="" path="/404.htm" responseMode="ExecuteURL" />
// </httpErrors>
// </system.webServer>
//
// </configuration>
//
test.htm
<!doctype html>
<html lang="zh-Hant-TW">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>your title</title>
</head>
<body>
<script>
window.addEventListener(
"load",
async function()
{
while(true)
{
try
{
var oResponse=await fetch(
"test.ashx",
{
method: "POST",
headers: { "Content-Type": "application/json; charset=UTF-8" },
body: JSON.stringify({"strUsername":"john", "strPassword":"123"})
}
);
var strJson=await oResponse.text();
var oJson=JSON.parse(strJson);
console.log(oJson);
}
catch(oError)
{
console.log({ "oResponse":oResponse, "strJson":strJson, "oError":oError });
alert((oResponse.url+"\n"+oResponse.status+"\n"+oResponse.statusText)+"\n\n"+strJson+"\r\n"+(oError.toString()));
break;
}
break;
}
}
);
</script>
</body>
</html>
ICH eCTD 3.2.2 + TFDA eCTD-R2.1 xml 示意檔案
EPSON TM-T70II 熱感式印表機,用 javascript 列印,還可切一刀。
首先用 EpsonNet Config 程式,將印表機的 ip 設定好。
然後從瀏覽器登入 http://192.168.1.x/ 帳密可能是 epson/epson 或 空白/SN 或 epson/SN ~
到 Configuration/Network/ePOS-Print 頁籤
Enable ePOS-Print 功能,然後 Send
函數庫可到原廠下載
https://download-center.epson.com/softwares/?device_id=TM-T70II&os=IOS&language=zh-TW®ion=TW
請下載 Epson ePOS SDK for JavaScript
解壓縮之後,請抓出 epos-2.27.0.js
製作一個 html 程式類似下面這樣。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>epson test</title>
<script src="epos-2.27.0.js"></script>
</head>
<body>
<div>
<img id="imgLotusFlower" src="test.jpg">
<canvas id="myCanvas" style="display: none;"></canvas>
</div>
<div>
<button onclick="printTest()">測試列印</button>
</div>
<div id="divResult"></div>
<script>
var oCanvas=null, oCtx=null;
window.addEventListener(
"load",
async function()
{
var oImg = document.getElementById("imgLotusFlower");
oCanvas=document.getElementById("myCanvas");
oCanvas.setAttribute("width", 400);
oCanvas.setAttribute("height", 400);
oCtx=oCanvas.getContext("2d");
oCtx.drawImage(oImg, 0, 0, oImg.width, oImg.height, 0, 0, 400, 400);
}
);
function printTest()
{
let oBuilder=new epson.ePOSBuilder();
oBuilder.addTextLang("zh-tw");
oBuilder.addTextSize(2, 2); // 寬兩倍,高兩倍
oBuilder.addText("test00013\n");
oBuilder.addTextAlign(oBuilder.ALIGN_RIGHT);
oBuilder.addText("電子發票證明聯\n");
oBuilder.addTextAlign(oBuilder.ALIGN_CENTER);
oBuilder.addText("置中\n");
oBuilder.addTextAlign(oBuilder.ALIGN_LEFT);
oBuilder.addText("電子發票證明聯補印\n");
oBuilder.addTextSize(1, 2); // 寬一倍,高兩倍
oBuilder.addText("盛雲藥品股份有限公司\n");
oBuilder.addTextSize(1, 1);
oBuilder.addText("一");
oBuilder.addTextPosition(100); // 100 dots
oBuilder.addText("有移動嗎?\n");
oBuilder.addText("項二耶");
oBuilder.addTextPosition(100); // 100 dots
oBuilder.addText("有對齊嗎\n");
oBuilder.addBarcode("4711234567890",oBuilder.BARCODE_EAN13,oBuilder.HRI_BELOW,oBuilder.FONT_A,2,60);
oBuilder.addText("\n");
oBuilder.addBarcode("123456789012",oBuilder.BARCODE_CODE39,oBuilder.HRI_NONE,oBuilder.FONT_A,2,60); // HRI_BELOW / HRI_NONE
oBuilder.addText("\n");
oBuilder.addSymbol("https://www.macro.com.tw",oBuilder.SYMBOL_QRCODE_MODEL_2,oBuilder.LEVEL_M,6,0);
oBuilder.addText("\n");
oBuilder.addCut(oBuilder.CUT_FEED);
oBuilder.addImage(oCtx, 0, 0, 400, 400); // 400 dots x 400 dots
oBuilder.addCut(oBuilder.CUT_FEED); // 切紙
let strRequest=oBuilder.toString();
var oEPOS=new epson.ePOSPrint("http://192.168.1.71/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000");
oEPOS.onreceive=function(oResult)
{
if (oResult.success) { document.getElementById("divResult").innerHTML="列印成功"; }
else { document.getElementById("divResult").innerHTML="列印失敗"; }
};
oEPOS.send(strRequest);
}
</script>
</body>
</html>