forked from BertMueller18/PowerShell-PDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDF.psm1
More file actions
64 lines (57 loc) · 2.51 KB
/
Copy pathPDF.psm1
File metadata and controls
64 lines (57 loc) · 2.51 KB
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
#
# (C) 2015 Patrick Lambert - http://dendory.net
#
# Import assembly: iTextSharp is from: https://sourceforge.net/projects/itextsharp
Add-Type -Path "$PSScriptRoot\itextsharp.dll"
#
# Function definitions
#
# Set basic PDF settings for the document
Function Create-PDF([iTextSharp.text.Document]$Document, [string]$File, [int32]$TopMargin, [int32]$BottomMargin, [int32]$LeftMargin, [int32]$RightMargin, [string]$Author)
{
$Document.SetPageSize([iTextSharp.text.PageSize]::A4)
$Document.SetMargins($LeftMargin, $RightMargin, $TopMargin, $BottomMargin)
[void][iTextSharp.text.pdf.PdfWriter]::GetInstance($Document, [System.IO.File]::Create($File))
$Document.AddAuthor($Author)
}
# Add a text paragraph to the document, optionally with a font name, size and color
function Add-Text([iTextSharp.text.Document]$Document, [string]$Text, [string]$FontName = "Arial", [int32]$FontSize = 12, [string]$Color = "BLACK")
{
$p = New-Object iTextSharp.text.Paragraph
$p.Font = [iTextSharp.text.FontFactory]::GetFont($FontName, $FontSize, [iTextSharp.text.Font]::NORMAL, [iTextSharp.text.BaseColor]::$Color)
$p.SpacingBefore = 2
$p.SpacingAfter = 2
$p.Add($Text)
$Document.Add($p)
}
# Add a title to the document, optionally with a font name, size, color and centered
function Add-Title([iTextSharp.text.Document]$Document, [string]$Text, [Switch]$Centered, [string]$FontName = "Arial", [int32]$FontSize = 16, [string]$Color = "BLACK")
{
$p = New-Object iTextSharp.text.Paragraph
$p.Font = [iTextSharp.text.FontFactory]::GetFont($FontName, $FontSize, [iTextSharp.text.Font]::BOLD, [iTextSharp.text.BaseColor]::$Color)
if($Centered) { $p.Alignment = [iTextSharp.text.Element]::ALIGN_CENTER }
$p.SpacingBefore = 5
$p.SpacingAfter = 5
$p.Add($Text)
$Document.Add($p)
}
# Add an image to the document, optionally scaled
function Add-Image([iTextSharp.text.Document]$Document, [string]$File, [int32]$Scale = 100)
{
[iTextSharp.text.Image]$img = [iTextSharp.text.Image]::GetInstance($File)
$img.ScalePercent(50)
$Document.Add($img)
}
# Add a table to the document with an array as the data, a number of columns, and optionally centered
function Add-Table([iTextSharp.text.Document]$Document, [string[]]$Dataset, [int32]$Cols = 3, [Switch]$Centered)
{
$t = New-Object iTextSharp.text.pdf.PDFPTable($Cols)
$t.SpacingBefore = 5
$t.SpacingAfter = 5
if(!$Centered) { $t.HorizontalAlignment = 0 }
foreach($data in $Dataset)
{
$t.AddCell($data);
}
$Document.Add($t)
}