feat: the print PDF ends in a footer naming the order, item, date and length
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 3m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 3m55s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped
Dropstar's item 4 (2026-10-21): the PDF had no text at all, so a sheet cut off or dropped in the room was guesswork. A 1,5 cm band after the last piece, outside the billed length and never over artwork, carries one line in black with no background: DROPSTAR · Pedido DTF-123 · Item 1/2 · 21/10/2026 · 0,90 m The order is named by its Kanban number, the purchase order Tiny keeps, since Tiny's own number may not exist yet when the PDF is made. The brand is text until Dropstar sends the logo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -396,10 +396,32 @@ def check_layout(item, sizes, vector=()):
|
||||
return lowest
|
||||
|
||||
|
||||
def render(item, files, out, title):
|
||||
# The footer (Dropstar, 2026-10-21): a 1,5 cm band after the last piece with one
|
||||
# line of black text on no background, saying which order, item, date and length
|
||||
# the sheet is, so a sheet cut off or dropped in the room is still known. The band
|
||||
# is outside the billed length: the page grows by it and never covers artwork.
|
||||
FOOTER_CM = Decimal('1.5')
|
||||
FOOTER_PT = 18
|
||||
FOOTER_FONTS = {'F1': 'Helvetica-Bold', 'F2': 'Helvetica'}
|
||||
|
||||
|
||||
def footer_commands(text):
|
||||
"""The footer's line, its first part (the brand) in bold, 0,5 cm from the left."""
|
||||
brand, _, rest = text.partition(' · ')
|
||||
def literal(value):
|
||||
raw = value.encode('cp1252', 'replace')
|
||||
return b'(' + raw.replace(b'\\', b'\\\\').replace(b'(', b'\\(').replace(b')', b'\\)') + b')'
|
||||
x = 0.5 * PT_PER_CM
|
||||
y = (float(FOOTER_CM) * PT_PER_CM - FOOTER_PT * 0.7) / 2
|
||||
return (b'q 0 g BT /F1 %d Tf %s %s Td %s Tj /F2 %d Tf %s Tj ET Q\n'
|
||||
% (FOOTER_PT, serialize(x), serialize(y), literal(brand), FOOTER_PT, literal(' · ' + rest if rest else '')))
|
||||
|
||||
|
||||
def render(item, files, out, title, footer=None):
|
||||
"""Write the PDF for one approved order item.
|
||||
|
||||
`files` maps each source index to (local path, original name). Returns the
|
||||
`files` maps each source index to (local path, original name). With
|
||||
`footer`, the page gets the footer band and that line in it. Returns the
|
||||
evidence the Kanban shows: page size, what was billed, and the lowest DPI.
|
||||
|
||||
Raster sources are written by the streaming writer above. PDF sources are
|
||||
@@ -418,12 +440,13 @@ def render(item, files, out, title):
|
||||
lowest_dpi = check_layout(item, [source.size for source in sources], vector)
|
||||
|
||||
width_pt = float(production['film_width_cm']) * PT_PER_CM
|
||||
height_pt = float(production['height_cm']) * PT_PER_CM
|
||||
page_cm = Decimal(str(production['height_cm'])) + (FOOTER_CM if footer else 0)
|
||||
height_pt = float(page_cm) * PT_PER_CM
|
||||
unit = max(1, math.ceil(max(width_pt, height_pt) / MAX_PAGE_PT))
|
||||
|
||||
first = tempfile.TemporaryFile() if vector else out
|
||||
try:
|
||||
write_rasters(production, sources, first, title, width_pt, height_pt, unit)
|
||||
write_rasters(production, sources, first, title, width_pt, height_pt, unit, footer)
|
||||
if vector:
|
||||
first.seek(0)
|
||||
add_vector_pages(production, sources, first, out, height_pt)
|
||||
@@ -435,6 +458,8 @@ def render(item, files, out, title):
|
||||
source.close()
|
||||
return {'film_width_cm': str(production['film_width_cm']),
|
||||
'height_cm': str(production['height_cm']),
|
||||
'page_height_cm': str(page_cm),
|
||||
'footer': footer,
|
||||
'billed_metres': str(item['billed_metres']),
|
||||
'placements': len(production['placements']),
|
||||
'sources': len(sources),
|
||||
@@ -443,7 +468,7 @@ def render(item, files, out, title):
|
||||
'user_unit': unit}
|
||||
|
||||
|
||||
def write_rasters(production, sources, out, title, width_pt, height_pt, unit):
|
||||
def write_rasters(production, sources, out, title, width_pt, height_pt, unit, footer=None):
|
||||
pdf = PdfWriter(out)
|
||||
images = {index: source.embed(pdf) for index, source in enumerate(sources)
|
||||
if isinstance(source, SourceImage)}
|
||||
@@ -456,12 +481,16 @@ def write_rasters(production, sources, out, title, width_pt, height_pt, unit):
|
||||
matrix = placement_matrix(placement, height_pt)
|
||||
commands.append(b'q ' + b' '.join(serialize(v) for v in matrix) +
|
||||
b' cm /Im%d Do Q\n' % placement['source_index'])
|
||||
resources = {'XObject': {f'Im{index}': ref for index, ref in images.items()}}
|
||||
if footer:
|
||||
commands.append(footer_commands(footer))
|
||||
resources['Font'] = {key: {'Type': Name('Font'), 'Subtype': Name('Type1'), 'BaseFont': Name(font),
|
||||
'Encoding': Name('WinAnsiEncoding')} for key, font in FOOTER_FONTS.items()}
|
||||
content = pdf.stream({'Filter': Name('FlateDecode')}, deflate(commands))
|
||||
pages = pdf.alloc()
|
||||
page_box = [0, 0, width_pt / unit, height_pt / unit]
|
||||
page = {'Type': Name('Page'), 'Parent': pages, 'MediaBox': page_box, 'TrimBox': page_box,
|
||||
'Resources': {'XObject': {f'Im{index}': ref for index, ref in images.items()}},
|
||||
'Contents': content}
|
||||
'Resources': resources, 'Contents': content}
|
||||
if unit > 1:
|
||||
page['UserUnit'] = unit
|
||||
page_ref = pdf.obj(page)
|
||||
|
||||
Reference in New Issue
Block a user