-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Initialize-PDF.ps1
65 lines (62 loc) · 3.16 KB
/
Initialize-PDF.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Initialize-PDF {
[CmdletBinding()]
param(
[Array] $Elements
)
foreach ($Element in $Elements) {
$Splat = $Element.Settings
if ($Splat) {
Remove-EmptyValue -Hashtable $Splat
}
if ($Element.Type -eq 'Page') {
if (-not $Script:PDFStart.FirstPageUsed) {
#$Area = New-PDFArea -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate -AreaType ([iText.Layout.Properties.AreaBreakType]::LAST_PAGE)
#New-InternalPDFPage -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
# This adds margings to first page if New-PDFOptions is used but no margins were defined on New-PDFPage
if (-not $Splat.Margins.MarginBottom) {
$Splat.Margins.MarginBottom = $Script:PDFStart.DocumentSettings.MarginBottom
}
if (-not $Splat.Margins.MarginTop) {
$Splat.Margins.MarginTop = $Script:PDFStart.DocumentSettings.MarginTop
}
if (-not $Splat.Margins.MarginLeft) {
$Splat.Margins.MarginLeft = $Script:PDFStart.DocumentSettings.MarginLeft
}
if (-not $Splat.Margins.MarginRight) {
$Splat.Margins.MarginRight = $Script:PDFStart.DocumentSettings.MarginRight
}
New-InternalPDFPage -PageSize $Splat.PageSize -Rotate:$Splat.Rotate -MarginLeft $Splat.Margins.MarginLeft -MarginTop $Splat.Margins.MarginTop -MarginBottom $Splat.Margins.MarginBottom -MarginRight $Splat.Margins.MarginRight
#Add-PDFDocumentContent -Object $Area
$Script:PDFStart.FirstPageUsed = $true
} else {
# This fixes margins. Margins have to be added before new PageArea
$SplatMargins = $Splat.Margins
New-InternalPDFOptions @SplatMargins
$Area = New-PDFArea -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
Add-PDFDocumentContent -Object $Area
}
# New-InternalPDFPage -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
# New-InternalPDFOptions -Settings $Element.Settings
if ($Element.Settings.PageContent) {
Initialize-PDF -Elements $Element.Settings.PageContent
}
} elseif ($Element.Type -eq 'Text') {
$Paragraph = New-InternalPDFText @Splat
foreach ($P in $Paragraph) {
Add-PDFDocumentContent -Object $P
}
} elseif ($Element.Type -eq 'List') {
New-InternalPDFList -Settings $Element.Settings
} elseif ($Element.Type -eq 'Paragraph') {
} elseif ($Element.Type -eq 'Options') {
$SplatMargins = $Splat.Margins
New-InternalPDFOptions @SplatMargins
} elseif ($Element.Type -eq 'Table') {
$Table = New-InteralPDFTable @Splat
#$null = $Script:Document.Add($Table)
Add-PDFDocumentContent -Object $Table
} elseif ($Element.Type -eq 'Image') {
New-InternalPDFImage @Splat
}
}
}