0
我有pdf的內容在字節數組。我想要一個客戶端的方式來打印這個pdf到本地打印機使用JS。 有可能嗎?如何使用JS將字節數組打印到本地機器打印機?
我有pdf的內容在字節數組。我想要一個客戶端的方式來打印這個pdf到本地打印機使用JS。 有可能嗎?如何使用JS將字節數組打印到本地機器打印機?
您需要在瀏覽器窗口中的Blob首先打開它,並調用打印功能
我沒有測試代碼,但hopfully它會工作
var byteArray = yourDocumentBytes;
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
// This will check if the browser is IE
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
var blob = new Blob(byteArray, { type: 'application/pdf' });
window.navigator.msSaveBlob(blob, documentName);
} else // If another browser
{
var element = document.createElement('a');
element.setAttribute('href', 'data:application/pdf;base64,' + encodeURIComponent(getBase64(byteArray)));
element.setAttribute('download', documentName);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// and call print function like this
window.print()