parallax / jsPDF

Client-side JavaScript PDF generation for everyone.

Home Page:https://parall.ax/products/jspdf

Repository from Github https://github.comparallax/jsPDFRepository from Github https://github.comparallax/jsPDF

AddImage doesn't respect the size provided in px

bajras opened this issue · comments

Trying to export screenshot to pdf using HTMLtoCanvas using the pixel unit. The output PDF is smaller than what it is passed, but works fine if the unit is in in.

const doc = new jsPDF({
    orientation: "landscape",
    unit: "px",
    format: [792, 432],
    hotfixes: ["px_scaling"]
  });
  doc.addImage(
    canvas,
    0,
    0,
    792,
    432
  );
  doc.save(`some.pdf`);

The output for this pdf in pixel in sketch is 607.5 x 337.5 should have been 792x432(which is 11x6in).

But if I change the units to be In it works fine

const doc = new jsPDF({
    orientation: "landscape",
    unit: "in",
    format: [11, 6],
  });
  doc.addImage(
    canvas,
    0,
    0,
    11,
    6
  );
  doc.save(`some.pdf`);

The output for this pdf in pixel check in sketch is 792 x 432 (which is 11x6in).

Is it something Im missing here?

72 pixels in Sketch converts to 1 inch in an exported PDF

Cannot reproduce. Please provide a complete and runnable repro. Which jsPDF version are you using?

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.