devZenaight commited on
Commit
06c3356
·
1 Parent(s): add8107

chart spacing

Browse files
app/DocumentGeneration/pdf_generator.py CHANGED
@@ -150,23 +150,12 @@ def calculate_real_page_numbers(request: ExportRequest, filtered_sections):
150
  if y_title > 25:
151
  temp_pdf.ln(3)
152
 
153
- # Add chart title
154
- temp_pdf.set_font("Arial", "B", 16)
155
- temp_pdf.set_text_color(0, 0, 0)
156
- temp_pdf.set_xy(25, y_title)
157
- temp_pdf.cell(0, 14, chart_info["title"], ln=True)
158
-
159
- # Add subtle line under chart title
160
- text_width = temp_pdf.get_string_width(chart_info["title"])
161
- line_width = min(text_width + 8, 160)
162
- temp_pdf.set_draw_color(221, 221, 221)
163
- temp_pdf.set_line_width(0.3)
164
- temp_pdf.line(25, y_title + 14, 25 + line_width, y_title + 14)
165
 
166
  # Add chart image
167
  img_width = 160 # Much larger chart width
168
  x = (210 - img_width) / 2
169
- y_img = y_title + 20
170
 
171
  # Save image to temp file
172
  with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_img:
@@ -430,6 +419,28 @@ def create_pdf_document(request: ExportRequest):
430
  content_text = re.sub(r'<!--CHARTDATASTART-->.*?<!--CHARTDATAEND-->', '', content_text, flags=re.DOTALL)
431
  content_text = re.sub(r'<!--CHARTDATASTART-->.*$', '', content_text, flags=re.DOTALL)
432
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
  # No need to filter section titles since we're not adding them manually
434
 
435
  # Skip enhance_subheadings_with_bold for grouped rendering to preserve ** markers
@@ -443,9 +454,9 @@ def create_pdf_document(request: ExportRequest):
443
  # Add placeholder text to prevent blank page
444
  pdf.multi_cell(160, 8, f"Content for {section.title} section is being processed...", align='L')
445
 
446
- # Add minimal spacer only if we have content
447
  if content_text and content_text.strip():
448
- pdf.ln(3) # Small space after content
449
 
450
  # ---- Charts for this section ----
451
  charts_added = 0 # IMPORTANT: initialize to avoid NameError
@@ -525,8 +536,7 @@ def create_pdf_document(request: ExportRequest):
525
  if y_title > 25: # If not at top of page, add minimal space
526
  pdf.ln(3) # Minimal spacing to fit more charts per page
527
 
528
- # Subheader (title) and subtle rule
529
- y_title = add_subheader(pdf, chart_info["title"], 16, y_title)
530
 
531
  # Centered image with larger dimensions for better visibility
532
  img_width = 160 # Much larger chart width for better visibility
 
150
  if y_title > 25:
151
  temp_pdf.ln(3)
152
 
153
+ # Chart title is already included in the chart itself, no need for separate title
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  # Add chart image
156
  img_width = 160 # Much larger chart width
157
  x = (210 - img_width) / 2
158
+ y_img = y_title
159
 
160
  # Save image to temp file
161
  with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_img:
 
419
  content_text = re.sub(r'<!--CHARTDATASTART-->.*?<!--CHARTDATAEND-->', '', content_text, flags=re.DOTALL)
420
  content_text = re.sub(r'<!--CHARTDATASTART-->.*$', '', content_text, flags=re.DOTALL)
421
 
422
+ # Remove chart titles from content to prevent duplicate headings
423
+ # Get chart titles for this section
424
+ section_charts = chart_info_map.get(section.title, [])
425
+ if not section_charts:
426
+ # Try case-insensitive match
427
+ for chart_source, charts in chart_info_map.items():
428
+ if chart_source.lower() == section.title.lower():
429
+ section_charts = charts
430
+ break
431
+
432
+ # Remove chart titles from content
433
+ for chart_info in section_charts:
434
+ chart_title = chart_info["title"]
435
+ # Remove various markdown heading formats for the chart title
436
+ patterns_to_remove = [
437
+ rf'^#+\s*{re.escape(chart_title)}\s*$', # # Title, ## Title, etc.
438
+ rf'^\*\*{re.escape(chart_title)}\*\*\s*$', # **Title**
439
+ rf'^{re.escape(chart_title)}\s*$', # Just the title
440
+ ]
441
+ for pattern in patterns_to_remove:
442
+ content_text = re.sub(pattern, '', content_text, flags=re.MULTILINE | re.IGNORECASE)
443
+
444
  # No need to filter section titles since we're not adding them manually
445
 
446
  # Skip enhance_subheadings_with_bold for grouped rendering to preserve ** markers
 
454
  # Add placeholder text to prevent blank page
455
  pdf.multi_cell(160, 8, f"Content for {section.title} section is being processed...", align='L')
456
 
457
+ # Add visual separation between content and charts
458
  if content_text and content_text.strip():
459
+ pdf.ln(15) # More generous spacing for better visual separation
460
 
461
  # ---- Charts for this section ----
462
  charts_added = 0 # IMPORTANT: initialize to avoid NameError
 
536
  if y_title > 25: # If not at top of page, add minimal space
537
  pdf.ln(3) # Minimal spacing to fit more charts per page
538
 
539
+ # Chart title is already included in the chart itself, no need for separate subheader
 
540
 
541
  # Centered image with larger dimensions for better visibility
542
  img_width = 160 # Much larger chart width for better visibility