Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
a68b9839f5 | |
|
da49c89d15 |
lib
debugger-app-3.0.4.jarfontbox-3.0.4.jarpdfbox-3.0.4.jarpdfbox-app-3.0.4.jarpdfbox-tools-3.0.4.jarpreflight-app-3.0.4.jar
pom.xmlsrc/main
java/org/example/saladeconciertos
resources
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
pom.xml
2
pom.xml
|
@ -58,7 +58,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.24</version>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -13,6 +13,7 @@ import javafx.scene.layout.VBox;
|
|||
import javafx.stage.Stage;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.DriverManager;
|
||||
|
@ -184,10 +185,10 @@ public class EscogerEvento {
|
|||
alert.showAndWait().ifPresent(response -> {
|
||||
if (response == buttonTypePDF) {
|
||||
// Generar el PDF del reporte usando la clase PDFGenerator
|
||||
String qrImagePath = "src/main/resources/qrcode.png"; // Cambia esto por la ruta de tu imagen QR
|
||||
InputStream qrImageStream = getClass().getResourceAsStream("/qrcode.png"); // Cambia esto por la ruta de tu imagen QR
|
||||
String timestamp = new java.text.SimpleDateFormat("yyyy-MM-dd HH_mm").format(new java.util.Date());
|
||||
String pdfFileName = "Reporte_"+eventName.replace(" ", "_")+"_" + timestamp + ".pdf";
|
||||
PDFGenerator.generarPDF(eventName, "", "", 0.0, qrImagePath, String.join("\n", seatDetails), pdfFileName);
|
||||
PDFGenerator.generarPDF(eventName, "", "", 0.0, qrImageStream, String.join("\n", seatDetails), pdfFileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,14 +4,16 @@ import org.apache.pdfbox.pdmodel.PDDocument;
|
|||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
|
||||
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class PDFGenerator {
|
||||
|
||||
// Método para generar un PDF con los detalles del reporte de ventas
|
||||
public static void generarPDF(String eventName, String eventDate, String clientName, double totalPrice, String qrImagePath, String ticketDetails, String pdfFileName) {
|
||||
public static void generarPDF(String eventName, String eventDate, String clientName, double totalPrice, InputStream qrImageStream, String ticketDetails, String pdfFileName) {
|
||||
// Ruta donde se guardará el PDF
|
||||
String downloadsPath = System.getProperty("user.home") + "/Downloads/";
|
||||
String pdfPath = downloadsPath + pdfFileName;
|
||||
|
@ -24,36 +26,48 @@ public class PDFGenerator {
|
|||
// Crear un flujo de contenido para la página
|
||||
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
|
||||
// Configurar la fuente y el tamaño para el título del evento
|
||||
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 24);
|
||||
PDType1Font fontBold = new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD);
|
||||
contentStream.setFont(fontBold, 24);
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(50, 750);
|
||||
contentStream.showText(eventName);
|
||||
contentStream.endText();
|
||||
|
||||
// Configurar la fuente y el tamaño para la fecha del evento
|
||||
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 18);
|
||||
contentStream.setFont(fontBold, 18);
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(50, 720);
|
||||
contentStream.showText(eventDate);
|
||||
contentStream.endText();
|
||||
|
||||
// Configurar la fuente y el tamaño para el contenido del reporte
|
||||
contentStream.setFont(PDType1Font.HELVETICA, 12);
|
||||
PDType1Font fontRegular = new PDType1Font(Standard14Fonts.FontName.HELVETICA);
|
||||
contentStream.setFont(fontRegular, 12);
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(50, 680);
|
||||
float textY = 680; // Posición Y inicial del contenido
|
||||
contentStream.newLineAtOffset(50, textY);
|
||||
|
||||
// Dividir el texto en líneas y escribir cada línea por separado
|
||||
String[] lines = ticketDetails.split("\n");
|
||||
for (String line : lines) {
|
||||
contentStream.showText(line);
|
||||
contentStream.newLineAtOffset(0, -15); // Mover hacia abajo para la siguiente línea
|
||||
textY -= 15; // Mover hacia abajo para la siguiente línea
|
||||
contentStream.newLineAtOffset(0, -15);
|
||||
}
|
||||
|
||||
contentStream.endText();
|
||||
|
||||
// Calcular la posición Y de la imagen (teniendo en cuenta su altura)
|
||||
float imageHeight = 150; // Altura de la imagen
|
||||
float imageY = textY - 50 - imageHeight; // 50 unidades de margen + altura de la imagen
|
||||
|
||||
// Agregar la imagen del código QR (si existe)
|
||||
if (qrImagePath != null && !qrImagePath.isEmpty()) {
|
||||
PDImageXObject qrImage = PDImageXObject.createFromFile(qrImagePath, document);
|
||||
contentStream.drawImage(qrImage, 50, 50, 150, 150); // Ajusta la posición y el tamaño de la imagen
|
||||
if (qrImageStream != null) {
|
||||
try {
|
||||
PDImageXObject qrImage = PDImageXObject.createFromByteArray(document, qrImageStream.readAllBytes(), "qrcode");
|
||||
contentStream.drawImage(qrImage, 50, imageY, 150, 150); // Ajusta la posición y el tamaño
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error al cargar la imagen QR: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +81,7 @@ public class PDFGenerator {
|
|||
}
|
||||
|
||||
// Método para generar un PDF con los detalles del ticket de compra
|
||||
public static void generarTicketPDF(String eventName, String eventDate, String clientName, double totalPrice, String qrImagePath, String ticketDetails, String pdfFileName) {
|
||||
public static void generarTicketPDF(String eventName, String eventDate, String clientName, double totalPrice, InputStream qrImageStream, String ticketDetails, String pdfFileName) {
|
||||
// Ruta donde se guardará el PDF
|
||||
String downloadsPath = System.getProperty("user.home") + "/Downloads/";
|
||||
String pdfPath = downloadsPath + pdfFileName;
|
||||
|
@ -80,30 +94,41 @@ public class PDFGenerator {
|
|||
// Crear un flujo de contenido para la página
|
||||
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
|
||||
// Configurar la fuente y el tamaño para el título
|
||||
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 20);
|
||||
PDType1Font fontBold = new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD);
|
||||
contentStream.setFont(fontBold, 20);
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(50, 750);
|
||||
contentStream.showText("Ticket de Compra");
|
||||
contentStream.endText();
|
||||
|
||||
// Configurar la fuente y el tamaño para el contenido
|
||||
contentStream.setFont(PDType1Font.HELVETICA, 12);
|
||||
PDType1Font fontRegular = new PDType1Font(Standard14Fonts.FontName.HELVETICA);
|
||||
contentStream.setFont(fontRegular, 12);
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(50, 700);
|
||||
float textY = 700; // Posición Y inicial del contenido
|
||||
contentStream.newLineAtOffset(50, textY);
|
||||
|
||||
// Dividir el texto en líneas y escribir cada línea por separado
|
||||
String[] lines = ticketDetails.split("\n");
|
||||
for (String line : lines) {
|
||||
contentStream.showText(line);
|
||||
contentStream.newLineAtOffset(0, -15); // Mover hacia abajo para la siguiente línea
|
||||
textY -= 15; // Mover hacia abajo para la siguiente línea
|
||||
contentStream.newLineAtOffset(0, -15);
|
||||
}
|
||||
|
||||
contentStream.endText();
|
||||
|
||||
// Calcular la posición Y de la imagen (teniendo en cuenta su altura)
|
||||
float imageHeight = 150; // Altura de la imagen
|
||||
float imageY = textY - 50 - imageHeight; // 50 unidades de margen + altura de la imagen
|
||||
|
||||
// Agregar la imagen del código QR
|
||||
if (qrImagePath != null && !qrImagePath.isEmpty()) {
|
||||
PDImageXObject qrImage = PDImageXObject.createFromFile(qrImagePath, document);
|
||||
contentStream.drawImage(qrImage, 50, 50, 150, 150); // Ajusta la posición y el tamaño de la imagen
|
||||
if (qrImageStream != null) {
|
||||
try {
|
||||
PDImageXObject qrImage = PDImageXObject.createFromByteArray(document, qrImageStream.readAllBytes(), "qrcode");
|
||||
contentStream.drawImage(qrImage, 50, imageY, 150, 150); // Ajusta la posición y el tamaño
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error al cargar la imagen QR: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,9 +97,9 @@ public class VentaBoletos extends Application {
|
|||
titleLabel.getStyleClass().add("title");
|
||||
|
||||
// Agregar el logo de la aplicación
|
||||
ImageView logo = new ImageView(new Image(getClass().getResourceAsStream("/logo.png")));
|
||||
logo.setFitWidth(100);
|
||||
logo.setFitHeight(100);
|
||||
ImageView logo = new ImageView(new Image(getClass().getResourceAsStream("/escenario.png")));
|
||||
logo.setFitWidth(500);
|
||||
logo.setFitHeight(130);
|
||||
|
||||
// Crear y configurar el label de bienvenida
|
||||
Label welcomeLabel = new Label("Seleccione sus asientos");
|
||||
|
@ -278,7 +278,9 @@ public class VentaBoletos extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
public static void main(String[] args) {launch(args);
|
||||
System.setProperty("org.apache.pdfbox.rendering.UsePureJavaCMYK", "true");
|
||||
System.setProperty("org.apache.pdfbox.rendering.UsePureJavaRendering", "true");
|
||||
System.setProperty("org.apache.pdfbox.base.disableFontCache", "true");
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ import javafx.scene.layout.VBox;
|
|||
import javafx.stage.Stage;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
@ -251,9 +253,9 @@ public class VentanaPago {
|
|||
actualizarEstadoBoletos(selectedSeats, ventaBoletos.getEventId()); // Cambia el idevento según corresponda
|
||||
|
||||
// Generar el PDF del ticket usando la clase PDFGenerator
|
||||
String qrImagePath = "src/main/resources/qrcode.png"; // Ruta de tu imagen QR
|
||||
InputStream qrImageStream = getClass().getResourceAsStream("/qrcode.png"); // Ruta de tu imagen QR
|
||||
String pdfFileName = "ticket_" + System.currentTimeMillis() + ".pdf";
|
||||
PDFGenerator.generarTicketPDF(eventName, eventDate, clientName, totalPrice, qrImagePath, ticketDetails.toString(), pdfFileName);
|
||||
PDFGenerator.generarTicketPDF(eventName, eventDate, clientName, totalPrice, qrImageStream, ticketDetails.toString(), pdfFileName);
|
||||
|
||||
// Mostrar alerta de que el ticket fue guardado
|
||||
mostrarAlertaTicketGuardado(pdfFileName, paymentLayout);
|
||||
|
@ -261,7 +263,7 @@ public class VentanaPago {
|
|||
|
||||
private void generarPDF(String clientName, List<Integer> selectedSeats, Map<Integer, Double> seatPrices, String eventName, String eventDate, double totalPrice, String paymentMethod) {
|
||||
// Generar el PDF del ticket usando la clase PDFGenerator
|
||||
String qrImagePath = "src/main/resources/qrcode.png"; // Ruta de tu imagen QR
|
||||
InputStream qrImageStream = getClass().getResourceAsStream("/qrcode.png"); // Ruta de tu imagen QR
|
||||
StringBuilder ticketDetails = new StringBuilder();
|
||||
ticketDetails.append("Evento: ").append(eventName).append("\n");
|
||||
ticketDetails.append("Fecha: ").append(new SimpleDateFormat("dd-MM-yyyy").format(new Date())).append("\n");
|
||||
|
@ -275,7 +277,7 @@ public class VentanaPago {
|
|||
ticketDetails.append("\nTotal: $").append(String.format("%.2f", totalPrice));
|
||||
|
||||
String pdfFileName = "ticket_" + System.currentTimeMillis() + ".pdf";
|
||||
PDFGenerator.generarTicketPDF(eventName, eventDate, clientName, totalPrice, qrImagePath, ticketDetails.toString(), pdfFileName);
|
||||
PDFGenerator.generarTicketPDF(eventName, eventDate, clientName, totalPrice, qrImageStream, ticketDetails.toString(), pdfFileName);
|
||||
}
|
||||
|
||||
private void actualizarEstadoBoletos(List<Integer> selectedSeats, int idevento) {
|
||||
|
|
Binary file not shown.
After ![]() (image error) Size: 15 KiB |
Loading…
Reference in New Issue