-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
html: margins have no effect #2924
Comments
Some afterthoughts: The behavior between margins and the
|
.html is much better than addHtml, fromHtml, etc. |
I installed jspdf@2.1.1 for .html use. |
Same problem. Margins in html method has no effect :( |
Make sure you are avoiding collapasing margins. For example margin-bottom on one element, and margin-top on an element below it will collapse inward to the element NOT to the margins |
@HackbrettXXX Yes I think that may be very useful, I currently have a letter generation use case and am dearly missing this feature. |
Ok so has there been anyone who managed to solve this ? yes @HackbrettXXX my issue was a duplicate. I am setting margin with an array of random numbers but this has no effect on the printed pdf. I am using using the latest version of jsPdf and setting of margins does not work. v2.1.1 seems like it is very limited to customizability using the html() plugin compared to the previous versions of jsPdf using fromHtml() & addHtml() Do I have to install previous version below 2.0.0 such as 1.5.3 to achive the desired outcome ? |
Please can someone guide me on this ? I desperately need tis margin feature !! |
@kevinborg If you need the margins right now, you need to downgrade back to 1.5.3 and use from/addHTML. If it can wait, you may wait for this issue to be resolved. You may also prepare a pull request yourself if it is urgent. |
@HackbrettXXX I have downgraded to 1.5.3 but this causes a problem were the downloading a pdf does not work and i am unable to debug this because no console error is thrown. I have installed html2canvas separately and using addHTML method as shown below
am I doing something wrong or missing something here ? Also do i need to install a specific version of html2canvas ? |
I'd also like to use margins with the Are there plans to fix this or update the documentation? |
We will fix this as soon as someone from the community provides a pull request. I personally don't have time for this currently. |
Did anyone fixed or found a workaround for this problem? I also really need this 'feature' to work properly. I think that 'upgrades' like this one, when a default behavior is getting broke, it should be a priority in getting it working. It shouldn't be an issue in the first place. It's freaking frustrating when a library says it's doing something, and after you install it and use it, you realize that it's not actually doing what it's supposed to do... |
@HackbrettXXX I would love to have a go at this, but I'm currently having trouble running the |
@jeffsieu thanks. I'm assigning you. In your debugging page, you need to load html2canvas (and dompurify if you pass a string to
|
@HackbrettXXX Is the content supposed to be scaled to fit the margins? And to be clear, is it context2d.js that manipulates the position/scale of the output? |
@emildatcu I understand that this is frustrating, but please understand that this is a (free!) open source library that's currently maintained by a single person (me). And I simply don't have the time to fix everything immediately. Even keeping up with all new issues and pull requests is hard. That's why it's open source and everyone can contribute to this project :) |
@jeffsieu The content should not be scaled to fit the margins. Instead, consider it as if the drawing canvas is the entire page minus the margins. If something would extend beyond the left/right margin, we should clip that. If something extends below the bottom margin, start a new page (with the top margin). See also my #2924 (comment). The position is AFAIK partly controlled by context2d.js and partly html.js. I'm not too familiar with both files. |
@HackbrettXXX After a bit of digging around in the code, I still find it quite challenging to fully understand what's going on in the library. To my understanding, the html function takes in an html element, then puts it in a pre-defined container, passes that container to html2canvas, then takes the resultant canvas and assigns it as a property of context2d, after which it gets turned into a pdf. I'm still unsure at which point in the code does the canvas get split into pages, which is probably where the margin needs to be added. Can you provide any guidance? |
The The splitting into pages is controlled by the |
Ok, I managed to get the top and left margins working, but I'm unsure how to modify the pdf renderer to cut off at the right and bottom margins. As Context2D is making calls to |
Hello, P.S. I can not use html2Canvas as well as I need the pdf text to be selectable. |
@Jigisha-sublime, I used this as a workaround at least until this issue is fixed and works, and the text is selectable:
}` hope it helps you as well :) |
@datcuemil, thanks for your response. |
Also, is there any way we can repeat the HTML header on each page with this method? |
I am also not seeing any effect of margin attributes. I am using html to render div contents and its splitting the text in between. margin has no impact at all |
I just update version 2.3.1 . It ok. But #2924 sill problem. I hope you will fix soon. |
@vandum that not working i have that : |
Is any fix done in latest version about margins ? |
I have the same problem |
I have to the same problem |
still an issue |
@yatkolenko |
The documentation and code suggest that the user can set page margins in the
html
method, but they have no effect. The margin options seem to get lost somewhere.The text was updated successfully, but these errors were encountered: