How can I fill up the paper during printing? Is it possible to fill the entire page with this image?

Viewed 67

I am using html2canvas to capture a div on my Calendar and open the image on a new window,then print it. But on the print preview,the image is not filling up the paper.There are always blanks up, down, left and right, I want it to fill the page.

This is set to "Fit to page width": enter image description here And scale 100% is worse: enter image description here Here is my code:

function printCalendar(){
    
            var printMaxWidth = "1420px";
            var printMaxHeight = "890px";
            //Create the option to open a window
            var option = 'width=' + printMaxWidth + ',height=' + printMaxHeight;
            var calendartPrintWindow = window.open("", "", option); 
            
            //Open the document of the window
            calendartPrintWindow.document.open();

            //Html2canvas
            html2canvas(document.querySelector("#calendarContainer")).then(canvas => {
                //Insert the created html document inside it 
                calendartPrintWindow.document.write('<img src="'+canvas.toDataURL()+'"/>');
                //Close the document the window
                calendartPrintWindow.document.close();
                //Print
                setTimeout(function(){calendartPrintWindow.print();},100);}); 
     }

"Fit to page width" looks good but it will be great when the image can fill the entire page.Is there and Ideas?Thanks.

0 Answers
Related