Skip to content

Commit

Permalink
Added option to disable outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Jan 22, 2021
1 parent ecefe45 commit 8e995ef
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 18 deletions.
11 changes: 9 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,16 @@
- **language** - `string: "DE" | "EN" | "IT" | "FR"`. *default* `"DE"`.
- **size** - `string: "A4" | "A6/5"`. *default* `"A6/5"`.
- **scissors** - `boolean`: *default* `true`.
> Whether you want to show the scissors icons or the text `Separate before paying in`.
Whether you want to show the scissors icons or the text `Separate before paying in`.
> **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false.
- **separate** - `boolean`: *default* `false`.
Whether you want to show the text `Separate before paying in` rather than the scissors icons.

> **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false.
- **outlines** - `boolean`: *default* `true`.
Whether you want render the outlines. This option may be disabled if you use perforated paper.
- **autoGenerate** - `boolean`: *default* `true`.
> Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.
Whether you want to automatically finalize the PDF. When set to false you are able to add your own content to the PDF using PDFKit.

<br/>

Expand Down
62 changes: 47 additions & 15 deletions src/swissqrbill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export interface options {
language?: languages,
size?: size,
scissors?: boolean,
autoGenerate?: boolean
separate?: boolean,
outlines?: boolean
autoGenerate?: boolean,
}

export import PDFTable = ExtendedPDF.PDFTable;
Expand All @@ -51,6 +53,8 @@ export class PDF extends ExtendedPDF.PDF {
public size: size = "A6/5";
private _data: data;
private _scissors: boolean = true;
private _separate: boolean = false;
private _outlines: boolean = true;
private _language: languages = "DE";
private _marginTop: number = 0;
private _autoGenerate: boolean = true;
Expand Down Expand Up @@ -167,6 +171,18 @@ export class PDF extends ExtendedPDF.PDF {
}
if(options.scissors !== undefined){
this._scissors = options.scissors;
this._separate = !options.scissors;
}
if(options.separate !== undefined){
this._separate = options.separate;
this._scissors = !options.separate;
}
if(options.scissors === false && options.separate === false){
this._separate = false;
this._scissors = false;
}
if(options.outlines !== undefined){
this._outlines = options.outlines;
}
if(options.autoGenerate !== undefined){
this._autoGenerate = options.autoGenerate;
Expand Down Expand Up @@ -228,12 +244,30 @@ export class PDF extends ExtendedPDF.PDF {
private _drawOutlines(): void {


//-- Horizontal line
//-- Lines

if(this._outlines === true){


//-- Horizontal line

if(this.page.height > utils.mmToPoints(105)){

this.moveTo(0, this._marginTop)
.lineTo(utils.mmToPoints(210), this._marginTop)
.lineWidth(.75)
.strokeOpacity(1)
.dash(1, { size: 1 })
.strokeColor("black")
.stroke();

}


if(this.page.height > utils.mmToPoints(105)){
//-- Vertical line

this.moveTo(0, this._marginTop)
.lineTo(utils.mmToPoints(210), this._marginTop)
this.moveTo(utils.mmToPoints(62), this._marginTop)
.lineTo(utils.mmToPoints(62), this._marginTop + utils.mmToPoints(105))
.lineWidth(.75)
.strokeOpacity(1)
.dash(1, { size: 1 })
Expand All @@ -243,15 +277,7 @@ export class PDF extends ExtendedPDF.PDF {
}


//-- Vertical line

this.moveTo(utils.mmToPoints(62), this._marginTop)
.lineTo(utils.mmToPoints(62), this._marginTop + utils.mmToPoints(105))
.lineWidth(.75)
.strokeOpacity(1)
.dash(1, { size: 1 })
.strokeColor("black")
.stroke();
//-- Scissors

if(this._scissors === true){

Expand All @@ -271,7 +297,12 @@ export class PDF extends ExtendedPDF.PDF {
.fill();
this.translate(0, 0);

} else {
}


//-- Separation text

if(this._separate === true){

if(this.page.height > utils.mmToPoints(105)){

Expand All @@ -283,6 +314,7 @@ export class PDF extends ExtendedPDF.PDF {
});

}

}

}
Expand Down
24 changes: 24 additions & 0 deletions tests/no-scissors-no-outlines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-outline.pdf", { "scissors" : false, "outlines": false, "size": "A4" });
24 changes: 24 additions & 0 deletions tests/no-scissors-no-separate-no-outlines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate-no-outline.pdf", { "scissors" : false, "separate": false, "outlines": false, "size": "A4" });
24 changes: 24 additions & 0 deletions tests/no-scissors-no-separate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/no-scissors-no-separate.pdf", { "scissors" : false, "separate": false, "size": "A4" });
24 changes: 24 additions & 0 deletions tests/no-scissors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/no-scissors.pdf", { "scissors" : false, "size": "A4" });
24 changes: 24 additions & 0 deletions tests/no-separate-no-outlines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/no-separate-no-outline.pdf", { "separate" : false, "outlines": false, "size": "A4" });
12 changes: 12 additions & 0 deletions tests/run-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ echo "normal-iban-creditor-reference"
call node normal-iban-creditor-reference
echo "normal-iban-no-reference"
call node normal-iban-no-reference
echo "no-scissors"
call node no-scissors
echo "no-scissors-no-outlines"
call node no-scissors-no-outlines
echo "no-scissors-no-separate"
call node no-scissors-no-separate
echo "no-separate-no-outlines"
call node no-separate-no-outlines
echo "no-scissors-no-separate-no-outlines"
call node no-scissors-no-separate-no-outlines
echo "qr-iban"
call node qr-iban
echo "separate"
call node separate
echo "separate-scissors"
call node separate-scissors
echo "callback"
call node callback
echo "callback-with-options"
Expand Down
12 changes: 12 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ echo "no-debtor-no-amount-no-reference"
node no-debtor-no-amount-no-reference
echo "no-debtor-no-reference"
node no-debtor-no-reference
echo "no-scissors"
node no-scissors
echo "no-scissors-no-outlines"
node no-scissors-no-outlines
echo "no-scissors-no-separate"
node no-scissors-no-separate
echo "no-separate-no-outlines"
node no-separate-no-outlines
echo "no-scissors-no-separate-no-outlines"
node no-scissors-no-separate-no-outlines
echo "normal-iban-creditor-reference"
node normal-iban-creditor-reference
echo "normal-iban-no-reference"
Expand All @@ -41,6 +51,8 @@ echo "qr-iban"
node qr-iban
echo "separate"
node separate
echo "separate-scissors"
node separate-scissors
echo "callback"
node callback
echo "callback-with-options"
Expand Down
24 changes: 24 additions & 0 deletions tests/separate-scissors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const SwissQRBill = require("../");

const data = {
currency: "CHF",
amount: 1199.95,
reference: "210000000003139471430009017",
creditor: {
name: "Robert Schneider AG",
address: "Rue du Lac 1268",
zip: 2501,
city: "Biel",
account: "CH4431999123000889012",
country: "CH"
},
debtor: {
name: "Pia-Maria Rutschmann-Schnyder",
address: "Grosse Marktgasse 28",
zip: 9400,
city: "Rorschach",
country: "CH"
}
};

const pdf = new SwissQRBill.PDF(data, "./output/separate-scissors.pdf", { "separate" : true, "scissors": true, "size": "A4" });
2 changes: 1 addition & 1 deletion tests/separate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const data = {
}
};

const pdf = new SwissQRBill.PDF(data, "./output/separate.pdf", { "scissors" : false, size: "A4" });
const pdf = new SwissQRBill.PDF(data, "./output/separate.pdf", { "separate" : true, "size": "A4" });

0 comments on commit 8e995ef

Please sign in to comment.