feat: pallets and boxes for deals
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import os
|
||||
|
||||
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
|
||||
from reportlab.lib.units import mm
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
from reportlab.platypus import SimpleDocTemplate
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from constants import APP_PATH
|
||||
|
||||
|
||||
class BasePdfCardGenerator:
|
||||
def __init__(self, session: AsyncSession):
|
||||
self._session = session
|
||||
assets_folder = os.path.join(APP_PATH, 'assets')
|
||||
fonts_folder = os.path.join(assets_folder, 'fonts')
|
||||
font_file_path = os.path.join(fonts_folder, 'DejaVuSans.ttf')
|
||||
self.page_width = 58 * mm
|
||||
self.page_height = 40 * mm
|
||||
pdfmetrics.registerFont(TTFont('DejaVuSans', font_file_path))
|
||||
|
||||
self.styles = getSampleStyleSheet()
|
||||
self._set_small_paragraph_styles()
|
||||
self._set_medium_paragraph_styles()
|
||||
|
||||
def _set_small_paragraph_styles(self):
|
||||
common_paragraph_style = {
|
||||
"parent": self.styles['Normal'],
|
||||
"fontName": "DejaVuSans",
|
||||
"spaceAfter": 4,
|
||||
"fontSize": 9,
|
||||
}
|
||||
|
||||
self.small_style = ParagraphStyle(
|
||||
'Small',
|
||||
alignment=0,
|
||||
**common_paragraph_style,
|
||||
)
|
||||
|
||||
self.small_centered_style = ParagraphStyle(
|
||||
'SmallCentered',
|
||||
alignment=1,
|
||||
**common_paragraph_style,
|
||||
)
|
||||
|
||||
def _set_medium_paragraph_styles(self):
|
||||
self.medium_style = ParagraphStyle(
|
||||
'Medium',
|
||||
parent=self.styles['Normal'],
|
||||
fontName="DejaVuSans",
|
||||
spaceAfter=6,
|
||||
fontSize=12,
|
||||
alignment=0,
|
||||
)
|
||||
|
||||
def _create_doc(self, buffer):
|
||||
return SimpleDocTemplate(
|
||||
buffer,
|
||||
pagesize=(self.page_width, self.page_height),
|
||||
rightMargin=1,
|
||||
leftMargin=1,
|
||||
topMargin=1,
|
||||
bottomMargin=1
|
||||
)
|
||||
Reference in New Issue
Block a user