WIA Scan in the browser
URL: "http://localhost:8080"
Query scanner settings
Resource URI: [URL]/api/GetScannerParameters
Metod: POST
Description: Returns some scanner settings.
Headers Information
Content-Type: application/json;
Request Information
not necessary
(Body - raw - JSON)
{ "method":"GetScannerParameters", "sourceIndex": 0 }
Response Formats
{ "sources": { "selectedSource": "0", "sourcesList": [{ "key": "{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000", "value": "HP LaserJet MFP M28-M31 (USB)" }] }, "flatbedResolutions": [200,300,600], "pixelTypes": [ { "Id": 1, "Color": "Color", "Description": "Цветное" }, { "Id": 2, "Color": "Greyscale", "Description": "Оттенки серого" }, { "Id": 4, "Color": "BlackWhite", "Description": "Черно-белое" } ], "fileFormats": [ {"Name": "JPG"}, {"Name": "PNG"}, {"Name": "TIF"}, {"Name": "BMP"}, {"Name": "GIF"} ], "allowedFormats": [ { "Width": 8.27, "Height": 11.69, "Name": "A4" }, { "Width": 5.83, "Height": 8.27, "Name": "A5" }, { "Width": 8.27, "Height": 5.83, "Name": "A5 LS" }, { "Width": 4.13, "Height": 5.84, "Name": "A6" }, { "Width": 5.84, "Height": 4.13, "Name": "A6 LS" } ] }
Scanning
Resource URI: [URL]/api/Scan
Metod: POST
Description: Scanning and return image.
Headers Information
Content-Type: application/json;
Request Information
(Body - raw - JSON)
{ "method":"Scan", "source": "0", "dpi":"200", "ColorMode":4, "FFormat":"PNG", "PageFormat":{ "Width": 8.27, "Height": 5.83, "Name": "A5 LS" }, "Brightness":-400, "Contrast":0 }
Response Formats
Content-Type: image/[png,jpg,tif,bmp,gif]
blob:http:// ....
Sample JavaScript
//GetScannerParameters const url="http://localhost:8080/api/"; const postData = async (url = '', data = {}) => { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); return response.json(); }const jsonData = { "method": "GetScannerParameters", "sourceIndex": 0 }; postData(url + "GetScannerParameters", jsonData) .then((data) => { console.log(data); });
//Scanning const scanWIA = async (url = '', data = {}) => { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); return response; } var scanParam = { "method":"Scan", "source": "0", "dpi":"200", "ColorMode":4, "FFormat":"PNG", "PageFormat":{ "Width": 8.27, "Height": 5.83, "Name": "A5 LS" }, "Brightness":-400, "Contrast":0 }
//add div id ="Scanned" scanWIA(url + "Scan", scanParam) .then((data) => { let Scanned = document.getElementById("Scanned"); let img = document.createElement("IMG"); if (Scanned.children.length > 0) { Scanned.replaceChildren(); } data.blob().then(function (blob) { fileDate = blob; objectURL = URL.createObjectURL(fileDate); img.src = objectURL; Scanned.appendChild(img); }) });
// Save or ... // add button id="ButtonSave" // fileName - according to your request, change in the program var ButtSave = document.getElementById("ButtonSave"); ButtSave.addEventListener('click', SaveClick, false); function SaveClick() { let fileName = "file."+ scanParam.FFormat.toLowerCase(); ; let link = document.createElement('a'); link.download = fileName; link.href = URL.createObjectURL(fileDate); link.click(); URL.revokeObjectURL(link.href); }