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

Fix cell.js getTextDimensions doesn't respect lineHeightFactor option #3814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imjosh
Copy link

@imjosh imjosh commented Jan 22, 2025

Before/After
image

var doc = new jsPDF();
const textOptions = {
  maxWidth: 50,
  lineHeightFactor: 1.5
};

const paragraphs = [
  '1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tempor leo tellus, ut luctus mi aliquet a. Aenean id mauris volutpat, ullamcorper libero a, bibendum leo. Praesent ut enim sapien. Ut et felis interdum, molestie eros quis, facilisis odio.',
  '2. Cras risus ex, dapibus eu interdum in, placerat eu neque. Quisque venenatis tellus ac aliquam eleifend.',
  '3. Nunc ex urna, laoreet a gravida molestie, bibendum ac tellus. Nulla finibus sed lectus porta elementum. Suspendisse potenti. Sed quis purus at nunc sollicitudin posuere.',
];

let y = 15;
paragraphs.forEach(paragraph => {
  const height = doc.getTextDimensions(paragraph, textOptions).h;
  doc.text(paragraph, 15, y, textOptions);
  y += height + 5;
});

@imjosh imjosh marked this pull request as ready for review January 22, 2025 23:35
@imjosh
Copy link
Author

imjosh commented Jan 22, 2025

Related to #1933

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

Successfully merging this pull request may close these issues.

1 participant