tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.21k stars 1.68k forks source link

dom content is not completely converted #366

Open kikyoluka opened 3 years ago

kikyoluka commented 3 years ago

Use case: description, code

I generated a lot of things in a div cycle that exceeded the height of the div, so I set overflow: automatically added a side scroll bar to display the excess content, like Figure 1 :image.pngHowever, when I use the toPng method to convert this div, it only converts the content of the div in the current scroll bar, and does not convert the remaining content that can be displayed through the scroll bar, as shown in Figure 2:image.png

This is my code for conversion:

print: function () {
      const node = this.$refs.list
      const images = this.$refs.img
      const BASE_DPI = 72
      const scale = window.devicePixelRatio
      toPng(node, {
        height: node.offsetHeight * scale,
        width: node.offsetWidth * scale,
        style: {
          transform: `scale(${scale})`,
          transformOrigin: 'top left',
          width: `${node.offsetWidth}px`,
          height: `${node.offsetHeight}px`
        }
      })
        .then((dataUrl) => {
          images.src = changeDpiDataUrl(dataUrl, BASE_DPI * scale)
          this.$print(images)
        })
    }

What should I do to make it convert the content of my entire div into a picture, thanks.

Expected behavior

Convert all the contents of node into PNG images and call the browser to print

Actual behavior (stack traces, console logs etc)

Only part of the node content is converted

Library version

^2.6.0

Browsers

xiaoxinshiwo commented 1 year ago

Refer to https://github.com/tsayen/dom-to-image/issues/183#issuecomment-468606593 It resolved my problem with scroll-Y, but with scroll-x, still fail to capture entire dom content.