#381 Fix list item wrapping and alignment in PDFs#399
#381 Fix list item wrapping and alignment in PDFs#399Delberin-Ali wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
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
Listobjects. - 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
Listtype is ambiguous and may conflict withSystem.Collections.Generic.List<T>. Consider using the full namespace (e.g.,iTextSharp.text.List) or an alias to clarify intent.
List currentList = null;
| 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| } | ||
| else if (isUnorderedList) | ||
| { | ||
| currentLine = currentLine.TrimStart('*', '-', 'o', ' '); |
There was a problem hiding this comment.
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.
| currentLine = currentLine.TrimStart('*', '-', 'o', ' '); | |
| currentLine = Regex.Replace(currentLine, @"^(?:\*|-|o)\s+", ""); |
| currentList.First = 1 + listIndexOffset - currentList.Size; | ||
| var item = new ListItem(para); | ||
| item.SpacingAfter = 1f; |
There was a problem hiding this comment.
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.
| 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; |
|
|
||
| if (currentList != null) | ||
| { | ||
| var para = new Paragraph(); |
There was a problem hiding this comment.
[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.
| 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 |
No description provided.