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

Longer page being misaligned on page and truncated at bottom #684

Open
karencfisher opened this issue Feb 28, 2024 · 1 comment
Open

Longer page being misaligned on page and truncated at bottom #684

karencfisher opened this issue Feb 28, 2024 · 1 comment

Comments

@karencfisher
Copy link

karencfisher commented Feb 28, 2024

I am generating PDF files from contents within the "main" element. This way only the "printable" portion of the page is converted (excluding, for example, navigation elements also on the page). Generally, it works quite nicely. The issue I am seeing, however, is that with longer main portions of the page, the resultant PDF has a very large margin at the top of the page, and lower part of the content is truncated.

For example, this result is fine:

fine

But with a longer content, this is happening:

cutoff

Here is the code calling html2pdf:

downloadButton.addEventListener("click", () => {
    const main = document.getElementById("main");
    const titleField = document.getElementById("card-title");
    const title = titleField.querySelector("h1").innerHTML;
    const opt = {
        filename: `${title}.pdf`
    }
    html2pdf().set(opt).from(main).save();
});

If useful, here are the HTML (Jinja template) and CSS files for the page:
https://github.com/karencfisher/recipe-share/blob/main/templates/recipe-card.html
https://github.com/karencfisher/recipe-share/blob/main/static/recipe-card.css

@Brokeflounder
Copy link

I had the same problem
I solved it with this: #420

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

No branches or pull requests

2 participants