Skip to content

Fix DOCX employee directory rendering - #161

Merged
shps951023 merged 1 commit into
mainfrom
fix/docx-employee-directory-rendering
Sep 8, 2026
Merged

Fix DOCX employee directory rendering#161
shps951023 merged 1 commit into
mainfrom
fix/docx-employee-directory-rendering

Conversation

@shps951023

@shps951023 shps951023 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • preserve DOCX paragraph border spacing and render empty bordered separators consistently
  • align image-only paragraphs and Calibri bold heading baselines with the reference output
  • embed the matching Calibri bold face when available
  • add focused converter regression coverage and update both benchmark page images

Validation

  • dotnet test tests/MiniPdf.Tests: 192/192 passed
  • scripts/Run-Benchmark_docx.ps1 -Filter "employee_directory_with_photo"
  • benchmark improved from 0.6952 to 0.9988 overall
  • text similarity: 1.0; pages: 2/2; visual average: 0.9969

Summary by CodeRabbit

  • Bug Fixes

    • Improved DOCX-to-PDF paragraph border rendering, including border spacing and empty bordered paragraphs.
    • Corrected paragraph spacing and page-position handling, especially for first and empty paragraphs.
    • Improved alignment of images in image-only paragraphs and prevented images from extending above the top margin.
    • Improved baseline alignment for bold heading text.
    • Improved bold Calibri font rendering and embedding.
    • Corrected a document conversion case to match the expected two-page layout and visual output.
  • Tests

    • Added coverage for paragraph spacing, bordered paragraphs, and image alignment.

Copilot AI lite review requested due to automatic review settings September 8, 2026 15:40
@shps951023
shps951023 merged commit 86b231a into main Sep 8, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 96e889cb-cc5a-4c1f-90aa-f871eed5c20f

📥 Commits

Reviewing files that changed from the base of the PR and between 0383290 and e7abcf6.

⛔ Files ignored due to path filters (2)
  • tests/MiniPdf.Benchmark/reports_docx/images/docx_classic34_employee_directory_with_photo_p1_minipdf.png is excluded by !**/*.png
  • tests/MiniPdf.Benchmark/reports_docx/images/docx_classic34_employee_directory_with_photo_p2_minipdf.png is excluded by !**/*.png
📒 Files selected for processing (5)
  • src/MiniPdf/DocxReader.cs
  • src/MiniPdf/DocxToPdfConverter.cs
  • src/MiniPdf/PdfWriter.cs
  • tests/MiniPdf.Benchmark/reports_docx/comparison_report.json
  • tests/MiniPdf.Tests/DocxToPdfConverterTests.cs

📝 Walkthrough

Walkthrough

The change preserves DOCX border spacing and paragraph offsets, aligns inline images and selected heading text, and embeds bold Calibri through the Unicode font path. Tests and benchmark data validate paragraph layout and converted output.

Changes

DOCX paragraph rendering

Layer / File(s) Summary
Paragraph border spacing and layout
src/MiniPdf/DocxReader.cs, src/MiniPdf/DocxToPdfConverter.cs, tests/MiniPdf.Tests/DocxToPdfConverterTests.cs
Border edges now parse w:space. Paragraph borders use per-edge spacing. Empty bordered paragraphs preserve spacing-before and adjust their layout advance. First-paragraph spacing updates CurrentY directly.
Inline image and heading placement
src/MiniPdf/DocxToPdfConverter.cs, tests/MiniPdf.Tests/DocxToPdfConverterTests.cs, tests/MiniPdf.Benchmark/reports_docx/comparison_report.json
Image-only paragraphs apply a vertical offset and top-margin clamp. Bold Calibri headings receive a baseline offset. Tests and benchmark results cover the updated placement.
Bold Calibri font embedding
src/MiniPdf/PdfWriter.cs
Bold Calibri blocks now use the preferred-font embedding path, collect WinAnsi code points, and resolve calibrib.ttf.

Estimated code review effort: 3 (Moderate) | ~25 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/docx-employee-directory-rendering

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Border spacing and border-space parsing changes introduce correctness risks (corner-join alignment and locale-dependent parsing) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves DOCX-to-PDF fidelity for the “employee directory with photo” scenario by refining paragraph spacing/border rendering, image-only paragraph layout, and Calibri bold font embedding, plus adding targeted regression tests and updating benchmark artifacts.

Changes:

  • Preserve first-paragraph spacing-before at the top of page 1 and keep empty bordered separator paragraphs consistent (including border spacing behavior).
  • Adjust inline image-only paragraph vertical alignment and tweak Calibri bold heading baseline alignment.
  • Embed Calibri Bold when available and add/refresh focused regression tests + benchmark report updates.
File summaries
File Description
tests/MiniPdf.Tests/DocxToPdfConverterTests.cs Adds focused regression tests for spacing-before, empty bordered paragraphs, and image-only paragraph alignment.
tests/MiniPdf.Benchmark/reports_docx/comparison_report.json Updates benchmark report metrics/artifacts to reflect improved rendering scores.
src/MiniPdf/PdfWriter.cs Adds preferred-font embedding gating logic (including Calibri bold embedding) and maps “Calibri Bold” to a system font file.
src/MiniPdf/DocxToPdfConverter.cs Updates paragraph spacing behavior for the very first paragraph, renders borders for empty bordered paragraphs, adjusts image rendering API and heading baseline.
src/MiniPdf/DocxReader.cs Parses paragraph border spacing (w:space) into the border model.
Review details
  • Files reviewed: 5/7 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/MiniPdf/DocxReader.cs
Comment on lines +1770 to +1772
var space = float.TryParse(el.Attribute(W + "space")?.Value, out var parsedSpace)
? parsedSpace
: 0f;
Comment on lines +2018 to +2020
if (borders.Left != null)
state.CurrentPage.AddLine(paragraphLeft - borders.Left.Space, paragraphTop + borders.Left.Space,
paragraphLeft - borders.Left.Space, paragraphBottom - borders.Left.Space, borders.Left.Color, borders.Left.Width);
Comment on lines +2021 to +2023
if (borders.Right != null)
state.CurrentPage.AddLine(paragraphRight + borders.Right.Space, paragraphTop + borders.Right.Space,
paragraphRight + borders.Right.Space, paragraphBottom - borders.Right.Space, borders.Right.Color, borders.Right.Width);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants