Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only renders what is on shown the screen and the result image is clipped #837

Closed
icakirlar opened this issue Mar 30, 2016 · 9 comments
Closed

Comments

@icakirlar
Copy link

This issue can be shown as a duplicate of previous issues #542, #511, #588, etc. However the problem is still open.

Html2canvas is successful when the bounds of the window is never changed and the target element is always %100 visible on the screen. However, this assumption is not always valid. When the bounds of the window is changed or scroll down/up operations only effects the bounds of the defaultView, but the dom structure remains the same after first initiation. In order to fix the problem I applied the following change in the source code and works fine for my case. Hope it can be placed in 0.5.0 release.

  • renderDocument expects the windowWidth and windowHeight values. But the actual values (core.js, line 44) refers to document.defaultView.innerWidth and document.defaultView.innerHeight values. If the size of the view changed, unless your element is a part of the actual document, rendering do not take into consideration of your whole element, it only renders the visible area. If you pass appropriate values, it renders the whole element without any problem.

if you call renderDocument( node.ownerDocument,
options,
options.innerWidth, //first width of the window when the document is created
options.innerHeight,//first heightof the window when the document is created
index )
like this it works properly.

@820fans
Copy link

820fans commented Apr 21, 2016

Great !!! I solved the problem after trying your method . Thank you !!

@Dayjo
Copy link

Dayjo commented Jun 7, 2016

@icakirlar awesome, been wondering if this was possible, often my users are using small browser windows and you end up with a cropped off image, when really you want the whole document area whether it's visible or not.

Any chance of making this a pull request?

@NPC
Copy link

NPC commented Jun 14, 2016

Hmm, for me this change (unless I did it incorrectly) renders elements that are partially off-screen as completely black, while top-level elements seem to render fine.

@Dayjo
Copy link

Dayjo commented Jun 16, 2016

I also have now tried this without success. Trying to make sure the entire 1024 x 576 element is rendered, (if it's clipped off the page / scrolled off the page, that is black) my code is as follows;

            var w = 232, h = 148; var self = this;
                return html2canvas(document.getElementById('da-page-canvas'), {
                    background: '#fff',
                    allowTaint: true,
                    useCORS: true,
                    page: this,
                    onclone: function(doc){
                        var canv = doc.getElementById('da-page-canvas');
                        canv.style.borderColor = 'transparent';
                        canv.className = "da-page-canvas da-screenshot";

                        var selected = doc.querySelectorAll('.ui-selected');
                        for ( var i =0; i< selected.length; i++ ) {
                            selected[i].classList.remove('ui-selected');
                        }
                    },
                    onrendered: function(canvas){
                        var url = canvas.toDataURL("image/jpeg", 0.95);
                        handleImage(url);
                    }
                }, 1024, 576);

@AmolKur
Copy link

AmolKur commented Aug 8, 2016

Same issue here - parallax/jsPDF#793. Any solution on this ?

@ewkonzo
Copy link

ewkonzo commented Nov 5, 2016

@icakirlar i had to folk this to make changes you suggested, now i know why this has so many folks.

The fix worked tho, thanks!

@niklasvh
Copy link
Owner

Is this still an issue with v1.0.0? If so, could you please share an example on jsfiddle.

@no-response
Copy link

no-response bot commented Dec 12, 2017

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@newdevsoft7
Copy link

Hi @icakirlar,
Where can I find core.js now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants