DirectBrowserPrint Test Print

by musicreader

HTML

<script src="https://www.directbrowserprint.com/API/api.js"></script>
<h1>DirectBrowserPrint Test Print</h1>

    <div>
        <label for="fileInput">Select Files to Print:</label><br/>
        <input type="file" id="fileInput" multiple>
        <button id="printNow">
        PRINT
        </button>
    </div>

CSS

#fileInput{
  margin-top:10px;
}

#DirectBrowserPrint_Progress{
  position: absolute;
  z-index: 1000;
  left: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  background-color: black;
  color: white;
  text-align: center;
  padding: 10px;
}

JavaScript

const app_id = "MyTestApp";
const config_id = "Config1";

document.addEventListener('DOMContentLoaded', async (event) => {

					var url_script="https://www.directbrowserprint.com/API/pdf/pdf.js";
					var url_worker="https://www.directbrowserprint.com/API/pdf/pdf.worker.js";
					DirectBrowserPrintAPI.loadPDFJS(url_script,url_worker);

            document.getElementById('printNow').addEventListener('click', async () => {
                const fileInput = document.getElementById('fileInput');
                const files = fileInput.files;

                if (files.length > 0) {
                   DirectBrowserPrintAPI.printBlobs(app_id,config_id, files, "en");
                }
            });
            

        });