Skip to content

jsPDF and React- Content Zoomed  #3202

@sanishtjppi

Description

@sanishtjppi

Hi,

Loved the whole idea of this library and thank you for creating such an awesome job. I am trying to replace my Puppeteer-based server-side PDF generation with jsPDF. I have several react apps which creates HTML report and print that as PDF.

When I use the html() method, the content is always zoomed for some reason. I thought it's something with my code, so I created a clean slate CRA project and tried the html() option. The result was the same. Everything is rendered as I wanted, but all are zoomed big to another level. Content will clip because of this.

Any idea why this might be happening?

I am just using the most basic jsPDF code,

const doc = new jsPDF();
      doc.html(document.body, {
        callback: function (doc) {
          doc.save();
        },        
      });

I am using "jspdf": "^2.3.1" "react": "^17.0.2". All latest as I am writing this.

Update:

Using html2canvas with a very low scale gives better results. Not sure whether it's a the right way to deal with it.

  const doc = new jsPDF();
  
    doc.html(document.body, {
      callback: function (doc) {
        doc.save();
      },      
      html2canvas:{scale:0.1}
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions