fix(build): create sub-app make_pdf
Some checks failed
Deploy Production Server / if_merged (pull_request) Failing after 18s

This commit is contained in:
2025-02-06 11:11:10 +01:00
parent 9f8d9dd0ca
commit 4c83b80b6d
15 changed files with 415 additions and 236 deletions

38
src/main/pdf_gen/.gitignore vendored Normal file
View File

@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

51
src/main/pdf_gen/pom.xml Normal file
View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.titionfire</groupId>
<artifactId>pdf_gen</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fr.titionfire.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,223 @@
package fr.titionfire;
import com.lowagie.text.*;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Objects;
public class Main {
public static void main(String[] args) {
PdfData pdfData = new PdfData();
File dest = new File(args[0]);
pdfData.fname = args[1];
pdfData.lname = args[2];
pdfData.genre = args[3];
pdfData.categorie = args[4];
pdfData.certificate = args[5];
pdfData.saison = Integer.parseInt(args[6]);
pdfData.licence = Integer.parseInt(args[7]);
pdfData.club = args[8];
pdfData.club_no = Integer.parseInt(args[9]);
pdfData.birth_date = args[10];
pdfData.photo_file = new File(args[11]);
try {
FileOutputStream out = new FileOutputStream(dest);
new Main().make_pdf(pdfData, out);
} catch (IOException ignored) {
ignored.printStackTrace();
System.exit(1);
}
System.out.println("PDF generated successfully");
System.exit(0);
}
private void make_pdf(PdfData pdfData, FileOutputStream out) throws IOException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Document document = new Document();
PdfWriter.getInstance(document, out);
document.open();
document.addCreator("FFSAF");
document.addTitle(
"Attestation d'adhésion " + pdfData.saison + "-" + (pdfData.saison + 1) + " de " + pdfData.lname + " " + pdfData.fname);
document.addCreationDate();
document.addProducer("https://www.ffsaf.fr");
InputStream fontStream = Main.class.getClassLoader().getResourceAsStream("DMSans-Regular.ttf");
if (fontStream == null) {
throw new IOException("Font file not found");
}
BaseFont customFont = BaseFont.createFont("DMSans-Regular.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, true,
null, fontStream.readAllBytes());
// Adding font
Font headerFont = new Font(customFont, 26, Font.BOLD);
Font subHeaderFont = new Font(customFont, 16, Font.BOLD);
Font bigFont = new Font(customFont, 18, Font.BOLD);
Font bodyFont = new Font(customFont, 15, Font.BOLD);
Font smallFont = new Font(customFont, 10, Font.NORMAL);
// Creating the main table
PdfPTable mainTable = new PdfPTable(2);
mainTable.setWidthPercentage(100);
mainTable.setSpacingBefore(20f);
mainTable.setSpacingAfter(0f);
mainTable.setWidths(new float[]{120, 300});
mainTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
// Adding logo
Image logo = Image.getInstance(
Objects.requireNonNull(
getClass().getClassLoader().getResource("FFSSAF-bord-blanc-fond-transparent.png")));
logo.scaleToFit(120, 120);
PdfPCell logoCell = new PdfPCell(logo);
logoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
logoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
logoCell.setPadding(0);
logoCell.setRowspan(1);
logoCell.setBorder(PdfPCell.NO_BORDER);
mainTable.addCell(logoCell);
// Adding header
PdfPCell headerCell = new PdfPCell(new Phrase("FEDERATION FRANCE\nSOFT ARMORED FIGHTING", headerFont));
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
headerCell.setBorder(PdfPCell.NO_BORDER);
mainTable.addCell(headerCell);
document.add(mainTable);
Paragraph addr = new Paragraph("5 place de la Barreyre\n63320 Champeix", subHeaderFont);
addr.setAlignment(Element.ALIGN_CENTER);
addr.setSpacingAfter(2f);
document.add(addr);
Paragraph association = new Paragraph("Association loi 1901 W633001595\nSIRET 829 458 355 00015", smallFont);
association.setAlignment(Element.ALIGN_CENTER);
document.add(association);
// Adding spacing
document.add(new Paragraph("\n\n"));
// Adding attestation
PdfPTable attestationTable = new PdfPTable(1);
attestationTable.setWidthPercentage(60);
PdfPCell attestationCell = new PdfPCell(
new Phrase("ATTESTATION D'ADHESION\nSaison " + pdfData.saison + "-" + (pdfData.saison + 1),
bigFont));
attestationCell.setHorizontalAlignment(Element.ALIGN_CENTER);
attestationCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
attestationCell.setPadding(20f);
attestationTable.addCell(attestationCell);
document.add(attestationTable);
// Adding spacing
document.add(new Paragraph("\n\n"));
// Adding member details table
PdfPTable memberTable = new PdfPTable(2);
memberTable.setWidthPercentage(100);
memberTable.setWidths(new float[]{130, 300});
memberTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
// Adding member photo
Image memberPhoto;
if (pdfData.photo_file != null && pdfData.photo_file.exists()) {
memberPhoto = Image.getInstance(Files.readAllBytes(pdfData.photo_file.toPath()));
} else {
memberPhoto = Image.getInstance(
Objects.requireNonNull(getClass().getClassLoader().getResource("blank-profile-picture.png")));
}
memberPhoto.scaleToFit(120, 150);
PdfPCell photoCell = new PdfPCell(memberPhoto);
photoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
photoCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
photoCell.setRowspan(5);
photoCell.setBorder(PdfPCell.NO_BORDER);
memberTable.addCell(photoCell);
String[] cert;
if (pdfData.certificate != null && !pdfData.certificate.isBlank()) {
cert = pdfData.certificate.split("¤");
if (cert.length <= 1) {
cert = new String[]{pdfData.certificate, "--"};
} else {
try {
cert[1] = sdf.format(new SimpleDateFormat("yyyy-MM-dd").parse(cert[1]));
} catch (ParseException e) {
cert[1] = "--";
}
}
} else {
cert = new String[]{"--", "--"};
}
// Adding member details
memberTable.addCell(new Phrase("NOM : " + pdfData.lname.toUpperCase(), bodyFont));
memberTable.addCell(new Phrase("Prénom : " + pdfData.fname, bodyFont));
memberTable.addCell(new Phrase("Licence n° : " + pdfData.licence, bodyFont));
memberTable.addCell(new Phrase("Certificat médical par " + cert[0] + ", le " + cert[1], bodyFont));
memberTable.addCell(new Phrase("")); // Empty cell for spacing
document.add(memberTable);
// Adding spacing
document.add(new Paragraph("\n"));
Paragraph memberClub = new Paragraph("CLUB : " + pdfData.club.toUpperCase(), bodyFont);
document.add(memberClub);
Paragraph memberClubNumber = new Paragraph("N° club : " + pdfData.club_no, bodyFont);
document.add(memberClubNumber);
// Adding spacing
document.add(new Paragraph("\n"));
Paragraph memberBirthdate = new Paragraph("Date de naissance : " + pdfData.birth_date, bodyFont);
document.add(memberBirthdate);
Paragraph memberGender = new Paragraph("Sexe : " + pdfData.genre, bodyFont);
document.add(memberGender);
Paragraph memberAgeCategory = new Paragraph("Catégorie d'âge : " + pdfData.categorie, bodyFont);
document.add(memberAgeCategory);
// Adding spacing
document.add(new Paragraph("\n\n"));
// Adding attestation text
PdfPTable textTable = new PdfPTable(1);
textTable.setWidthPercentage(100);
PdfPCell textCell = new PdfPCell(new Phrase(
"""
Ce document atteste que ladhérent
- est valablement enregistré auprès de la FFSAF,
- est assuré dans sa pratique du Béhourd Léger et du Battle Arc en entraînement et en compétition.
Il peut donc sinscrire à tout tournoi organisé sous légide de la FFSAF sil remplit les éventuelles
conditions de qualification.
Il peut participer à tout entraînement dans un club affilié si celui ci autorise les visiteurs.""",
smallFont));
textCell.setHorizontalAlignment(Element.ALIGN_LEFT);
textCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
textCell.setBorder(PdfPCell.NO_BORDER);
textTable.addCell(textCell);
document.add(textTable);
// Close the document
document.close();
}
}

View File

@@ -0,0 +1,19 @@
package fr.titionfire;
import java.io.File;
import java.util.Date;
public class PdfData {
int saison;
int licence;
String fname;
String lname;
String club;
int club_no;
String categorie;
String genre;
String birth_date;
String certificate;
File photo_file;
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB