softdinlibreriajs 12.0.32 → 12.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -5
- package/src/GenerarPDF.js +88 -67
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "softdinlibreriajs",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.34",
|
|
4
4
|
"description": "Libreria Softdin",
|
|
5
5
|
"main": "src/",
|
|
6
6
|
"scripts": {
|
|
@@ -19,8 +19,5 @@
|
|
|
19
19
|
"url": "https://github.com/SoftdinNomina/libreriaSoftdinJS/issues"
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/SoftdinNomina/libreriaSoftdinJS#readme",
|
|
22
|
-
"_comments": "comando para ejecutar las veriosnes despues debe cambiar la VERSION 12.0.24 por la que sigue despues ejecutar este comando npm publish"
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"pdfmake": "^0.2.14"
|
|
25
|
-
}
|
|
22
|
+
"_comments": "comando para ejecutar las veriosnes despues debe cambiar la VERSION 12.0.24 por la que sigue despues ejecutar este comando npm publish"
|
|
26
23
|
}
|
package/src/GenerarPDF.js
CHANGED
|
@@ -1,72 +1,93 @@
|
|
|
1
|
-
import
|
|
2
|
-
import pdfFonts from 'pdfmake/build/vfs_fonts';
|
|
3
|
-
|
|
4
|
-
// Registrar las fuentes de pdfmake
|
|
5
|
-
pdfMake.vfs = pdfFonts.pdfMake.vfs;
|
|
1
|
+
import { jsPDF } from "jspdf";
|
|
6
2
|
|
|
7
3
|
// Función para generar el PDF
|
|
8
|
-
export const generarCertificadoLaboral = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
content: [
|
|
23
|
-
{ text: 'Certificado Laboral', style: 'header' },
|
|
24
|
-
{
|
|
25
|
-
text: `A quien corresponda:`,
|
|
26
|
-
margin: [0, 20]
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
text: [
|
|
30
|
-
`Por medio de la presente se certifica que el señor/a `,
|
|
31
|
-
{ text: employeeName, bold: true },
|
|
32
|
-
` ha laborado en nuestra empresa `,
|
|
33
|
-
{ text: companyName, bold: true },
|
|
34
|
-
` como `,
|
|
35
|
-
{ text: jobTitle, bold: true },
|
|
36
|
-
` desde `,
|
|
37
|
-
{ text: startDate, bold: true },
|
|
38
|
-
` hasta `,
|
|
39
|
-
{ text: endDate, bold: true },
|
|
40
|
-
`.`
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
{ text: 'Agradecemos la atención a la presente.', margin: [0, 20] }
|
|
44
|
-
],
|
|
45
|
-
footer: function(currentPage, pageCount) {
|
|
46
|
-
return {
|
|
47
|
-
columns: [
|
|
48
|
-
{ text: `Página ${currentPage} de ${pageCount}`, alignment: 'right', margin: [0, 0, 20, 0] },
|
|
49
|
-
{ text: 'Pie de página - Información de contacto', alignment: 'center', margin: [0, 0, 0, 10] }
|
|
50
|
-
]
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
styles: {
|
|
54
|
-
header: {
|
|
55
|
-
fontSize: 22,
|
|
56
|
-
bold: true,
|
|
57
|
-
alignment: 'center'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
4
|
+
export const generarCertificadoLaboral = (form, logoBase64) => {
|
|
5
|
+
console.log("Generando certificado laboral...");
|
|
6
|
+
// Validaciones de entrada
|
|
7
|
+
if (
|
|
8
|
+
!form ||
|
|
9
|
+
!form.report_header ||
|
|
10
|
+
!form.description ||
|
|
11
|
+
!form.signature ||
|
|
12
|
+
!form.report_footer
|
|
13
|
+
) {
|
|
14
|
+
console.error("Faltan datos en el formulario.");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
61
17
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.error('Element with id "iframeContainer" not found.');
|
|
69
|
-
}
|
|
18
|
+
const doc = new jsPDF({
|
|
19
|
+
orientation: "portrait", // Orientación vertical
|
|
20
|
+
unit: "mm", // Unidades en milímetros
|
|
21
|
+
format: "letter", // Tamaño carta
|
|
22
|
+
putOnlyUsedFonts: true,
|
|
23
|
+
precision: 16, // Precisión flotante
|
|
70
24
|
});
|
|
71
|
-
};
|
|
72
25
|
|
|
26
|
+
// Encabezado: agregar logo si está habilitado
|
|
27
|
+
const imgData = logoBase64.value;
|
|
28
|
+
if (form.show_logo && imgData) {
|
|
29
|
+
doc.addImage(imgData, "JPEG", 15, 10, 30, 30); // (imagen, tipo, x, y, ancho, alto)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Agregar encabezado del reporte
|
|
33
|
+
doc.setFontSize(16);
|
|
34
|
+
const maxWidthHeader = form.show_logo ? 150 : 200;
|
|
35
|
+
const linesHeader = doc.splitTextToSize(form.report_header, maxWidthHeader);
|
|
36
|
+
let yPosition = 20; // Posición Y inicial
|
|
37
|
+
linesHeader.forEach((line) => {
|
|
38
|
+
doc.text(line, form.show_logo ? 120 : 100, yPosition, { align: "center" });
|
|
39
|
+
yPosition += 8;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
yPosition += 20; // Incrementar posición Y para el siguiente bloque
|
|
43
|
+
|
|
44
|
+
// Información del certificado
|
|
45
|
+
doc.setFontSize(20);
|
|
46
|
+
doc.setFont("helvetica", "bold");
|
|
47
|
+
const certText = "CERTIFICA";
|
|
48
|
+
const certTextWidth = doc.getTextWidth(certText);
|
|
49
|
+
const certX = (doc.getPageWidth() - certTextWidth) / 2; // Centrar el texto
|
|
50
|
+
doc.text(certText, certX, yPosition);
|
|
51
|
+
|
|
52
|
+
// Descripción del certificado
|
|
53
|
+
doc.setFontSize(12);
|
|
54
|
+
doc.setFont("helvetica", "normal");
|
|
55
|
+
const linesDescription = doc.splitTextToSize(form.description, 180);
|
|
56
|
+
yPosition += 20;
|
|
57
|
+
linesDescription.forEach((line) => {
|
|
58
|
+
doc.text(line, 20, yPosition);
|
|
59
|
+
yPosition += 10;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Firma
|
|
63
|
+
const firmaLinea = "__________________________________";
|
|
64
|
+
const firmaTextWidth = doc.getTextWidth(firmaLinea);
|
|
65
|
+
const firmaX = (doc.getPageWidth() - firmaTextWidth) / 2;
|
|
66
|
+
doc.text(firmaLinea, firmaX, 230);
|
|
67
|
+
|
|
68
|
+
doc.setFont("helvetica", "bold");
|
|
69
|
+
const linesSignature = doc.splitTextToSize(form.signature, 180);
|
|
70
|
+
yPosition = 235;
|
|
71
|
+
linesSignature.forEach((line) => {
|
|
72
|
+
const textWidth = doc.getTextWidth(line);
|
|
73
|
+
const textX = (doc.getPageWidth() - textWidth) / 2;
|
|
74
|
+
doc.text(line, textX, yPosition);
|
|
75
|
+
yPosition += 4;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Pie de informe
|
|
79
|
+
doc.setFont("helvetica", "normal");
|
|
80
|
+
doc.setFontSize(8);
|
|
81
|
+
const linesFooter = doc.splitTextToSize(form.report_footer, 180);
|
|
82
|
+
yPosition = 255;
|
|
83
|
+
linesFooter.forEach((line) => {
|
|
84
|
+
const textWidth = doc.getTextWidth(line);
|
|
85
|
+
const textX = (doc.getPageWidth() - textWidth) / 2;
|
|
86
|
+
doc.text(line, textX, yPosition);
|
|
87
|
+
yPosition += 4;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Generar salida como URL blob
|
|
91
|
+
const pdfOutput = doc.output("bloburl");
|
|
92
|
+
return pdfOutput; // Devolver la URL del PDF generado
|
|
93
|
+
};
|