fix: Replace Prawn with Grover for PDF ticket generation
- Replace Prawn PDF generation with Grover (Chrome headless) for better compatibility - Add HTML-based ticket template with embedded CSS styling - Implement robust Grover loading with fallback to HTML download - Add QR code generation methods to Ticket model - Remove legacy TicketPdfGenerator service and tests - Update PDF generation in TicketsController with proper error handling The new implementation provides: - Better HTML/CSS rendering for ticket layouts - More reliable PDF generation using Chrome engine - Fallback mechanism for better user experience - Cleaner separation of template rendering and PDF conversion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
11
app/views/layouts/pdf.html.erb
Normal file
11
app/views/layouts/pdf.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><%= yield :title %></title>
|
||||
<%= stylesheet_link_tag "pdf" %>
|
||||
</head>
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
98
app/views/tickets/_pdf_ticket.html.erb
Normal file
98
app/views/tickets/_pdf_ticket.html.erb
Normal file
@@ -0,0 +1,98 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ticket #<%= ticket.id %></title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000000;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.ticket-container {
|
||||
max-width: 350px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 10px;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
color: #2D1B69;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.event-name {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.event-name h2 {
|
||||
color: #000000;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ticket-info {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.qr-code-section {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.qr-code-container svg {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ticket-container">
|
||||
<div class="header">
|
||||
<h1>ApéroNight</h1>
|
||||
</div>
|
||||
|
||||
<div class="event-name">
|
||||
<h2><%= ticket.event.name %></h2>
|
||||
</div>
|
||||
|
||||
<div class="ticket-info">
|
||||
<div class="info-row">
|
||||
<strong>Ticket Holder:</strong> <%= ticket.first_name %> <%= ticket.last_name %>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<strong>Ticket Type:</strong> <%= ticket.ticket_type.name %>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<strong>Price:</strong> €<%= ticket.price_euros %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="qr-code-section">
|
||||
<div class="qr-code-container">
|
||||
<%= raw ticket.generate_qr_svg %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
14
app/views/tickets/show.pdf.erb
Normal file
14
app/views/tickets/show.pdf.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<% content_for :title, "Ticket ##{ticket.id}" %>
|
||||
|
||||
<div style="font-family: Arial, sans-serif; max-width: 350px; margin: 20px auto; padding: 20px; border: 1px solid #ccc;">
|
||||
<div style="text-align: center;">
|
||||
<h1 style="color: #2D1B69;">ApéroNight</h1>
|
||||
</div>
|
||||
<h2><%= ticket.event.name %></h2>
|
||||
<p>Ticket Holder: <%= ticket.first_name %> <%= ticket.last_name %></p>
|
||||
<p>Ticket Type: <%= ticket.ticket_type.name %></p>
|
||||
<p>Price: €<%= ticket.price_euros %></p>
|
||||
<div style="text-align: center; margin-top: 20px;">
|
||||
<%= raw ticket.generate_qr_svg %>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user