You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
// 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);
width/height
ifformat
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).pt
the default unit (scale factor 1).floatPrecision
option in favor ofprecision
.getFontList
API with separate font style and font weighthtml
API. Make it return a proper Promise.setTextColor
- it's the same assetFillColor
set/getFontSize
should use current document unit, not alwayspt
. Same for similar functions likegetLineHeight
.The text was updated successfully, but these errors were encountered: