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
/// </summary>
public override void Render()
{
if (PDFAppendix.Attachments.Count == 0)
{
return;
}
Bookmarks.AddRootOutline(PDFAppendix.Heading, RootOutline);
TocItem tocItem = new TocItem
......
......@@ -10,6 +10,7 @@ using PDFGenerator.Models;
using PDFGenerator.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using static PDFGenerator.Utilities.Globals;
namespace PDFGenerator.EvaluationReport
......@@ -192,6 +193,17 @@ namespace PDFGenerator.EvaluationReport
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>
/// Adds page break to document.
/// </summary>
......
......@@ -67,7 +67,7 @@ namespace PDFGenerator.EvaluationReport
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))
.Add(NewLine)
......@@ -91,7 +91,7 @@ namespace PDFGenerator.EvaluationReport
}
// 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
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
style.SetFontColor(new DeviceRgb(156, 158, 159));
}
Table = new Table(1, false).UseAllAvailableWidth()
Table = new Table(1, false)
.UseAllAvailableWidth()
.SetKeepTogether(false);
AddParagraphWithLeadingToTable(Table, Evaluation.TableHeader, true, style);
......@@ -72,23 +73,21 @@ namespace PDFGenerator.EvaluationReport
{
if (!string.IsNullOrEmpty(item.Paragraph))
{
Cell cell = new Cell().SetBorder(Border.NO_BORDER);
DeviceRgb color;
if (item.IsReached)
{
Table.AddCell(
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)
)
);
color = new DeviceRgb(221, 235, 206);
}
else
{
Table.AddCell(
Panel.GetPanel(
new Paragraph(new Text(item.Paragraph.Replace(' ', '\u00A0')).AddStyle(Styles.Paragraph)), new DeviceRgb(249, 210, 218)
)
);
color = 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
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);
}
});
......
......@@ -169,7 +169,9 @@ namespace PDFGenerator.Renderers
PdfDocument resultDocument = new PdfDocument(new PdfWriter(memoryStream));
// the first page of a PdfDocument is 1
// exclude appendix start page as last page, if there are no attachments
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
// will be absent in the resultant document to which we copy pages.
......@@ -183,7 +185,7 @@ namespace PDFGenerator.Renderers
{
reorderedPages.Add(i);
}
for (int i = firstPage + 1; i <= PageBeforeTOC; i++)
for (int i = firstPage + 1; i <= lastPage; 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