Skip to content

Commit a6c4ed0

Browse files
committed
+ iText can read bold&italic style of an outline but can not write it due to a partial check.
1 parent ea132af commit a6c4ed0

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

PdfMetadataEditor/PdfMetadataEditor/Backends/PdfEditor_iText.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class PdfEditor_iText : IPdfEditor
1616
public bool IsCreated { get; set; } = false;
1717
public bool IsBoldOutlineSupported { get; } = true;
1818
public bool IsItalicOutlineSupported { get; } = true;
19-
public bool IsBoldItalicOutlineSupported { get; } = false;
19+
public bool IsBoldItalicOutlineSupported { get; } = true;
2020

2121
public int LastPageNumber => pdfDocument!.GetNumberOfPages();
2222

@@ -64,6 +64,7 @@ public List<Entry> GetOutline()
6464
PageNo = GetPageNumberFromDestination(topLevel),
6565
IsBold = topLevel.GetStyle() == 2,
6666
IsItalic = topLevel.GetStyle() == 1,
67+
IsBoldItalic = topLevel.GetStyle() == 3,
6768
};
6869
entries.Add(entry);
6970
stack.Push((topLevel, entry));
@@ -92,9 +93,9 @@ public List<Entry> GetOutline()
9293

9394
private int GetPdfOutlineStyle(Entry entry)
9495
{
95-
int style = !(entry.IsBold | entry.IsItalic)
96+
int style = !(entry.IsBold | entry.IsItalic | entry.IsBoldItalic)
9697
? 0
97-
: (entry.IsBold ? 2 : entry.IsItalic ? 1 : 0);
98+
: (entry.IsBold ? 2 : entry.IsItalic ? 1 : entry.IsBoldItalic ? 3 : 0);
9899
return style;
99100
}
100101

PdfMetadataEditor/PdfMetadataEditor/Pages/Home.razor.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,35 @@ private async Task ImportChanges(IEnumerable<FluentInputFileEventArgs> files)
289289
}
290290
}
291291

292+
public enum OutlineStyleSupport
293+
{
294+
None = 0,
295+
ReadOnly = 1,
296+
ReadWrite = 2,
297+
}
298+
292299
public class BackendStyleSupport()
293300
{
294301
[Display(Name = "Backend")]
295302
public string? Backend { get; set; }
303+
296304
[Display(Name = "Bold")]
297-
public bool Bold { get; set; }
305+
public OutlineStyleSupport Bold { get; set; }
306+
298307
[Display(Name = "Italic")]
299-
public bool Italic { get; set; }
308+
public OutlineStyleSupport Italic { get; set; }
309+
300310
[Display(Name = "Bold & Italic")]
301-
public bool BoldItalic { get; set; }
311+
public OutlineStyleSupport BoldItalic { get; set; }
302312
}
303313

304314
public IQueryable<BackendStyleSupport> GetBackendStyleSupport()
305315
{
306316
return new[]
307317
{
308-
new BackendStyleSupport() { Backend = "iText", Bold = true, Italic = true, BoldItalic = false },
309-
new BackendStyleSupport() { Backend = "PdfSharpCore", Bold = true, Italic = true, BoldItalic = true },
310-
new BackendStyleSupport() { Backend = "MuPDF.js", Bold = false, Italic = false, BoldItalic = false },
318+
new BackendStyleSupport() { Backend = "iText", Bold = OutlineStyleSupport.ReadWrite, Italic = OutlineStyleSupport.ReadWrite, BoldItalic = OutlineStyleSupport.ReadOnly },
319+
new BackendStyleSupport() { Backend = "PdfSharpCore", Bold = OutlineStyleSupport.ReadWrite, Italic = OutlineStyleSupport.ReadWrite, BoldItalic = OutlineStyleSupport.ReadWrite },
320+
new BackendStyleSupport() { Backend = "MuPDF.js", Bold = OutlineStyleSupport.None, Italic = OutlineStyleSupport.None, BoldItalic = OutlineStyleSupport.None },
311321
}.AsQueryable();
312322
}
313323

0 commit comments

Comments
 (0)