Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/jspdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function TilingPattern(boundingBox, xStep, yStep, gState, matrix) {
* @param {number} [options.precision=16] Precision of the element-positions.
* @param {number} [options.userUnit=1.0] Not to be confused with the base unit. Please inform yourself before you use it.
* @param {string[]} [options.hotfixes] An array of strings to enable hotfixes such as correct pixel scaling.
* @param {boolean} [options.autoPageOrientation=true] When enabled, jsPDF swaps custom page dimensions to match the selected orientation ("portrait" keeps height >= width, "landscape" keeps width >= height). Disable to preserve custom dimensions as provided.
* @param {Object} [options.encryption]
* @param {string} [options.encryption.userPassword] Password for the user bound by the given permissions list.
* @param {string} [options.encryption.ownerPassword] Both userPassword and ownerPassword should be set for proper authentication.
Expand Down Expand Up @@ -216,6 +217,7 @@ function jsPDF(options) {
var precision;
var floatPrecision = 16;
var defaultPathOperation = "S";
var autoPageOrientation = true;
var encryptionOptions = null;

options = options || {};
Expand All @@ -240,6 +242,9 @@ function jsPDF(options) {
if (typeof options.floatPrecision !== "undefined") {
floatPrecision = options.floatPrecision;
}
if (typeof options.autoPageOrientation === "boolean") {
autoPageOrientation = options.autoPageOrientation;
}
defaultPathOperation = options.defaultPathOperation || "S";
}

Expand Down Expand Up @@ -2738,17 +2743,19 @@ function jsPDF(options) {

format = [width, height];

switch (orientation.substr(0, 1)) {
case "l":
if (height > width) {
format = [height, width];
}
break;
case "p":
if (width > height) {
format = [height, width];
}
break;
if (autoPageOrientation) {
switch (orientation.substr(0, 1)) {
case "l":
if (height > width) {
format = [height, width];
}
break;
case "p":
if (width > height) {
format = [height, width];
}
break;
}
}

beginPage(format);
Expand Down
15 changes: 15 additions & 0 deletions test/specs/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,19 @@ describe("Core: Paging", () => {
expect(doc.getPageWidth(0)).toEqual(doc.getPageWidth(1));
expect(doc.getPageHeight(0)).toEqual(doc.getPageHeight(1));
});
it("should preserve custom dimensions when autoPageOrientation is disabled", () => {
const doc = new jsPDF({
orientation: "portrait",
unit: "pt",
format: [600, 300],
autoPageOrientation: false
});

expect(doc.getPageWidth(1)).toEqual(600);
expect(doc.getPageHeight(1)).toEqual(300);

doc.addPage([700, 200], "portrait");
expect(doc.getPageWidth(2)).toEqual(700);
expect(doc.getPageHeight(2)).toEqual(200);
});
});
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ declare module "jspdf" {
putOnlyUsedFonts?: boolean;
hotfixes?: string[];
floatPrecision?: number | "smart";
autoPageOrientation?: boolean;

}

export interface Point {
Expand Down