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)
|
||||
|
||||
@@ -21,6 +21,8 @@ import os
|
||||
import tempfile
|
||||
import time
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
from zoneinfo import ZoneInfo
|
||||
from uuid import NAMESPACE_URL, UUID, uuid4, uuid5
|
||||
|
||||
from psycopg.types.json import Jsonb
|
||||
@@ -28,6 +30,9 @@ from psycopg.types.json import Jsonb
|
||||
from .core.auth import audit
|
||||
from .core.db import connect
|
||||
from .printfile import Unsupported, render
|
||||
from .tiny import purchase_order
|
||||
|
||||
LOCAL = ZoneInfo('America/Sao_Paulo')
|
||||
|
||||
CLAIM_TIMEOUT = timedelta(minutes=15)
|
||||
MAX_ATTEMPTS = 3
|
||||
@@ -55,7 +60,7 @@ def queue(c, order_id, items, only_missing=False):
|
||||
|
||||
|
||||
def claim(c):
|
||||
return c.execute('''SELECT p.*, o.snapshot, o.number FROM dtf_local.print_files p
|
||||
return c.execute('''SELECT p.*, o.snapshot, o.number, o.created_at AS ordered_at FROM dtf_local.print_files p
|
||||
JOIN dtf_local.orders o ON o.id=p.order_id
|
||||
WHERE p.status='pending' OR (p.status='rendering' AND p.claimed_at < now()-%s)
|
||||
ORDER BY p.created_at FOR UPDATE OF p SKIP LOCKED LIMIT 1''', (CLAIM_TIMEOUT,)).fetchone()
|
||||
@@ -137,6 +142,17 @@ def whole_sheet(item, uploads):
|
||||
return row
|
||||
|
||||
|
||||
def footer(job, item):
|
||||
"""The print file's footer line: DROPSTAR · Pedido DTF-123 · Item 1/2 ·
|
||||
21/10/2026 · 0,90 m. The order is named by its Kanban number, which Tiny
|
||||
keeps as the purchase order; the length is the one billed."""
|
||||
count = len(job['snapshot']['items'])
|
||||
day = job['ordered_at'].astimezone(LOCAL).strftime('%d/%m/%Y')
|
||||
billed = f"{Decimal(str(item['billed_metres'])):.2f}".replace('.', ',')
|
||||
return ' · '.join(('DROPSTAR', f'Pedido {purchase_order(job["number"])}',
|
||||
f'Item {job["item_index"] + 1}/{count}', day, f'{billed} m'))
|
||||
|
||||
|
||||
def produce(storage, job, item, uploads):
|
||||
"""Fetch the item's artwork and render it. Returns (pdf path, name, size, evidence)."""
|
||||
for upload_id in item['uploads']:
|
||||
@@ -156,7 +172,8 @@ def produce(storage, job, item, uploads):
|
||||
handle, output = tempfile.mkstemp(prefix='print-', suffix='.pdf')
|
||||
try:
|
||||
with os.fdopen(handle, 'wb') as out:
|
||||
detail = render(item, files, out, f'Pedido {number} - item {job["item_index"] + 1}')
|
||||
detail = render(item, files, out, f'Pedido {number} - item {job["item_index"] + 1}',
|
||||
footer=footer(job, item))
|
||||
except BaseException:
|
||||
os.unlink(output)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user