Skip to content

#381 Fix list item wrapping and alignment in PDFs#399

Open
Delberin-Ali wants to merge 1 commit intomainfrom
381-pdf-generation-presentation-of-bullets
Open

#381 Fix list item wrapping and alignment in PDFs#399
Delberin-Ali wants to merge 1 commit intomainfrom
381-pdf-generation-presentation-of-bullets

Conversation

@Delberin-Ali
Copy link
Collaborator

No description provided.

@Delberin-Ali Delberin-Ali requested review from Copilot and dgruntz July 10, 2025 08:26
@Delberin-Ali Delberin-Ali self-assigned this Jul 10, 2025
@Delberin-Ali Delberin-Ali linked an issue Jul 10, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the ToLinkedParagraph method to detect and properly wrap alphabetical, unordered, and numeric list items when rendering PDFs, aiming to fix wrapping and alignment issues.

  • Added detection for contiguous list lines (alpha, unordered, numeric) and grouping into iTextSharp List objects.
  • Refactored line iteration and URL handling to support list and non-list paragraphs uniformly.
  • Updated paragraph and list formatting (spacing, leading, indentation).
Comments suppressed due to low confidence (1)

ProStudCreator/StringExtensions.cs:413

  • The List type is ambiguous and may conflict with System.Collections.Generic.List<T>. Consider using the full namespace (e.g., iTextSharp.text.List) or an alias to clarify intent.
            List currentList = null;

Comment on lines +430 to 450
if (lines.Length >= 3)
{
paragraphs.Add(new Paragraph("\n", _font));
continue;
if (listUnordered.IsMatch(currentLine))
{
if ((i < lines.Length - 1 && listUnordered.IsMatch(lines[i + 1])) ||
(i > 0 && listUnordered.IsMatch(lines[i - 1])))
isUnorderedList = true;
}
else if (listAlpha.IsMatch(currentLine))
{
if ((i < lines.Length - 1 && listAlpha.IsMatch(lines[i + 1])) ||
(i > 0 && listAlpha.IsMatch(lines[i - 1])))
isAlphaList = true;
}
else if (listNumeric.IsMatch(currentLine))
{
if ((i < lines.Length - 1 && listNumeric.IsMatch(lines[i + 1])) ||
(i > 0 && listNumeric.IsMatch(lines[i - 1])))
isNumericList = true;
}
}
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

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

Requiring lines.Length >= 3 prevents two‐item lists from being recognized. Instead, detect list sequences by checking only the current and adjacent lines without a global length threshold.

Copilot uses AI. Check for mistakes.
}
else if (isUnorderedList)
{
currentLine = currentLine.TrimStart('*', '-', 'o', ' ');
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

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

Using TrimStart with 'o' will strip all leading 'o' characters, which may remove valid content in some items. Consider using a regex or StartsWith + Substring to remove only the list marker.

Suggested change
currentLine = currentLine.TrimStart('*', '-', 'o', ' ');
currentLine = Regex.Replace(currentLine, @"^(?:\*|-|o)\s+", "");

Copilot uses AI. Check for mistakes.
Comment on lines +529 to +531
currentList.First = 1 + listIndexOffset - currentList.Size;
var item = new ListItem(para);
item.SpacingAfter = 1f;
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

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

The calculation for First may misalign numbering when items are added. It’s clearer to set First once on list creation based on the first item's index, rather than adjusting by Size on each iteration.

Suggested change
currentList.First = 1 + listIndexOffset - currentList.Size;
var item = new ListItem(para);
item.SpacingAfter = 1f;
var item = new ListItem(para);
item.SpacingAfter = 1f;
if (currentList.First == 0) // Set First only once when the list is created
currentList.First = initialListIndex;

Copilot uses AI. Check for mistakes.

if (currentList != null)
{
var para = new Paragraph();
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

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

[nitpick] When closing out the final currentList, the new paragraph lacks explicit leading, spacing, and alignment settings applied elsewhere. Consider applying consistent formatting (SetLeading, SpacingAfter, alignment) to maintain uniform appearance.

Suggested change
var para = new Paragraph();
var para = new Paragraph();
para.SetLeading(0, 1.2f); // Set line spacing
para.SpacingAfter = 10f; // Set spacing after the paragraph
para.Alignment = Element.ALIGN_LEFT; // Set alignment

Copilot uses AI. Check for mistakes.
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.

PDF Generation: Presentation of Bullets

2 participants