Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PDSLLabs Public
QMSL
PDFGenerator QMSL
Commits
4d45134b
Commit
4d45134b
authored
Jan 07, 2021
by
Sebastian Drenckberg
Browse files
refactor annotations
parent
b20408a8
Pipeline
#386949
passed with stage
in 14 seconds
Changes
21
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
pdf-generator/Controllers/EvaluationReportController.cs
View file @
4d45134b
...
...
@@ -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
)
...
...
pdf-generator/EvaluationReport/Appendix.cs
View file @
4d45134b
...
...
@@ -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">
c
ustom attachments to be added</param>
/// <param name="customUploads">
C
ustom 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">
t
he item composed of an attachment key and content</param>
/// <param name="item">
T
he 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
//
i
n case the original author of the document defined permissions
, then
these permissions are ignored by setting 'unethicalReading' to true
;
//
t
his is not a problem, as setting such permissions has become obsolete,
because
since PDF became an ISO standard
,
//
I
n case the original author of the document defined permissions these permissions are ignored by setting 'unethicalReading' to true
.
//
T
his 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
);
//
m
islead iText into thinking that the original PDF file was not encrypted
//
M
islead 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:
a
void memory overhead problems from big imported files
// table for inserting imported pages
// true flag:
A
void 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
release
d
// 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
write
s
the remainder of the table that was
n'
t rendered yet
// once all the cells
are added
write the remainder of the table that was
no
t rendered yet
table
.
Complete
();
source
.
Close
();
...
...
pdf-generator/EvaluationReport/BaseSection.cs
View file @
4d45134b
...
...
@@ -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></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></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">
i
mage to be resized</param>
/// <returns>
t
he resized image</returns>
/// <param name="image">
I
mage to be resized
.
</param>
/// <returns>
T
he 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">
n
ew custom uploads to be considered</param>
/// <param name="customUploads">
a
lready available custom uploads</param>
/// <param name="uploads">
N
ew custom uploads to be considered
.
</param>
/// <param name="customUploads">
A
lready 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 t
riggered
// secondly, if data does not correspond to a PDF file, an exception is t
hrown
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">
t
he table
,
on which the paragraph is added</param>
/// <param name="text">
t
he paragra
h
content<
/
param>
/// <param name="header">
f
lag indicat
esm
whether the content is a
hedaer for the table
</param>
/// <param name="style">
g
iven style for paragraph</param>
/// <param name="table">
T
he table on which the paragraph is added
.
</param>
/// <param name="text">
T
he paragra
phs
content
.
<param>
/// <param name="header">
F
lag indicat
ing
whether the content is a
table header.
</param>
/// <param name="style">
G
iven 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"></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>
t
ext with preserved leading whitespaces</returns>
/// <param name="text">
Text which leading whitespaces to be preserved.
</param>
/// <returns>
T
ext 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"></param>
/// <param name="image">
Image to add do document.
</param>
private
void
AddScaledImage
(
Image
image
)
{
Document
.
Add
(
GetScaledImage
(
image
));
...
...
pdf-generator/EvaluationReport/CourseGeneralInformation.cs
View file @
4d45134b
...
...
@@ -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
]));
...
...
pdf-generator/EvaluationReport/CourseInformationTables.cs
View file @
4d45134b
...
...
@@ -102,9 +102,9 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds a new cell to table.
/// </summary>
/// <param name="table">
t
he table
,
on which a new cell is added</param>
/// <param name="text">
t
he cell content</param>
/// <param name="leftColumn">
f
lag to differentiate between left and right column</param>
/// <param name="table">
T
he table on which a new cell is added
.
</param>
/// <param name="text">
T
he cell content
.
</param>
/// <param name="leftColumn">
F
lag to differentiate between left and right column
.
</param>
private
void
AddCell
(
Table
table
,
string
text
,
bool
leftColumn
)
{
Cell
cell
=
new
Cell
().
Add
(
...
...
pdf-generator/EvaluationReport/Cover.cs
View file @
4d45134b
...
...
@@ -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
),
...
...
pdf-generator/EvaluationReport/CriterionTarget.cs
View file @
4d45134b
...
...
@@ -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
=>
...
...
pdf-generator/EvaluationReport/EvaluationResults.cs
View file @
4d45134b
...
...
@@ -34,7 +34,7 @@ namespace PDFGenerator.EvaluationReport
/// <summary>
/// Adds pillar information to document and goes through all its quality targets.
/// </summary>
/// <param name="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"></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"></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">
h
olds the information of each measure</param>
/// <param name="measureTable">
H
olds 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
(
...
...
pdf-generator/EvaluationReport/KpiEvaluation.cs
View file @
4d45134b
...
...
@@ -24,7 +24,7 @@ namespace PDFGenerator.EvaluationReport
}
/// <summary>
/// Renders the content regarding a single kpi and
go
es through
als
its reports.
/// Renders the content regarding a single kpi and
iterat
es 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">
hold
s information for each available course</param>
/// <param name="evaluatedKpis">
Contain
s information for each available course
.
</param>
private
void
AddKpiCommentSection
(
List
<
EvaluatedKpi
>
evaluatedKpis
)
{
evaluatedKpis
.
ForEach
(
item
=>
...
...
pdf-generator/EvaluationReport/KpiEvaluationReports.cs
View file @
4d45134b
...
...
@@ -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 l
ist of images
, which
represent
s
the report</param>
/// <param name="images">
L
ist of images represent
ing
the report
.
</param>
private
void
AddImageToTable
(
List
<
byte
[
]>
images
)
{
ImageData
imageData
;
...
...
pdf-generator/EvaluationReport/TableOfContents.cs
View file @
4d45134b
...
...
@@ -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"></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"></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">
t
he page number for the appendix
start
</param>
/// <param name="appendixStart">
T
he 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">
t
he PDF document</param>
/// <param name="appendixStart">
t
he page number for the appendix
start
</param>
/// <param name="document">
T
he PDF document
.
</param>
/// <param name="appendixStart">
T
he 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>
///
c
onverts a number to roman numerals.
///
C
onverts a number to roman numerals.
/// </summary>
/// <param name="number">
p
age number</param>
/// <returns>
t
he number in roman numerals</returns>
/// <param name="number">
P
age number
to convert.
</param>
/// <returns>
T
he
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
;
}
}
...
...
pdf-generator/Program.cs
View file @
4d45134b
...
...
@@ -24,7 +24,7 @@ namespace PDFGenerator
}
finally
{
//
E
nsure to flush and stop internal timers/threads before application
-
exit (Avoid segmentation fault on Linux)
//
e
nsure 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
}
...
...
pdf-generator/Renderers/EvaluationReportRenderer.cs
View file @
4d45134b
...
...
@@ -29,17 +29,17 @@ namespace PDFGenerator.Renderers
{
EvaluationReport
=
evaluationReport
;
//
O
pen PDF document in write mode
//
o
pen PDF document in write mode
MemoryStream
=
new
MemoryStream
();
PdfWriter
=
new
PdfWriter
(
MemoryStream
);
//
I
nitialize PDF document
//
i
nitialize 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
);
//
C
reate document to add new elements
//
c
reate 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, reorder
s
pages in the document and adds a header to it.
/// </summary>
/// <returns>
t
he generated PDF document as byte array</returns>
/// <returns>
T
he 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
KPI
s.
/// Renders the section regarding the assessment of criterion targets and
kpi
s.
/// </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
;
a
dds header to
document.
/// Moves the table of contents directly after the cover a
nd adds
document
header
.
/// </summary>
/// <param name="memoryStream">
t
he PDF document
, on which the table of contents is reordered and a header is added
</param>
/// <param name="memoryStream">
T
he 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
();
//
A
dd
ing
page numbers
//
a
dd page numbers
AddHeader
(
resultDocument
);
resultDocument
.
Close
();
}
...
...
@@ -201,7 +202,7 @@ namespace PDFGenerator.Renderers
/// <summary>
/// Adds a header to the document.
/// </summary>
/// <param name="pdfDocument">
t
he PDF document</param>
/// <param name="pdfDocument">
T
he 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
();
...
...
pdf-generator/Renderers/FactsheetRenderer.cs
View file @
4d45134b
using
System
;
namespace
PDFGenerator.Renderers
{
public
class
FactsheetRenderer
:
IRenderer
...
...
@@ -5,11 +7,11 @@ namespace PDFGenerator.Renderers
/// <summary>