plan D fixed
This commit is contained in:
parent
afd7e9d941
commit
b500bfa6c1
2 changed files with 30 additions and 13 deletions
|
|
@ -51,6 +51,10 @@ class _ServicesAdapter:
|
||||||
def workflow(self):
|
def workflow(self):
|
||||||
return self._context.workflow
|
return self._context.workflow
|
||||||
|
|
||||||
|
@workflow.setter
|
||||||
|
def workflow(self, value):
|
||||||
|
self._context.workflow = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self):
|
def chat(self):
|
||||||
return self._get_service("chat")
|
return self._get_service("chat")
|
||||||
|
|
|
||||||
|
|
@ -247,13 +247,28 @@ class RendererPdf(BaseRenderer):
|
||||||
removed = False
|
removed = False
|
||||||
for idx, flowable in enumerate(story):
|
for idx, flowable in enumerate(story):
|
||||||
fRepr = repr(flowable)
|
fRepr = repr(flowable)
|
||||||
|
if "Image" in fRepr and hasattr(flowable, 'drawWidth') and hasattr(flowable, 'drawHeight'):
|
||||||
|
from reportlab.platypus import Image as ReportLabImage
|
||||||
|
if isinstance(flowable, ReportLabImage):
|
||||||
|
frameH = 650.0
|
||||||
|
frameW = 450.0
|
||||||
|
if flowable.drawHeight > frameH or flowable.drawWidth > frameW:
|
||||||
|
scaleW = frameW / flowable.drawWidth if flowable.drawWidth > frameW else 1.0
|
||||||
|
scaleH = frameH / flowable.drawHeight if flowable.drawHeight > frameH else 1.0
|
||||||
|
s = min(scaleW, scaleH) * 0.9
|
||||||
|
flowable.drawWidth = flowable.drawWidth * s
|
||||||
|
flowable.drawHeight = flowable.drawHeight * s
|
||||||
|
flowable._width = flowable.drawWidth
|
||||||
|
flowable._height = flowable.drawHeight
|
||||||
|
removed = True
|
||||||
|
break
|
||||||
if "Table" in fRepr and hasattr(flowable, '_cellvalues'):
|
if "Table" in fRepr and hasattr(flowable, '_cellvalues'):
|
||||||
try:
|
try:
|
||||||
nRows = len(flowable._cellvalues)
|
nRows = len(flowable._cellvalues)
|
||||||
nCols = len(flowable._cellvalues[0]) if flowable._cellvalues else 0
|
nCols = len(flowable._cellvalues[0]) if flowable._cellvalues else 0
|
||||||
if nRows == 1 and nCols == 1:
|
if nRows == 1 and nCols == 1:
|
||||||
errPara = Paragraph(
|
errPara = Paragraph(
|
||||||
"[Code block omitted — content too large for PDF page]",
|
"[Code block omitted - content too large for PDF page]",
|
||||||
self._createNormalStyle({}),
|
self._createNormalStyle({}),
|
||||||
)
|
)
|
||||||
story[idx] = errPara
|
story[idx] = errPara
|
||||||
|
|
@ -1078,20 +1093,18 @@ class RendererPdf(BaseRenderer):
|
||||||
pilImage = PILImage.open(imageStream)
|
pilImage = PILImage.open(imageStream)
|
||||||
originalWidth, originalHeight = pilImage.size
|
originalWidth, originalHeight = pilImage.size
|
||||||
|
|
||||||
# Calculate available page dimensions (A4 with margins: 72pt left/right, 72pt top, 18pt bottom)
|
|
||||||
pageWidth = A4[0] # 595.27 points
|
pageWidth = A4[0] # 595.27 points
|
||||||
pageHeight = A4[1] # 841.89 points
|
pageHeight = A4[1] # 841.89 points
|
||||||
leftMargin = 72
|
# Use page dimensions minus margins with generous safety buffer
|
||||||
rightMargin = 72
|
# A4 = 595.27 x 841.89 pt; frame = page - margins - internal padding
|
||||||
topMargin = 72
|
_us = getattr(self, '_unifiedStyle', None) or {}
|
||||||
bottomMargin = 18
|
_pageMgn = (_us.get('page') or {}).get('marginsPt') or {}
|
||||||
|
marginTop = _pageMgn.get('top', 60)
|
||||||
# Use actual frame dimensions from SimpleDocTemplate
|
marginBottom = _pageMgn.get('bottom', 60)
|
||||||
# Frame is smaller than page minus margins due to internal spacing
|
marginLeft = _pageMgn.get('left', 60)
|
||||||
# From error message: frame is 439.27559055118115 x 739.8897637795277
|
marginRight = _pageMgn.get('right', 60)
|
||||||
# Use conservative values with safety margin
|
availableWidth = pageWidth - marginLeft - marginRight - 20 # 20pt safety
|
||||||
availableWidth = 430.0 # Slightly smaller than frame width for safety
|
availableHeight = pageHeight - marginTop - marginBottom - 80 # 80pt safety for header/footer
|
||||||
availableHeight = 730.0 # Slightly smaller than frame height for safety
|
|
||||||
|
|
||||||
# Convert original image size from pixels to points
|
# Convert original image size from pixels to points
|
||||||
# PIL provides size in pixels, need to convert to points
|
# PIL provides size in pixels, need to convert to points
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue