I am using a javascript code to annotate the pdf within the browser and after annnotating i am saving it to mydevice and then uploading it using another form.
but i want it be uploaded into the local storage of web page and then upload automatically to my upload.php
function printPDF() {
const printWindow = window.open('', '_blank');
const printDoc = printWindow.document;
for (let i = 0; i <= pdfDoc.numPages; i++) {
pdfDoc.getPage(i).then(page => {
const viewport = page.getViewport({ scale: 1.5 });
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = viewport.width;
canvas.height = viewport.height;
const renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext).promise.then(() => {
renderAnnotationsOnCanvas(context, i); // Render annotations on the canvas
const imageData = canvas.toDataURL();
printDoc.write('<img src="' + imageData + '" style="max-width: 100%;">');
if (i === pdfDoc.numPages) {
printDoc.close();
printWindow.onload = function () {
printWindow.print();
printWindow.close();
};
}
});
});
}
}
this is output window we get after the print pdf get trigger this just an example:
This is my java script code to save the the annotated pdf