Commit a365c8c6 authored by Sebastian Drenckberg's avatar Sebastian Drenckberg
Browse files

merge fix/annotations into master

parents 127e91b3 185357af
Pipeline #397120 passed with stages
in 1 minute and 35 seconds
......@@ -18,7 +18,7 @@ namespace PDFGenerator.Controllers
/// <summary>
/// Say hello!
/// </summary>
/// <returns></returns>
/// <returns>"Hello"</returns>
[HttpGet("Hello")]
public string Get()
{
......@@ -26,10 +26,10 @@ namespace PDFGenerator.Controllers
}
/// <summary>
/// Generates the PDF report.
/// Generates the PDF for an evaluation report.
/// </summary>
/// <param name="evaluationReport">Evaluation report for which the PDF should be rendered.</param>
/// <returns>the PDF document as byte array</returns>
/// <returns>PDF document as byte array.</returns>
[HttpPost("RenderReport")]
[RequestSizeLimit(100000000)]
public byte[] RenderReport([FromBody] PDFGenerator.Models.EvaluationReport evaluationReport)
......
......@@ -27,9 +27,9 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Includes custom uploads to the available attachments.
/// Includes custom uploads to attachments available.
/// </summary>
/// <param name="customUploads">custom attachments to be added</param>
/// <param name="customUploads">Custom attachments to be added.</param>
public void UpdateAppendix(Dictionary<string, byte[]> customUploads)
{
foreach (KeyValuePair<string, byte[]> item in customUploads)
......@@ -72,7 +72,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds a single attachment to document.
/// </summary>
/// <param name="item">the item composed of an attachment key and content</param>
/// <param name="item">The item composed of an attachment key and content.</param>
private void AddAttachment(KeyValuePair<string, byte[]> item)
{
PdfReader attachment = new PdfReader(new MemoryStream(item.Value));
......@@ -82,13 +82,13 @@ namespace PDFGenerator.EvaluationReport
// avoiding the exception 'PdfReader not opened with owner password' from third party encrypted PDF uploads involves
// manipulating both 'unethicalReading' and 'encrypted' flags from PdfReader
// in case the original author of the document defined permissions, then these permissions are ignored by setting 'unethicalReading' to true;
// this is not a problem, as setting such permissions has become obsolete, because since PDF became an ISO standard,
// In case the original author of the document defined permissions these permissions are ignored by setting 'unethicalReading' to true.
// This is not a problem, as setting such permissions has become obsolete, since PDF became an ISO standard and
// there is no longer a penalty for removing those permissions
// (refer to https://stackoverflow.com/questions/48064902/itext-7-pdfreader-is-not-opened-with-owner-password-error)
attachment.SetUnethicalReading(true);
// mislead iText into thinking that the original PDF file was not encrypted
// Mislead iText into thinking that the original PDF file was not encrypted
attachment.GetType()
.GetField("encrypted", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(attachment, false);
......@@ -103,7 +103,7 @@ namespace PDFGenerator.EvaluationReport
SetPageOrientation(Orientation.Landscape);
}
// if attachment orientation is portrait, but destination pdf is not
// if attachment orientation is portrait but destination pdf is not
else if ((attachmentPageSize.GetHeight() > attachmentPageSize.GetWidth()) && ((int)Math.Round(attachmentPageSize.GetHeight()) > pageSize.GetHeight()))
{
SetPageOrientation(Orientation.Portrait);
......@@ -120,8 +120,8 @@ namespace PDFGenerator.EvaluationReport
AddPageBreak();
}
// table for inserting imported pages;
// true flag: avoid memory overhead problems from big imported files
// table for inserting imported pages
// true flag: Avoid memory overhead problems from big imported files
Table table = new Table(1, true)
.UseAllAvailableWidth()
.SetDestination(item.Key);
......@@ -151,12 +151,12 @@ namespace PDFGenerator.EvaluationReport
table.AddCell(cell);
// flush content of a single page to render part of the table: cell objects that were rendered
// are made available to the garbage collector so that the memory used by those objects can be released
// flush content of a single page to render part of the table:
// memory used be rendered cell objects is made available to the garbage collector for release
table.Flush();
}
// once added all the cells, this writes the remainder of the table that wasn't rendered yet
// once all the cells are added write the remainder of the table that was not rendered yet
table.Complete();
source.Close();
......
......@@ -29,8 +29,7 @@ namespace PDFGenerator.EvaluationReport
Bookmarks = bookmarks;
TableOfContents = tableOfContents;
// get the root outline from the PdfDocument: false indicates that
// iText does not need to update the outlines
// get root outline from the PdfDocument: false indicates iText does not need to update the outlines.
RootOutline = Document.GetPdfDocument().GetOutlines(false);
}
......@@ -42,7 +41,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Gets the current page.
/// </summary>
/// <returns>the current page</returns>
/// <returns>The current page.</returns>
protected int GetCurrentPage()
{
return Document.GetPdfDocument().GetNumberOfPages();
......@@ -51,7 +50,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Gets default page size.
/// </summary>
/// <returns>the default page size</returns>
/// <returns>The default page size.</returns>
protected PageSize GetPageSize()
{
return Document.GetPdfDocument().GetDefaultPageSize();
......@@ -60,8 +59,8 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Resizes image to fit page size.
/// </summary>
/// <param name="image">image to be resized</param>
/// <returns>the resized image</returns>
/// <param name="image">Image to be resized.</param>
/// <returns>The resized image.</returns>
protected Image GetScaledImage(Image image)
{
PageSize pageSize = GetPageSize();
......@@ -77,12 +76,13 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Adds upload files directly to the document if they are images; uploads consisting of PDF files are
/// added to the available custom uploads to be rendered as attachments in appendix and links are added to the document referring to them;
/// if the custom uploads are neither PDF nor image files, then an exception is triggered.
/// Adds upload files directly to the document if they are images.
/// Uploads consisting of PDF files are added to the available custom uploads to be rendered as attachments in appendix
/// and links are added to the document referring to them instead.
/// If the custom uploads are neither PDF files nor image files an exception is thrown.
/// </summary>
/// <param name="uploads">new custom uploads to be considered</param>
/// <param name="customUploads">already available custom uploads</param>
/// <param name="uploads">New custom uploads to be considered.</param>
/// <param name="customUploads">Already available custom uploads.</param>
protected void AddCustomUploads(CustomUploads uploads, Dictionary<string, byte[]> customUploads)
{
if (uploads.Files == null)
......@@ -99,7 +99,8 @@ namespace PDFGenerator.EvaluationReport
bool imagesAvailable = false;
foreach (KeyValuePair<string, byte[]> file in uploads.Files)
{
// only accept files in image or PDF format, otherwise an exception is triggered below
// only accept files in image or PDF format, otherwise an exception is thrown below
// firstly, check if file is a valid image
if (ImageDataFactory.IsSupportedType(file.Value))
{
......@@ -115,7 +116,7 @@ namespace PDFGenerator.EvaluationReport
continue;
}
// secondly, if data does not correspond to a PDF file, an exception is triggered
// secondly, if data does not correspond to a PDF file, an exception is thrown
new PdfReader(new MemoryStream(file.Value));
if (!customUploads.ContainsKey(file.Key))
......@@ -145,10 +146,10 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds paragraph above the table.
/// </summary>
/// <param name="table">the table, on which the paragraph is added</param>
/// <param name="text">the paragrah content</param>
/// <param name="header">flag indicatesm whether the content is a hedaer for the table</param>
/// <param name="style">given style for paragraph</param>
/// <param name="table">The table on which the paragraph is added.</param>
/// <param name="text">The paragraphs content.<param>
/// <param name="header">Flag indicating whether the content is a table header.</param>
/// <param name="style">Given style for paragraph.</param>
protected void AddParagraphWithLeadingToTable(Table table, string text, bool header, Style style = null)
{
Cell cell = new Cell().SetBorder(Border.NO_BORDER);
......@@ -173,7 +174,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Changes the page orientation.
/// </summary>
/// <param name="orientation">orientation that the page should assume</param>
/// <param name="orientation">Orientation to change to.</param>
protected void SetPageOrientation(Orientation orientation)
{
if (orientation == Orientation.Landscape)
......@@ -194,11 +195,11 @@ namespace PDFGenerator.EvaluationReport
}
/// <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')
/// Prevents the default trim of leading whitespaces in the string
/// 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>
/// <param name="text">Text which leading whitespaces to be preserved.</param>
/// <returns>Text with preserved leading whitespaces.</returns>
protected string PreserveLeadingSpaces(string text)
{
return "\u0000" + Regex.Replace(text, @"\n", "\n\u0000");
......@@ -215,7 +216,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds scaled image to document.
/// </summary>
/// <param name="image">image to be scaled</param>
/// <param name="image">Image to add do document.</param>
private void AddScaledImage(Image image)
{
Document.Add(GetScaledImage(image));
......
......@@ -68,7 +68,7 @@ namespace PDFGenerator.EvaluationReport
AddCustomUploads(item.UploadedFilesForTopic, CustomUploads);
}
// description for the current topic, if available (topic-dependent)
// description for the current topic, if available (depends on topic)
if (item.Paragraphs.Count == 2)
{
Document.Add(ParagraphFactory.GetStandardParagraph(item.Paragraphs[1]));
......
......@@ -102,9 +102,9 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds a new cell to table.
/// </summary>
/// <param name="table">the table, on which a new cell is added</param>
/// <param name="text">the cell content</param>
/// <param name="leftColumn">flag to differentiate between left and right column</param>
/// <param name="table">The table on which a new cell is added.</param>
/// <param name="text">The cell content.</param>
/// <param name="leftColumn">Flag to differentiate between left and right column.</param>
private void AddCell(Table table, string text, bool leftColumn)
{
Cell cell = new Cell().Add(
......
......@@ -31,7 +31,6 @@ namespace PDFGenerator.EvaluationReport
Image image = new Image(imageData);
PageSize pageSize = GetPageSize();
//TODO Noch nicht 100% Vorgaben corporate design
image.ScaleAbsolute(MillimetersToPoints(60), MillimetersToPoints(16));
image.SetFixedPosition(
pageSize.GetRight() - image.GetImageScaledWidth() - MillimetersToPoints(5),
......
......@@ -78,7 +78,8 @@ namespace PDFGenerator.EvaluationReport
{
if (Target.EvaluatedCriterions.Any(evaluatedCrit => !string.IsNullOrEmpty(evaluatedCrit.Description)))
{
Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f)); // zielsetzung
// aimed target
Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f));
}
Target.EvaluatedCriterions.ForEach(item =>
......@@ -90,14 +91,15 @@ namespace PDFGenerator.EvaluationReport
Document.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 5f, 5f, 1.15f));
}
// avoid that existent multiple white spaces immediately after a line break are ignored from iText7
// avoid that existent multiple whitespaces after a line break are ignored by iText7
Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Description)));
}
});
if (Target.EvaluatedCriterions.Any(evaluatedCrit => !string.IsNullOrEmpty(evaluatedCrit.Comment)))
{
Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f)); // IST-Stand
// actual state
Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f));
}
Target.EvaluatedCriterions.ForEach(item =>
......
......@@ -34,7 +34,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds pillar information to document and goes through all its quality targets.
/// </summary>
/// <param name="pillar">input pillar</param>
/// <param name="pillar">Pillar to render into the document.</param>
private void RenderPillar(Pillar pillar)
{
Bookmarks.AddRootOutline(pillar.Heading, RootOutline);
......@@ -56,7 +56,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds quality target information to document and goes through all its criteria.
/// </summary>
/// <param name="qualityTarget">input quality target</param>
/// <param name="qualityTarget">Quality target to render into the document.</param>
private void RenderQualityTarget(QualityTarget qualityTarget)
{
string section = qualityTarget.Paragraphs[0];
......@@ -90,7 +90,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds criterion information to document and goes through all its kpi evaluations.
/// </summary>
/// <param name="criterion">input criterion</param>
/// <param name="criterion">Criterion to render into the document.</param>
private void RenderCriterion(Criterion criterion)
{
new CriterionTarget(criterion.CriterionTarget, Results.Sections[criterion.CriterionTarget.Paragraphs[0]], CustomUploads,
......@@ -108,7 +108,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds a table for listing measures as part of the criterion information
/// </summary>
/// <param name="measureTable">holds the information of each measure</param>
/// <param name="measureTable">Holds the information of each measure.</param>
private void AddMeasureSection(MeasureTable measureTable)
{
Table table = new Table(UnitValue.CreatePercentArray(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }), false)
......@@ -129,30 +129,30 @@ namespace PDFGenerator.EvaluationReport
measureTable.Measures.ForEach(measure =>
{
//first row
// first row
table.AddCell(new Cell().Add(new Paragraph(new Text("Kriterium/ Kennzahl").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Studiengang").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));
table.AddCell(new Cell().Add(new Paragraph(new Text("Fristigkeit").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Zuständigkeit").AddStyle(Styles.SmallBold))).SetVerticalAlignment(VerticalAlignment.MIDDLE).SetPaddingBottom(0));
//spans rows 2-4
// spans rows 2-4
table.AddCell(new Cell(3, 1).Add(new Paragraph(new Text(measure.FullId).AddStyle(Styles.Small)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
//second row
// second row
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.CourseName).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
table.AddCell(new Cell().Add(new Paragraph(new Text(measure.Maturity).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.Responsibilities).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
//third row
// third row
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text("Maßnahme").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
table.AddCell(new Cell(1, 5).Add(new Paragraph(new Text("Kommentar").AddStyle(Styles.SmallBold)).SetMultipliedLeading(1f)).SetPaddingBottom(0));
//fourth row
// fourth row
table.AddCell(new Cell(1, 4).Add(new Paragraph(new Text(measure.Description).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
table.AddCell(new Cell(1, 5).Add(new Paragraph(new Text(measure.Comments).AddStyle(Styles.Small)).SetMultipliedLeading(0.9f)).SetPaddingBottom(0));
});
// message for non-available measures, if available
// message for non-available measures if available
if (measureTable.Measures.Count == 0 && measureTable.Paragraphs.Count > 1)
{
table.AddCell(
......
......@@ -24,7 +24,7 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Renders the content regarding a single kpi and goes through als its reports.
/// Renders the content regarding a single kpi and iterates through its reports.
/// </summary>
public override void Render()
{
......@@ -66,7 +66,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds content about if the kpi is reached or not.
/// </summary>
/// <param name="evaluatedKpis">holds information for each available course</param>
/// <param name="evaluatedKpis">Containing information for each available course.</param>
private void AddKpiIsReachedSection(List<EvaluatedKpi> evaluatedKpis)
{
evaluatedKpis.ForEach(item =>
......@@ -84,7 +84,7 @@ namespace PDFGenerator.EvaluationReport
color = new DeviceRgb(249, 210, 218);
}
// avoid that existent multiple white spaces immediately after a line break are ignored from iText7
// avoid that existent multiple whitespaces after a line break are ignored by iText7
Table panel = Panel.GetPanel(new Paragraph(new Text(PreserveLeadingSpaces(item.Paragraph)).AddStyle(Styles.Paragraph)), color);
cell.Add(panel);
Table.AddCell(cell);
......@@ -95,7 +95,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds content about the kpi comment.
/// </summary>
/// <param name="evaluatedKpis">holds information for each available course</param>
/// <param name="evaluatedKpis">Contains information for each available course.</param>
private void AddKpiCommentSection(List<EvaluatedKpi> evaluatedKpis)
{
evaluatedKpis.ForEach(item =>
......
......@@ -126,7 +126,7 @@ namespace PDFGenerator.EvaluationReport
AddPageBreak();
// if order between images and text important
// if order between images and text is important
if (Reports.ReportElementOrder != null)
{
int countImages = 0;
......@@ -160,7 +160,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds a single report.
/// </summary>
/// <param name="images">the list of images, which represents the report</param>
/// <param name="images">List of images representing the report.</param>
private void AddImageToTable(List<byte[]> images)
{
ImageData imageData;
......
......@@ -31,9 +31,9 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Adds a new item to the list.
/// Adds a new item to the table of contents item list.
/// </summary>
/// <param name="item">new item to be added</param>
/// <param name="item">Item to add the table of contents item list.</param>
public void AddToTOC(TocItem item)
{
TocItems.Add(item);
......@@ -42,7 +42,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Renders the content for the table of contents.
/// </summary>
/// <param name="appendixStart">the appendix start page number</param>
/// <param name="appendixStart">The page number for the beginning of appendix.</param>
public void Render(int appendixStart)
{
TocPages = NumerOfPagesForTOC(appendixStart);
......@@ -53,7 +53,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Determines the number of pages for rendering the table of contents.
/// </summary>
/// <param name="appendixStart"> the appendix start page number</param>
/// <param name="appendixStart">The page number for the beginning of appendix.</param>
/// <returns></returns>
private int NumerOfPagesForTOC(int appendixStart)
{
......@@ -81,10 +81,10 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Adds the table of contents content to the document.
/// Adds the table of contents to the document.
/// </summary>
/// <param name="document">the PDF document</param>
/// <param name="appendixStart">the appendix start page number</param>
/// <param name="document">The PDF document.</param>
/// <param name="appendixStart">The page number for the beginning of appendix.</param>
private void AddTOC(Document document, int appendixStart)
{
Paragraph paragraph = new Paragraph(new Text("Inhaltsverzeichnis").AddStyle(Styles.H1)).SetMarginBottom(20f);
......@@ -133,10 +133,10 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// converts a number to roman numerals.
/// Converts a number to roman numerals.
/// </summary>
/// <param name="number">page number</param>
/// <returns>the number in roman numerals</returns>
/// <param name="number">Page number to convert.</param>
/// <returns>The converted number in roman numerals.</returns>
public static string ToRoman(int number)
{
if (number >= 1000)
......@@ -204,7 +204,7 @@ namespace PDFGenerator.EvaluationReport
return "i" + ToRoman(number - 1);
}
// number < 1
// if number < 1
return string.Empty;
}
}
......
......@@ -24,7 +24,7 @@ namespace PDFGenerator
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
// ensure to flush and stop internal timers/threads before application exit (Avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
}
......@@ -38,7 +38,7 @@ namespace PDFGenerator
}).ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
logging.SetMinimumLevel(LogLevel.Trace);
})
.UseNLog(); // NLog: Setup NLog for Dependency injection
}
......
......@@ -29,17 +29,17 @@ namespace PDFGenerator.Renderers
{
EvaluationReport = evaluationReport;
// Open PDF document in write mode
// open PDF document in write mode
MemoryStream = new MemoryStream();
PdfWriter = new PdfWriter(MemoryStream);
// Initialize PDF document
// initialize PDF document
PdfDocument pdfDocument = new PdfDocument(PdfWriter);
// change the page mode so that the bookmarks panel is opened by default
pdfDocument.GetCatalog().SetPageMode(PdfName.UseOutlines);
// Create document to add new elements
// create document to add new elements
Document = new Document(pdfDocument, PageSize.A4);
Document.SetMargins(Margins.Top_Margin, Margins.Right_Margin, Margins.Bottom_Margin, Margins.Left_Margin);
......@@ -50,9 +50,9 @@ namespace PDFGenerator.Renderers
}
/// <summary>
/// Renders all sections for the evaluation report, reorder pages in the document and adds a header to it.
/// Renders all sections for the evaluation report, reorders pages in the document and adds a header to it.
/// </summary>
/// <returns>the generated PDF document as byte array</returns>
/// <returns>The generated PDF document as byte array.</returns>
public byte[] Render()
{
RenderSections();
......@@ -136,7 +136,7 @@ namespace PDFGenerator.Renderers
}
/// <summary>
/// Renders the section regarding the assessment of criterion targets and KPIs.
/// Renders the section regarding the assessment of criterion targets and kpis.
/// </summary>
private void RenderEvaluationResults()
{
......@@ -159,9 +159,9 @@ namespace PDFGenerator.Renderers
}
/// <summary>
/// Moves the table of contents to the front directly after the the cover; adds header to document.
/// Moves the table of contents directly after the cover and adds document header.
/// </summary>
/// <param name="memoryStream">the PDF document, on which the table of contents is reordered and a header is added</param>
/// <param name="memoryStream">The PDF document to apply the changes on.</param>
private void MoveTocToFront(MemoryStream memoryStream)
{
PdfReader pdfReader = new PdfReader(new MemoryStream(MemoryStream.ToArray()));
......@@ -169,17 +169,18 @@ 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
// 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.
// this method should be called to preserve the outlines of the source pdf file
// otherwise they will be absent in the reusulting document to which pages are copied
// initializes an outline tree of the document and sets outline mode to true:
// the method will read the whole document and create the outline tree.
// the method will read the whole document and create the outline tree
resultDocument.InitializeOutlines();
// cover >> chapters >> toc --> cover >> toc >> chapters
// reorders 'cover > chapters > toc' to 'cover > toc > chapters'
List<int> reorderedPages = new List<int> { firstPage };
for (int i = PageBeforeTOC + 1; i <= PageBeforeTOC + TableOfContents.TocPages; i++)
{
......@@ -193,7 +194,7 @@ namespace PDFGenerator.Renderers
sourceDocument.CopyPagesTo(reorderedPages, resultDocument);
sourceDocument.Close();
// Adding page numbers
// add page numbers
AddHeader(resultDocument);
resultDocument.Close();
}
......@@ -201,7 +202,7 @@ namespace PDFGenerator.Renderers
/// <summary>
/// Adds a header to the document.
/// </summary>
/// <param name="pdfDocument">the PDF document</param>
/// <param name="pdfDocument">The PDF document.</param>
private void AddHeader(PdfDocument pdfDocument)
{
Document document = new Document(pdfDocument);
......@@ -217,7 +218,7 @@ namespace PDFGenerator.Renderers
// header for cover excluded
for (int i = firstPage + 1; i <= n; i++)
{
// get the page by the page number
// get page by the page number
ps = pdfDocument.GetPage(i).GetPageSizeWithRotation();
float height = ps.GetHeight();
......
using System;
namespace PDFGenerator.Renderers
{