pdf2.js 2.16 KB
class PDF2 {

	"use strict";

	constructor() {
		/** Coordinate container that occupies the whole page **/
		this.A4 = new Div(
			new Vector(0, 0),
			new Vector(595, 842)
		);

		this.containerSize = 86;
		this.font = {
			"font": "times",
			"type": "normal",
			"size": 10
		};
	}


	pdf(data) {
		/**
		 * The lambdas serve as "apply" functions
		 * Each function processes an element, executed in order of appeareance in HTML.
		 * They all return a coordinate "pointer" to draw.
		 */
		const pdfthis = this;
		const functionMapping = [
			(pointer, data) => pdfthis.mahaToPDF(pointer, data['header']),
			(pointer, data) => pdfthis.headerToPDF(pointer, data['header']),
			(pointer, data) => pdfthis.alineadorToPDF(pointer, data['alineador']),
			(pointer, data) => pdfthis.suspensionToPDF(pointer, data['suspension']),
			(pointer, data) => pdfthis.frenosToPDF(pointer, data['frenos']),
			(pointer, data) => pdfthis.traseroToPDF(pointer, data['trasero']),
			(pointer, data) => pdfthis.gaseshumosToPDF(pointer, data['gaseshumos'])
		];

		/**
		 * We pass the pointer to each function, which then modify it and passes it to the next,
		 * We start with (0%,0%)
		 */
		functionMapping.reduce(
			(pointer, treeMaker) => treeMaker(pointer, data),
			pdfthis.A4.position
		);

		return this.A4;
	}

	mahaToPDF(pointer, data) {

		const maha = this.A4.addRelativeChild(new Div(pointer, new Vector(Pos.end, 6)));

		maha.addRelativeChildren([
			
			new Line(
				new Vector(Pos.beg_margin, Pos.end),
				new Vector(Pos.end_margin, Pos.end)
			),

			new Text(
				["MAHA","EUROSYSTEM","Bitte hier Ihre","Anschrift eintragen"],
				new Vector(Pos.middle, Pos.quarter),
				this.font,
				"center"
			),

			new Text(
				["EUROSYSTEM","V 3.18.009",data['fecha']],
				new Vector(Pos.three_quarters, Pos.middle),
				this.font,
				"right"
			),

			new Image(
				document.getElementById("maha"),
				new Vector(Pos.end - 10, Pos.beg_margin),
				new Vector(10, Pos.end_margin)
			)
		]);

	}

	headerToPDF(pointer, data) {
	}

	alineadorToPDF(pointer, data) {
	}

	suspensionToPDF(pointer, data) {
	}

	frenosToPDF(pointer, data) {
	}

	traseroToPDF(pointer, data) {
	}

	gaseshumosToPDF(pointer, data) {
	}
}