Skip to content

jspdf.html() doesn't render correctly #3532

@milesje

Description

@milesje

I have read and understood the contribution guidelines.

jsPDF version is 2.5.1

I'm just performing a simple jspdf.html() call but the rendered PDF does not match the rendered HTML. I am using Tailwind CSS in the HTML but I have also converted the Tailwind code into inlined styles which produces the exact same results.

Here is the HTML to be rendered

<div id="appGenPdfText" class="flex flex-col w-full h-full space-y-1">
  <div class="flex flex-row bg-blue-200 justify-center">
    <p class="m-1 text-primary text-xl">APPLICANT GENERAL INFORMATION</p>
  </div>
  <div class="flex bg-primary justify-center">
    <p class="text-white">Primary Information</p>
  </div>
</div>

here is the JS which uses jsPDF to render as PDF.

let pdf = await new jsPDF({
  orientation: 'p',
  unit: 'pt',
  format: 'letter',
  putOnlyUsedFonts: true,
  compress: true
})
const source = await document.getElementById('appGenPdfText')

await pdf.html(source, {
  width: 580,
  windowWidth: 580,
  margin: 15
})
await pdf.save()

The resulting PDF looks like.
image

As you can see the first like of text for some reason has no spaces, and is not centered in the light blue box. The second line does have the space between words but also is not centered.

The rendered HTML looks like this.
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions