Skip to content

Commit

Permalink
#10
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Aug 1, 2020
1 parent 753aaeb commit 4968834
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 9 deletions.
19 changes: 19 additions & 0 deletions Example/Example06.AddingTables/Example06.01.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Import-Module .\PSWritePDF.psd1 -Force

$Data1 = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)

$Data2 = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data3 = [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }

$FilePath = [IO.Path]::Combine("$PSScriptRoot", 'Example06.01.pdf')
New-PDF {
New-PDFTable -DataTable $Data1
New-PDFTable -DataTable $Data2
} -FilePath $FilePath

Close-PDF -Document $Document
6 changes: 3 additions & 3 deletions PSWritePDF.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Przemyslaw Klys
#
# Generated on: 21.07.2020
# Generated on: 01.08.2020
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSWritePDF.psm1'

# Version number of this module.
ModuleVersion = '0.0.8'
ModuleVersion = '0.0.9'

# Supported PSEditions
CompatiblePSEditions = 'Desktop', 'Core'
Expand Down Expand Up @@ -51,7 +51,7 @@
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'PSSharedGoods'; GUID = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe'; ModuleVersion = '0.0.160'; })
RequiredModules = @(@{ModuleName = 'PSSharedGoods'; GUID = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe'; ModuleVersion = '0.0.165'; })

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand Down
40 changes: 39 additions & 1 deletion Private/Class.Splitter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,42 @@
$Path = [IO.Path]::Combine($this._destinationFolder, $Name)
return [iText.Kernel.Pdf.PdfWriter]::new($Path)
}
}
}

# [iText.Kernel.Geom.Vector]::I1
<#
RenderText([iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo] $renderInfo) {
[string] $curFont = $renderInfo.GetFont().PostscriptFontName
#//Check if faux bold is used
if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText)) {
$curFont += "-Bold";
}
#//This code assumes that if the baseline changes then we're on a newline
[iText.Kernel.Geom.Vector] $curBaseline = $renderInfo.GetBaseline().GetStartPoint();
[iText.Kernel.Geom.Vector] $topRight = $renderInfo.GetAscentLine().GetEndPoint();
[iText.Kernel.Geom.Rectangle] $rect = [iText.Kernel.Geom.Rectangle]::new($curBaseline[Vector.I1], $curBaseline[Vector.I2], $topRight[Vector.I1], $topRight[Vector.I2]);
[Single] $curFontSize = $rect.Height;
#//See if something has changed, either the baseline, the font or the font size
if (($this.lastBaseLine -eq $null) -or ($curBaseline[Vector.I2] -ne $lastBaseLine[Vector.I2]) -or ($curFontSize -ne $lastFontSize) -or ($curFont -ne $lastFont)) {
#//if we've put down at least one span tag close it
if (($this.lastBaseLine -ne $null)) {
$this.result.AppendLine("</span>");
}
#//If the baseline has changed then insert a line break
if (($this.lastBaseLine -ne $null) -and ($curBaseline[Vector.I2] -ne $lastBaseLine[Vector.I2]) {
$this.result.AppendLine("<br />");
}
#//Create an HTML tag with appropriate styles
$this.result.AppendFormat("<span style=`"font-family: { 0 }; font-size: { 1 }`">", $curFont, $curFontSize);
}
#//Append the current text
$this.result.Append($renderInfo.GetText());
#//Set currently used properties
$this.lastBaseLine = curBaseline;
$this.lastFontSize = curFontSize;
$this.lastFont = curFont;
}
#>
10 changes: 5 additions & 5 deletions Publish/Manage-Module.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Clear-Host
Import-Module "C:\Support\GitHub\PSPublishModule\PSPublishModule.psm1" -Force
Import-Module 'C:\Support\GitHub\PSPublishModule\PSPublishModule.psm1' -Force

$Configuration = @{
Information = @{
Expand All @@ -15,7 +15,7 @@ $Configuration = @{
# ID used to uniquely identify this module
GUID = '19fcb43c-d8c5-44a9-84e4-bccf29765490'
# Version number of this module.
ModuleVersion = '0.0.8'
ModuleVersion = '0.0.X'
# Author of this module
Author = 'Przemyslaw Klys'
# Company or vendor of this module
Expand All @@ -34,7 +34,7 @@ $Configuration = @{
IconUri = 'https://evotec.xyz/wp-content/uploads/2019/11/PSWritePDF.png'

RequiredModules = @(
@{ ModuleName = 'PSSharedGoods'; ModuleVersion = "Latest"; Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe' }
@{ ModuleName = 'PSSharedGoods'; ModuleVersion = 'Latest'; Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe' }
)
}
}
Expand Down Expand Up @@ -153,10 +153,10 @@ $Configuration = @{
Verbose = $false
}
PublishModule = @{ # requires Enable to be on to process all of that
Enabled = $true
Enabled = $false
Prerelease = ''
RequireForce = $false
GitHub = $true
GitHub = $false
}
}
}
Expand Down
93 changes: 93 additions & 0 deletions Tests/New-PDFTable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

Describe 'New-PDF' {
New-Item -Path $PSScriptRoot -Force -ItemType Directory -Name 'Output'
It 'New-PDFTable should not throw when using 2 element array' {
$Data = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)

$FilePath = [IO.Path]::Combine("$PSScriptRoot", 'Output', 'PDFTable1.pdf')
New-PDF {
New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true

New-PDFTable -DataTable $Data
} -FilePath $FilePath

$Document = Get-PDF -FilePath $FilePath
$Details = Get-PDFDetails -Document $Document

Close-PDF -Document $Document

$Page1 = $Details.Pages.'1'
$Page1.Size | Should -Be 'A4'
$Page1.Rotated | Should -Be $false
$Details.PagesNumber | Should -Be 1
}
It 'New-PDFTable should not throw when using 1 element array' {
$Data = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)

$FilePath = [IO.Path]::Combine("$PSScriptRoot", 'Output', 'PDFTable2.pdf')
New-PDF {
New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true

New-PDFTable -DataTable $Data
} -FilePath $FilePath

$Document = Get-PDF -FilePath $FilePath
$Details = Get-PDFDetails -Document $Document

Close-PDF -Document $Document

$Page1 = $Details.Pages.'1'
$Page1.Size | Should -Be 'A4'
$Page1.Rotated | Should -Be $false
$Details.PagesNumber | Should -Be 1
}
It 'New-PDFTable should not throw when using multiple tables' {
$Data1 = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data2 = @(
[ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
[ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data3 = @(
@{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
@{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data4 = @(
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
[PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data5 = @(
[ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
)
$Data6 = [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }

$FilePath = [IO.Path]::Combine("$PSScriptRoot", 'Output', 'PDFTable3.pdf')
New-PDF {
New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true

New-PDFTable -DataTable $Data1
New-PDFTable -DataTable $Data2
New-PDFTable -DataTable $Data3
New-PDFTable -DataTable $Data4
New-PDFTable -DataTable $Data5
New-PDFTable -DataTable $Data6
} -FilePath $FilePath

$Document = Get-PDF -FilePath $FilePath
$Details = Get-PDFDetails -Document $Document

Close-PDF -Document $Document

$Page1 = $Details.Pages.'1'
$Page1.Size | Should -Be 'A4'
$Page1.Rotated | Should -Be $false
$Details.PagesNumber | Should -Be 1
}
}

0 comments on commit 4968834

Please sign in to comment.