Open momo1108 opened 3 years ago
possibly fixed by my PR in html2canvas
@mikey0000 the PR you're talking about is https://github.com/niklasvh/html2canvas/pull/2708.
As it's not merged and it seems it's not going to be, today I used patch-package to patch html2canvas@1.4.1
for the project I'm working on. And it's working!
Here is the diff that solved my problem:
diff --git a/node_modules/html2canvas/dist/html2canvas.js b/node_modules/html2canvas/dist/html2canvas.js
index 84cb30d..8f2c75f 100644
--- a/node_modules/html2canvas/dist/html2canvas.js
+++ b/node_modules/html2canvas/dist/html2canvas.js
@@ -6572,6 +6572,8 @@
container.style.margin = '0';
container.style.padding = '0';
container.style.whiteSpace = 'nowrap';
+ container.style.position = 'absolute';
+ container.style.top = '-1000px';
body.appendChild(container);
img.src = SMALL_IMAGE;
img.width = 1;
@@ -6579,10 +6581,13 @@
img.style.margin = '0';
img.style.padding = '0';
img.style.verticalAlign = 'baseline';
+ img.style.display = 'inline-block';
span.style.fontFamily = fontFamily;
span.style.fontSize = fontSize;
span.style.margin = '0';
span.style.padding = '0';
+ span.style.lineHeight = 'normal';
+ span.style.height = 'auto';
span.appendChild(this._document.createTextNode(SAMPLE_TEXT));
container.appendChild(span);
container.appendChild(img);
This issue body was partially generated by patch-package.
It didn't work for me; I had to replace:
- const baseline = img.offsetTop - span.offsetTop + 2;
+ const baseline = img.offsetTop - span.offsetTop - 8;
And
- const middle = img.offsetTop - container.offsetTop + 2;
+ const middle = img.offsetTop - container.offsetTop - 8;
I'm using Vue.js for generating reporting page, and using html2pdf try to save reporting page(div element) as pdf file. Almost succeeded, but there is one problem.
If you look at the picture below,
It's almost written in korean, but all text is vertically aligned middle.
but if I save this div element as pdf file,
You can see all text except those in the charts, are a little down from middle. Those texts consists of various tags(p, th, td, textarea, span, etc..)
Can you guess any reason for this problem?
FYI, this is the code I'm using to save page as pdf file.
And, this is little hard to read, but this is the code for the report page.