Add Roboto font family and update PDF generation to use custom fonts
- Added Roboto font files to the Docker image and specified their location. - Updated the PDF generation code to use the Roboto font instead of Arial. - Enhanced the PDF output by including additional font styles (Bold, Italic, etc.) for better formatting. - Created a new directory for fonts in the Docker container to manage font files effectively.
This commit is contained in:
+2
-1
@@ -14,5 +14,6 @@ COPY . /app/
|
|||||||
RUN chmod +x /app/entrypoint.sh
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
RUN mkdir -pv /fonts
|
||||||
|
COPY tienda/static/fonts/ /fonts/
|
||||||
CMD ["/app/entrypoint.sh"]
|
CMD ["/app/entrypoint.sh"]
|
||||||
+12
-3
@@ -1,3 +1,6 @@
|
|||||||
|
import os
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from fpdf import FPDF
|
from fpdf import FPDF
|
||||||
import string, random
|
import string, random
|
||||||
class Recibo(FPDF):
|
class Recibo(FPDF):
|
||||||
@@ -13,8 +16,11 @@ class Recibo(FPDF):
|
|||||||
|
|
||||||
def generar_recibo(cliente: str, total: float, objetos: list, metodo_pago: str):
|
def generar_recibo(cliente: str, total: float, objetos: list, metodo_pago: str):
|
||||||
pdf = Recibo()
|
pdf = Recibo()
|
||||||
|
font_path = "/fonts/Roboto-Regular.ttf"
|
||||||
|
pdf.add_font('Roboto', '', '/fonts/Roboto-Regular.ttf')
|
||||||
|
pdf.add_font('Roboto', 'B', '/fonts/Roboto-Bold.ttf')
|
||||||
pdf.add_page()
|
pdf.add_page()
|
||||||
pdf.set_font("Arial", size=12)
|
pdf.set_font('Roboto', size=12)
|
||||||
|
|
||||||
pdf.cell(0, 10, f"Cliente: {cliente}", ln=True)
|
pdf.cell(0, 10, f"Cliente: {cliente}", ln=True)
|
||||||
pdf.cell(0, 10, f"")
|
pdf.cell(0, 10, f"")
|
||||||
@@ -23,7 +29,10 @@ def generar_recibo(cliente: str, total: float, objetos: list, metodo_pago: str):
|
|||||||
DATA.append(
|
DATA.append(
|
||||||
("Cant.", "Nombre", "Precio Unit.", "Subtotal")
|
("Cant.", "Nombre", "Precio Unit.", "Subtotal")
|
||||||
)
|
)
|
||||||
|
for i in objetos:
|
||||||
|
DATA.append(
|
||||||
|
(str(i["amount"]), str(i["product_name"]), str(i["price"]), str(float(i["price"])*int(i["amount"])))
|
||||||
|
)
|
||||||
pdf.cell(0, 10, "DETALLE DEL COBRO", ln=True, align='C')
|
pdf.cell(0, 10, "DETALLE DEL COBRO", ln=True, align='C')
|
||||||
pdf.ln(5)
|
pdf.ln(5)
|
||||||
|
|
||||||
@@ -33,7 +42,7 @@ def generar_recibo(cliente: str, total: float, objetos: list, metodo_pago: str):
|
|||||||
for datum in data_row:
|
for datum in data_row:
|
||||||
row.cell(datum)
|
row.cell(datum)
|
||||||
pdf.ln(5)
|
pdf.ln(5)
|
||||||
pdf.set_font("Arial", "B", 12)
|
pdf.set_font('Roboto', size=12)
|
||||||
pdf.cell(0, 10, f'TOTAL A PAGAR: {total} €', align="R")
|
pdf.cell(0, 10, f'TOTAL A PAGAR: {total} €', align="R")
|
||||||
return pdf.output(dest="S")
|
return pdf.output(dest="S")
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user