-
-
Save InfernoZeus/6010328 to your computer and use it in GitHub Desktop.
diff --git a/content/scripts/html2canvas.js b/content/scripts/html2canvas.js | |
index 7ab27ed..52f3eab 100644 | |
--- a/content/scripts/html2canvas.js | |
+++ b/content/scripts/html2canvas.js | |
@@ -2830,9 +2830,10 @@ _html2canvas.Renderer.Canvas = function(options) { | |
newCanvas = doc.createElement('canvas'); | |
newCanvas.width = bounds.width; | |
newCanvas.height = bounds.height; | |
- ctx = newCanvas.getContext("2d"); | |
- | |
- ctx.drawImage(canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height); | |
+ if (newCanvas.width != 0 && newCanvas.height != 0) { | |
+ ctx = newCanvas.getContext("2d"); | |
+ ctx.drawImage(canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height); | |
+ } | |
canvas = null; | |
return newCanvas; | |
} |
From 88d7a3e5dadf67e28605e6c9cc943dc72de175db Mon Sep 17 00:00:00 2001 | |
From: Ben Fox-Moore <[email protected]> | |
Date: Tue, 16 Jul 2013 18:03:52 +0200 | |
Subject: [PATCH] Patch html2canvas to jump back to previous scroll position | |
after parsing | |
--- | |
content/scripts/html2canvas.js | 3 +++ | |
1 file changed, 3 insertions(+) | |
diff --git a/content/scripts/html2canvas.js b/content/scripts/html2canvas.js | |
index 4689971..04820f8 100644 | |
--- a/content/scripts/html2canvas.js | |
+++ b/content/scripts/html2canvas.js | |
@@ -1013,6 +1013,8 @@ function h2cRenderContext(width, height) { | |
}; | |
} | |
_html2canvas.Parse = function (images, options) { | |
+ var top = window.pageYOffset || document.documentElement.scrollTop | |
+ var left = window.pageXOffset || document.documentElement.scrollLeft | |
window.scroll(0,0); | |
var element = (( options.elements === undefined ) ? document.body : options.elements[0]), // select body by default | |
@@ -2155,6 +2157,7 @@ _html2canvas.Parse = function (images, options) { | |
stack.backgroundColor = getCSS(document.documentElement, "backgroundColor"); | |
body.removeChild(hidePseudoElements); | |
+ window.scroll(left, top); | |
return stack; | |
} | |
-- | |
1.8.3.1 |
Doesn't work if the object is out screen, it saves only the visible part. Do u have any fix for that issue?
I still get the IndexSizeError exception due to a negative bounds.top value.
@elyngved, Im facing the same. No page scrolling in html to canvas conversion but, if the page is scrolled down from where it was loaded, it adds a padding above the content and leaves some of the bottom content. Any solution for that?
After a brief review of how the 0.4 core code works. I realized that it is possible to capture the area above the scrollbar (hidden on screen view, but visible on document). By inserting the element's exact position when cliping element to newCanvas. (Using jQuery (element) .offset () can do this)
I have fork v0.4 and made a patch with the modifications from @InfernoZeus and added a new offset.
See the difference here: ultra-bugs/html2canvas@84284cc
Or use the built-in bower with the package name: z-html2canvas#0.4.3
Great patch. I kind of can't believe how well it works. The diff points have changed though, I had to insert it here: