70002236 How to calculate the produced image size of printToImageData function

Article 70002236
Type HowTo
Product WebJS
Version 9
Date Added 6/29/2022 12:00:00 AM
Fixed 10.1002.0.1 (6/29/2022 12:00:00 AM)
Submitted by VectorDraw Team


How to calculate the produced image size of printToImageData function


On WebControl in order to print the content we use the prinToImageData() function where we pass the paper size and the resolution on DPI and this function returns an array of bytes which later we pass it to an HTLM5 canvas element and create a compressed png file.
So the size of the bytes that the function returns, depends on the resolution that we pass, but also on the paper size. For example if we pass an A4 paper dimensions and 100 resolution and an A3 paper size with the same 100 resolution, the bytes of the A3 paper size will be much more.

For example if we use an A4 paper size which is [830, 1170], /* paper size in inch x 100 */ with resolution 400, it will be 8.30 * 400 (horizontal) * 11.7* 400(vertical) * 4 (bytes each pixel(rgba)) = 3320pixels * 4680pixels * 4 bytes = 62.000.000 bytes.
Note that a safe limit for most of the devices and smartphones and X32 browsers is to be less than 65.000.000 bytes.

So we suggest to check the size of the array that prinToImageData() function returns and if it is more than 65.000.000 bytes lower down the resolution or the paper size because it has to do with the browser how much memory that can handle and also for each device.

Send comments on this topic.