I am facing an issue with printing a Base64 file. Despite my efforts, the file does not print as expected.
function convertToBase64() {
var selectedFile = document.getElementById("inputFile").files;
if (selectedFile.length > 0) {
var fileToLoad = selectedFile[0];
var fileReader = new FileReader();
var base64;
fileReader.onload = function (fileLoadedEvent) {
base64 = fileLoadedEvent.target.result;
const pdfBlob = new Blob([base64], { type: "application/pdf" });
const url = URL.createObjectURL(pdfBlob);
printJS({
printable: url,
type: "pdf",
base64: true
});
};
fileReader.readAsDataURL(fileToLoad);
}
}
In this code snippet, I attempt to convert a selected PDF file into a Base64 format for printing purposes using Print.js. Unfortunately, I am encountering difficulties in making the printing process work correctly.