
# Fonction pour créer une carte pôur NAGVIS
#
# Recoit en parametre :
#  - l'emplacement du fichier source
#  - l'emplacement du fichier de destination
#  - le texte à rajouter
#  - la position du texte dans l'image
Function AjoutTextePourImageMap {

    [CmdletBinding()]
    PARAM (
        [Parameter(Mandatory=$true)][String] $CheminSource,
        [Parameter(Mandatory=$true)][String] $CheminDestination,
        [Parameter(Mandatory=$true)][String] $Texte,
        [Parameter(Mandatory=$true)][String] $Position,
        [Parameter()][String] $Description = $null
    )

    Write-Verbose "Load System.Drawing"
    [Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null

    Write-Verbose "Get the image from $CheminSource"
    $srcImg = [System.Drawing.Image]::FromFile($CheminSource)

    Write-Verbose "Create a bitmap as $destPath"
    $outputIImg = new-object System.Drawing.Bitmap([int]($srcImg.width)),([int]($srcImg.height))

    Write-Verbose "Intialize Graphics"
    $Image = [System.Drawing.Graphics]::FromImage($outputIImg)
    $Image.SmoothingMode = "AntiAlias"

    $Rectangle = New-Object Drawing.Rectangle 0, 0, $srcImg.Width, $srcImg.Height
    $Image.DrawImage($srcImg, $Rectangle, 0, 0, $srcImg.Width, $srcImg.Height, ([Drawing.GraphicsUnit]::Pixel))

    Write-Verbose "Draw title: $Title"
    $Font = new-object System.Drawing.Font("Arial", 14, "Bold","Pixel")

    #get font size
    $font_size = [System.Windows.Forms.TextRenderer]::MeasureText($Texte, $Font)
    $font_size_width = $font_size.Width
    $font_size_height = $font_size.Height

    $rect = [System.Drawing.RectangleF]::FromLTRB(0, 0, $srcImg.Width, $srcImg.Height)

    If ($Position -eq "nom") {
        #$text_in_middle_top_offset = $srcImg.Height / 2
        $text_in_middle_top_offset = 180
        $text_in_middle_left_offset = 155

        #styling font
        $Brush = New-Object Drawing.SolidBrush([System.Drawing.Color]::FromArgb(255, 0, 0, 0))

        #lets draw font
        $Image.DrawString($Texte, $Font, $Brush, $text_in_middle_top_offset, $text_in_middle_left_offset)

    }
    ElseIf ($Position -eq "adresse") {
        $text_in_middle_top_offset = 180
        $text_in_middle_left_offset = 205

        #styling font
        $Brush = New-Object Drawing.SolidBrush([System.Drawing.Color]::FromArgb(255, 0, 0, 0))

        #lets draw font
        $Image.DrawString($Texte, $Font, $Brush, $text_in_middle_top_offset, $text_in_middle_left_offset)
    }
    ElseIf ($Position -eq "password") {
        $text_in_middle_top_offset = 180
        $text_in_middle_left_offset1 = 257
        $text_in_middle_left_offset2 = 280

        #styling font
        $Brush = New-Object Drawing.SolidBrush([System.Drawing.Color]::FromArgb(255, 0, 0, 0))

        #lets draw font
        $Image.DrawString($Texte, $Font, $Brush, $text_in_middle_top_offset, $text_in_middle_left_offset1)
        $Image.DrawString($Texte, $Font, $Brush, $text_in_middle_top_offset, $text_in_middle_left_offset2)
    }
    Else {
        $format = [System.Drawing.StringFormat]::GenericDefault
        $format.Alignment = [System.Drawing.StringAlignment]::Center
        $format.LineAlignment = [System.Drawing.StringAlignment]::Center
    }

    Write-Verbose "Save and close the files"
    $outputIImg.save($CheminDestination, [System.Drawing.Imaging.ImageFormat]::jpeg)
    $outputIImg.Dispose()
    $srcImg.Dispose()
}


$Nom            = "DUPONT"
$Prenom         = "Flavien"
$CRPCEN         = "59159"
$SamAccountName = "$Prenom.$Nom@no$CRPCEN.mailnot.fr"

Add-Type -Path “$PSScriptRoot\itextsharp.dll”
Import-Module "$PSScriptRoot\PDF.psm1"

AjoutTextePourImageMap -CheminSource "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001.jpg" -CheminDestination "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp.jpg" -Texte "$Prenom.$Nom" -Position "nom"
AjoutTextePourImageMap -CheminSource "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp.jpg" -CheminDestination "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-002.jpg" -Texte "$SamAccountName" -Position "adresse"
AjoutTextePourImageMap -CheminSource "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-002.jpg" -CheminDestination "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-003.jpg" -Texte "*******************" -Position "password"

$pdf = New-Object iTextSharp.text.Document
Create-PDF -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\exemple-0001.pdf" -TopMargin 20 -BottomMargin 20 -LeftMargin 20 -RightMargin 20 -Author "Patrick"

$pdf.Open()

Add-Text -Document $pdf -Text "1"
Add-Text -Document $pdf -Text "2"
Add-Text -Document $pdf -Text "3"
Add-Text -Document $pdf -Text "4"
Add-Text -Document $pdf -Text "5"
Add-Text -Document $pdf -Text "6"
Add-Text -Document $pdf -Text "7"
Add-Text -Document $pdf -Text "8"
Add-Text -Document $pdf -Text "9"
Add-Text -Document $pdf -Text "10"
Add-Text -Document $pdf -Text "11"
Add-Text -Document $pdf -Text "12"
Add-Text -Document $pdf -Text "13"
Add-Text -Document $pdf -Text "14"
Add-Text -Document $pdf -Text "15"
Add-Text -Document $pdf -Text "16"
Add-Text -Document $pdf -Text "17"
Add-Text -Document $pdf -Text "18"
Add-Text -Document $pdf -Text "19"
Add-Text -Document $pdf -Text "20"
Add-Text -Document $pdf -Text "21"
Add-Text -Document $pdf -Text "22"
Add-Text -Document $pdf -Text "23"
Add-Text -Document $pdf -Text "24"
Add-Text -Document $pdf -Text "25"
Add-Text -Document $pdf -Text "26"
Add-Text -Document $pdf -Text "27"
Add-Text -Document $pdf -Text "28"
Add-Text -Document $pdf -Text "29"
Add-Text -Document $pdf -Text "30"
Add-Text -Document $pdf -Text "31"
Add-Text -Document $pdf -Text "32"
Add-Text -Document $pdf -Text "33"
Add-Text -Document $pdf -Text "34"
Add-Text -Document $pdf -Text "35"
Add-Text -Document $pdf -Text "36"
Add-Text -Document $pdf -Text "37"
Add-Text -Document $pdf -Text "38"
Add-Text -Document $pdf -Text "39"
Add-Text -Document $pdf -Text "40"


Add-Title -Document $pdf -Text "Configuration de la messagerie sur Outlook" -Color "magenta" -Centered

Add-Text -Document $pdf -Text ""
Add-Text -Document $pdf -Text "Nous utilisons Outlook 2010"
Add-Text -Document $pdf -Text ""
Add-Text -Document $pdf -Text "Commencer par lancer l'application Outlook avec l'aide d'un des icones ci-dessous"

Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0003.jpg"

Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0004.jpg"



Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0002.jpg"

Add-Text -Document $pdf -Text ""
Add-Text -Document $pdf -Text "Dans l'application"

Add-Text -Document $pdf -Text ""
Add-Text -Document $pdf -Text "Nous arrivons dans la fenêtre ci-dessous"

Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001.jpg"

Add-Text -Document $pdf -Text "Nous devons remplir les champs vide avec les informaions contenu dans le tableau"
Add-Table -Document $pdf -Dataset @("Nom", "$Prenom.$Nom", "Adresse", "$SamAccountName", "Mot de passe", "String", "Confirmer le mot de passe", "String") -Cols 2 -Centered

Add-Text -Document $pdf -Text "Nous obtenons ceci"
Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-003.jpg"

Add-Text -Document $pdf -Text "Nous pouvons cliquer sur le bouton"
Add-Image -Document $pdf -File "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0005.jpg"

Add-Title -Document $pdf -Text "Configuration de la messagerie sur Iphone" -Color "magenta" -Centered

Add-Title -Document $pdf -Text "Configuration de la messagerie sur Androïd" -Color "magenta" -Centered

$pdf.Close()

Remove-Item -Path "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp.jpg" -Force
Remove-Item -Path "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-002.jpg" -Force
Remove-Item -Path "C:\Users\hcornet\Downloads\PowerShell-PDF-master\PowerShell-PDF-master\Outlook-0001-temp-003.jpg" -Force