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

Suggestiongs for next major release breaking changes #3067

Open
HackbrettXXX opened this issue Jan 18, 2021 · 1 comment
Open

Suggestiongs for next major release breaking changes #3067

HackbrettXXX opened this issue Jan 18, 2021 · 1 comment

Comments

@HackbrettXXX
Copy link
Collaborator

HackbrettXXX commented Jan 18, 2021

  • Don't flip width/height if format parameter does not fit dimensions. The orientation parameter only makes sense if a fixed page format like "a4" is provided. (e.g. addPage() orientation is inverted, and a question #3066).
  • Make some hotfixes the default behavior.
  • Maybe make pt the default unit (scale factor 1).
  • Get rid of floatPrecision option in favor of precision.
  • Redesign getFontList API with separate font style and font weight
  • Get rid of synchronous XHRs and make the respective APIs return a Promise.
  • Clean up html API. Make it return a proper Promise.
  • Maybe deprecate or remove setTextColor - it's the same as setFillColor
  • set/getFontSize should use current document unit, not always pt. Same for similar functions like getLineHeight.
@IV-R
Copy link

IV-R commented Dec 20, 2024

  • Don't flip width/height if format parameter does not fit dimensions. The orientation parameter only makes sense if a fixed page format like "a4" is provided. (e.g. addPage() orientation is inverted, and a question #3066).

  • Make some hotfixes the default behavior.

  • Maybe make pt the default unit (scale factor 1).

  • Get rid of floatPrecision option in favor of precision.

  • Redesign getFontList API with separate font style and font weight

  • Get rid of synchronous XHRs and make the respective APIs return a Promise.

  • Clean up html API. Make it return a proper Promise.

  • Maybe deprecate or remove setTextColor - it's the same as setFillColor

  • set/getFontSize should use current document unit, not always pt. Same for similar functions like getLineHeight.

#- ,,,,,,,,@[[[329]()]()]()]()43@6654
Here

// Function to create a jsPDF instance with consistent handling of orientation and dimensions
function createPDF(options) {
const {
orientation = 'portrait', // default orientation
unit = 'mm', // default unit
format = 'a4', // default format
width,
height,
} = options;

// Calculate dimensions based on the orientation
let pageWidth, pageHeight;

if (width && height) {
// If custom width and height are provided
if (orientation === 'landscape') {
pageWidth = Math.max(width, height);
pageHeight = Math.min(width, height);
} else {
pageWidth = Math.min(width, height);
pageHeight = Math.max(width, height);
}
} else {
// Use default format dimensions
const formatDimensions = jsPDF.getPageSize(format, unit);
if (orientation === 'landscape') {
pageWidth = formatDimensions.height;
pageHeight = formatDimensions.width;
} else {
pageWidth = formatDimensions.width;
pageHeight = formatDimensions.height;
}
}

// Create the jsPDF instance with the calculated dimensions
const doc = new jsPDF({
orientation,
unit,
format: [pageWidth, pageHeight],
});

return doc;
}

// Example usage
const pdf = createPDF({
orientation: 'landscape',
width: 210, // custom width
height: 297, // custom height
});

// Add some content
pdf.text('Hello, World!', 10, 10);

// Save the PDF
pdf.save('example.pdf');

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

No branches or pull requests

2 participants