Commit b20408a8 authored by Nuno Alves's avatar Nuno Alves
Browse files

Merge branch 'fix/739-pdf-outsourcing-bugs' into 'master'

From fix/739-pdf-outsourcing-bugs into master

Closes datencockpit/bl#739

See merge request datencockpit-open/pdf-generator!5
parents 20af835a b54bffac
Pipeline #386789 passed with stages
in 57 seconds
...@@ -46,6 +46,11 @@ namespace PDFGenerator.EvaluationReport ...@@ -46,6 +46,11 @@ namespace PDFGenerator.EvaluationReport
/// </summary> /// </summary>
public override void Render() public override void Render()
{ {
if (PDFAppendix.Attachments.Count == 0)
{
return;
}
Bookmarks.AddRootOutline(PDFAppendix.Heading, RootOutline); Bookmarks.AddRootOutline(PDFAppendix.Heading, RootOutline);
TocItem tocItem = new TocItem TocItem tocItem = new TocItem
......
...@@ -10,6 +10,7 @@ using PDFGenerator.Models; ...@@ -10,6 +10,7 @@ using PDFGenerator.Models;
using PDFGenerator.Utilities; using PDFGenerator.Utilities;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using static PDFGenerator.Utilities.Globals; using static PDFGenerator.Utilities.Globals;
namespace PDFGenerator.EvaluationReport namespace PDFGenerator.EvaluationReport
...@@ -192,6 +193,17 @@ namespace PDFGenerator.EvaluationReport ...@@ -192,6 +193,17 @@ namespace PDFGenerator.EvaluationReport
Document.Add(ParagraphFactory.GetTableHeaderParagraph(string.Empty)); Document.Add(ParagraphFactory.GetTableHeaderParagraph(string.Empty));
} }
/// <summary>
/// Prevents the default trim of existent leading whitespaces at the string beginning and immediately after a linebreak on iText7,
/// by adding a NULL character ('\u0000')
/// </summary>
/// <param name="text">input text</param>
/// <returns>text with preserved leading whitespaces</returns>
protected string PreserveLeadingSpaces(string text)
{
return "\u0000" + Regex.Replace(text, @"\n", "\n\u0000");
}
/// <summary> /// <summary>
/// Adds page break to document. /// Adds page break to document.
/// </summary> /// </summary>
......
...@@ -67,7 +67,7 @@ namespace PDFGenerator.EvaluationReport ...@@ -67,7 +67,7 @@ namespace PDFGenerator.EvaluationReport
style.SetFontColor(ColorConstants.BLACK); style.SetFontColor(ColorConstants.BLACK);
if (!Target.Selected && (count < Target.Paragraphs.Count)) if (!Target.Selected && Target.EvaluatedCriterions == null && (count < Target.Paragraphs.Count))
{ {
Document.Add(new Paragraph(new Text(Target.Paragraphs[count++]).AddStyle(style)) Document.Add(new Paragraph(new Text(Target.Paragraphs[count++]).AddStyle(style))
.Add(NewLine) .Add(NewLine)
...@@ -91,7 +91,7 @@ namespace PDFGenerator.EvaluationReport ...@@ -91,7 +91,7 @@ namespace PDFGenerator.EvaluationReport
} }
// avoid that existent multiple white spaces immediately after a line break are ignored from iText7 // avoid that existent multiple white spaces immediately after a line break are ignored from iText7
Document.Add(ParagraphFactory.GetStandardParagraph(item.Description.Replace(' ', '\u00A0'))); Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Description)));
} }
}); });
...@@ -109,7 +109,7 @@ namespace PDFGenerator.EvaluationReport ...@@ -109,7 +109,7 @@ namespace PDFGenerator.EvaluationReport
Document.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 5f, 5f, 1.15f)); Document.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 5f, 5f, 1.15f));
} }
Document.Add(ParagraphFactory.GetStandardParagraph(item.Comment.Replace(' ', '\u00A0'))); Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Comment)));
} }
}); });
} }
......
...@@ -35,7 +35,8 @@ namespace PDFGenerator.EvaluationReport ...@@ -35,7 +35,8 @@ namespace PDFGenerator.EvaluationReport
style.SetFontColor(new DeviceRgb(156, 158, 159)); style.SetFontColor(new DeviceRgb(156, 158, 159));
} }
Table = new Table(1, false).UseAllAvailableWidth() Table = new Table(1, false)
.UseAllAvailableWidth()
.SetKeepTogether(false); .SetKeepTogether(false);
AddParagraphWithLeadingToTable(Table, Evaluation.TableHeader, true, style); AddParagraphWithLeadingToTable(Table, Evaluation.TableHeader, true, style);
...@@ -72,23 +73,21 @@ namespace PDFGenerator.EvaluationReport ...@@ -72,23 +73,21 @@ namespace PDFGenerator.EvaluationReport
{ {
if (!string.IsNullOrEmpty(item.Paragraph)) if (!string.IsNullOrEmpty(item.Paragraph))
{ {
Cell cell = new Cell().SetBorder(Border.NO_BORDER);
DeviceRgb color;
if (item.IsReached) if (item.IsReached)
{ {
Table.AddCell( color = new DeviceRgb(221, 235, 206);
Panel.GetPanel(
// avoid trim of whitespaces immediately after line break (iText7 problem)
new Paragraph(new Text(item.Paragraph.Replace(' ', '\u00A0')).AddStyle(Styles.Paragraph)), new DeviceRgb(221, 235, 206)
)
);
} }
else else
{ {
Table.AddCell( color = new DeviceRgb(249, 210, 218);
Panel.GetPanel(
new Paragraph(new Text(item.Paragraph.Replace(' ', '\u00A0')).AddStyle(Styles.Paragraph)), new DeviceRgb(249, 210, 218)
)
);
} }
// avoid that existent multiple white spaces immediately after a line break are ignored from iText7
Table panel = Panel.GetPanel(new Paragraph(new Text(PreserveLeadingSpaces(item.Paragraph)).AddStyle(Styles.Paragraph)), color);
cell.Add(panel);
Table.AddCell(cell);
} }
}); });
} }
...@@ -110,7 +109,7 @@ namespace PDFGenerator.EvaluationReport ...@@ -110,7 +109,7 @@ namespace PDFGenerator.EvaluationReport
cell.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 0, 5, 1.15f)); cell.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 0, 5, 1.15f));
} }
cell.Add(ParagraphFactory.GetStandardParagraph(item.Comment.Replace(' ', '\u00A0'))); cell.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Comment)));
Table.AddCell(cell); Table.AddCell(cell);
} }
}); });
......
...@@ -169,7 +169,9 @@ namespace PDFGenerator.Renderers ...@@ -169,7 +169,9 @@ namespace PDFGenerator.Renderers
PdfDocument resultDocument = new PdfDocument(new PdfWriter(memoryStream)); PdfDocument resultDocument = new PdfDocument(new PdfWriter(memoryStream));
// the first page of a PdfDocument is 1 // the first page of a PdfDocument is 1
// exclude appendix start page as last page, if there are no attachments
int firstPage = 1; int firstPage = 1;
int lastPage = EvaluationReport.Appendix.Attachments.Count > 0 ? PageBeforeTOC : PageBeforeTOC - 1;
// One should call this method to preserve the outlines of the source pdf file, otherwise they // One should call this method to preserve the outlines of the source pdf file, otherwise they
// will be absent in the resultant document to which we copy pages. // will be absent in the resultant document to which we copy pages.
...@@ -183,7 +185,7 @@ namespace PDFGenerator.Renderers ...@@ -183,7 +185,7 @@ namespace PDFGenerator.Renderers
{ {
reorderedPages.Add(i); reorderedPages.Add(i);
} }
for (int i = firstPage + 1; i <= PageBeforeTOC; i++) for (int i = firstPage + 1; i <= lastPage; i++)
{ {
reorderedPages.Add(i); reorderedPages.Add(i);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment