├── .github
└── FUNDING.yml
├── CHANGELOG.MD
├── Example
├── Example01.HelloWorld
│ ├── Example01_MoreOptions.pdf
│ ├── Example01_MoreOptions.ps1
│ ├── Example01_Simple.pdf
│ ├── Example01_Simple.ps1
│ ├── Example01_Simple1.pdf
│ ├── Example01_Simple2.pdf
│ ├── Example01_Simple3-1.pdf
│ ├── Example01_Simple3-2.pdf
│ ├── Example01_Simple3-3.pdf
│ ├── Example01_Simple3.ps1
│ ├── Example01_Simple4.ps1
│ ├── Example01_WithSections.pdf
│ ├── Example01_WithSections.ps1
│ ├── Example01_WithSectionsMargins.pdf
│ ├── Example01_WithSectionsMargins.ps1
│ ├── Example01_WithSectionsMix.pdf
│ └── Example01_WithSectionsMix.ps1
├── Example02.Splitting
│ ├── Example02.ps1
│ ├── Output
│ │ ├── OutputDocument0.pdf
│ │ └── OutputDocument1.pdf
│ └── SampleToSplit.pdf
├── Example03.Merging
│ ├── Example03.MergeMultiple.ps1
│ ├── Example03.ps1
│ ├── Input
│ │ ├── OutputDocument0.pdf
│ │ └── OutputDocument1.pdf
│ └── Output
│ │ └── OutputDocument.pdf
├── Example03.MergingSign
│ ├── Example03.ps1
│ ├── Input
│ │ ├── sample01.pdf
│ │ └── sample06.pdf
│ └── Output
│ │ └── OutputDocument.pdf
├── Example04.ExtractText
│ ├── Example04.pdf
│ └── Example04.ps1
├── Example06.AddingTables
│ ├── Example06.01.pdf
│ ├── Example06.01.ps1
│ ├── Example06.pdf
│ └── Example06.ps1
├── Example07.Details
│ └── Examples07.Details.ps1
├── Example08.Forms
│ ├── Example.Forms.ps1
│ ├── Example.FormsFlattening.ps1
│ ├── Example.FormsFlatteningOnly.ps1
│ ├── Input
│ │ └── SampleAcroForm.pdf
│ └── Output
│ │ └── SampleAcroFormOutput.pdf
├── Example09.Images
│ ├── Evotec-Logo-600x190.png
│ ├── Example09-Images01.pdf
│ └── Example09-Images01.ps1
├── Example10.ConvertFromHTML
│ ├── Example10-FromFilePath.html
│ ├── Example10-FromFilePath.pdf
│ ├── Example10-FromFilePath.ps1
│ ├── Example10-FromHTML.pdf
│ ├── Example10-FromHTML.ps1
│ ├── Example10-FromURL.pdf
│ └── Example10-FromUri.ps1
└── ExperimentalCode
│ ├── CodeADSI.png
│ ├── Experiment1.pdf
│ ├── Experminent1.ps1
│ └── README.MD
├── Ignore
├── itext7.7.1.8
│ ├── LICENSE.md
│ ├── [Content_Types].xml
│ ├── _rels
│ │ └── .rels
│ ├── gnu-agpl-v3.0.md
│ ├── itext7.nuspec
│ ├── lib
│ │ ├── net40
│ │ │ ├── itext.barcodes.dll
│ │ │ ├── itext.barcodes.xml
│ │ │ ├── itext.forms.dll
│ │ │ ├── itext.forms.xml
│ │ │ ├── itext.io.dll
│ │ │ ├── itext.io.xml
│ │ │ ├── itext.kernel.dll
│ │ │ ├── itext.kernel.xml
│ │ │ ├── itext.layout.dll
│ │ │ ├── itext.layout.xml
│ │ │ ├── itext.pdfa.dll
│ │ │ ├── itext.pdfa.xml
│ │ │ ├── itext.sign.dll
│ │ │ ├── itext.sign.xml
│ │ │ ├── itext.styledxmlparser.dll
│ │ │ ├── itext.styledxmlparser.xml
│ │ │ ├── itext.svg.dll
│ │ │ └── itext.svg.xml
│ │ └── netstandard1.6
│ │ │ ├── itext.barcodes.dll
│ │ │ ├── itext.barcodes.xml
│ │ │ ├── itext.forms.dll
│ │ │ ├── itext.forms.xml
│ │ │ ├── itext.io.dll
│ │ │ ├── itext.io.xml
│ │ │ ├── itext.kernel.dll
│ │ │ ├── itext.kernel.xml
│ │ │ ├── itext.layout.dll
│ │ │ ├── itext.layout.xml
│ │ │ ├── itext.pdfa.dll
│ │ │ ├── itext.pdfa.xml
│ │ │ ├── itext.sign.dll
│ │ │ ├── itext.sign.xml
│ │ │ ├── itext.styledxmlparser.dll
│ │ │ ├── itext.styledxmlparser.xml
│ │ │ ├── itext.svg.dll
│ │ │ └── itext.svg.xml
│ └── package
│ │ └── services
│ │ └── metadata
│ │ └── core-properties
│ │ └── 078fff1771b243b6b33ef259c0510348.psmdcp
├── itext7.font-asian.7.1.8
│ ├── LICENSE.md
│ ├── [Content_Types].xml
│ ├── _rels
│ │ └── .rels
│ ├── gnu-agpl-v3.0.md
│ ├── itext7.font-asian.nuspec
│ ├── lib
│ │ ├── net40
│ │ │ ├── itext.font_asian.dll
│ │ │ └── itext.font_asian.xml
│ │ └── netstandard1.6
│ │ │ ├── itext.font_asian.dll
│ │ │ └── itext.font_asian.xml
│ └── package
│ │ └── services
│ │ └── metadata
│ │ └── core-properties
│ │ └── cc615427c8f142708565c9f448304c6d.psmdcp
├── itext7.hyph.7.1.8
│ ├── LICENSE.md
│ ├── [Content_Types].xml
│ ├── _rels
│ │ └── .rels
│ ├── gnu-agpl-v3.0.md
│ ├── itext7.hyph.nuspec
│ ├── lib
│ │ ├── net40
│ │ │ ├── itext.hyph.dll
│ │ │ └── itext.hyph.xml
│ │ └── netstandard1.6
│ │ │ ├── itext.hyph.dll
│ │ │ └── itext.hyph.xml
│ └── package
│ │ └── services
│ │ └── metadata
│ │ └── core-properties
│ │ └── 70a2355eefb24259bb87f4808da4b011.psmdcp
├── itext7.pdfhtml.2.1.5
│ ├── LICENSE.md
│ ├── [Content_Types].xml
│ ├── _rels
│ │ └── .rels
│ ├── gnu-agpl-v3.0.md
│ ├── itext7.pdfhtml.nuspec
│ ├── lib
│ │ ├── net40
│ │ │ ├── itext.html2pdf.dll
│ │ │ └── itext.html2pdf.xml
│ │ └── netstandard1.6
│ │ │ ├── itext.html2pdf.dll
│ │ │ └── itext.html2pdf.xml
│ └── package
│ │ └── services
│ │ └── metadata
│ │ └── core-properties
│ │ └── 8b965ce1289e4ca7920697e4c871992d.psmdcp
└── itext7.pdftest.7.1.8
│ ├── LICENSE.md
│ ├── [Content_Types].xml
│ ├── _rels
│ └── .rels
│ ├── gnu-agpl-v3.0.md
│ ├── itext7.pdftest.nuspec
│ ├── lib
│ ├── net40
│ │ ├── itext.pdftest.dll
│ │ └── itext.pdftest.xml
│ └── netstandard1.6
│ │ ├── itext.pdftest.dll
│ │ └── itext.pdftest.xml
│ └── package
│ └── services
│ └── metadata
│ └── core-properties
│ └── 8dc7e9802375404ebdbd16a556a096aa.psmdcp
├── LICENSE
├── Lib
├── Core
│ ├── BouncyCastle.Crypto.dll
│ ├── BouncyCastle.Crypto.xml
│ ├── Microsoft.DotNet.PlatformAbstractions.dll
│ ├── Microsoft.DotNet.PlatformAbstractions.xml
│ ├── Microsoft.Extensions.DependencyModel.dll
│ ├── Microsoft.Extensions.DependencyModel.xml
│ ├── Microsoft.Extensions.Logging.Abstractions.dll
│ ├── Microsoft.Extensions.Logging.dll
│ ├── Microsoft.Extensions.Options.dll
│ ├── itext.barcodes.dll
│ ├── itext.barcodes.xml
│ ├── itext.commons.dll
│ ├── itext.commons.xml
│ ├── itext.forms.dll
│ ├── itext.forms.xml
│ ├── itext.html2pdf.dll
│ ├── itext.html2pdf.xml
│ ├── itext.hyph.dll
│ ├── itext.hyph.xml
│ ├── itext.io.dll
│ ├── itext.io.xml
│ ├── itext.kernel.dll
│ ├── itext.kernel.xml
│ ├── itext.layout.dll
│ ├── itext.layout.xml
│ ├── itext.pdfa.dll
│ ├── itext.pdfa.xml
│ ├── itext.sign.dll
│ ├── itext.sign.xml
│ ├── itext.styledxmlparser.dll
│ ├── itext.styledxmlparser.xml
│ ├── itext.svg.dll
│ └── itext.svg.xml
├── Default
│ ├── BouncyCastle.Crypto.dll
│ ├── BouncyCastle.Crypto.xml
│ ├── Microsoft.Extensions.Logging.Abstractions.dll
│ ├── Microsoft.Extensions.Logging.dll
│ ├── Microsoft.Extensions.Options.dll
│ ├── itext.barcodes.dll
│ ├── itext.barcodes.xml
│ ├── itext.commons.dll
│ ├── itext.commons.xml
│ ├── itext.forms.dll
│ ├── itext.forms.xml
│ ├── itext.html2pdf.dll
│ ├── itext.html2pdf.xml
│ ├── itext.hyph.dll
│ ├── itext.hyph.xml
│ ├── itext.io.dll
│ ├── itext.io.xml
│ ├── itext.kernel.dll
│ ├── itext.kernel.xml
│ ├── itext.layout.dll
│ ├── itext.layout.xml
│ ├── itext.pdfa.dll
│ ├── itext.pdfa.xml
│ ├── itext.sign.dll
│ ├── itext.sign.xml
│ ├── itext.styledxmlparser.dll
│ ├── itext.styledxmlparser.xml
│ ├── itext.svg.dll
│ └── itext.svg.xml
└── LICENSE
├── PSWritePDF.AzurePipelines.yml
├── PSWritePDF.Tests.ps1
├── PSWritePDF.psd1
├── PSWritePDF.psm1
├── Private
├── Add-PDFDocumentContent.ps1
├── Class.Splitter.ps1
├── Class.TextWithFontExtractionStategy.ps1
├── Class.Validations.ps1
├── Get-InternalPDFFont.ps1
├── Get-PDFNamedPageSize.ps1
├── Initialize-PDF.ps1
├── New-InternalPDF.ps1
├── New-InternalPDFImage.ps1
├── New-InternalPDFList.ps1
├── New-InternalPDFOptions.ps1
├── New-InternalPDFPage.ps1
├── New-InternalPDFTable.ps1
├── New-InternalPDFText.ps1
├── Script.RGBColors.ps1
└── ScriptBlock.RGBColors.ps1
├── Public
├── Close-PDF.ps1
├── Constants
│ ├── Get-PDFConstantAction.ps1
│ ├── Get-PDFConstantColor.ps1
│ ├── Get-PDFConstantFont.ps1
│ ├── Get-PDFConstantPageSize.ps1
│ ├── Get-PDFConstantTextAlignment.ps1
│ └── Get-PDFConstantVersion.ps1
├── Get-PDF.ps1
├── Get-PDFDetails.ps1
├── Get-PDFFormField.ps1
├── New-PDF.ps1
├── New-PDFArea.ps1
├── New-PDFDocument.ps1
├── New-PDFImage.ps1
├── New-PDFInfo.ps1
├── New-PDFList.ps1
├── New-PDFListItem.ps1
├── New-PDFOptions.ps1
├── New-PDFPage.ps1
├── New-PDFTable.ps1
├── New-PDFText.ps1
├── Register-PDFFont.ps1
└── Standalone
│ ├── Convert-HtmlToPDF.ps1
│ ├── Convert-PDFToText.ps1
│ ├── Merge-PDF.ps1
│ ├── Set-PDFForm.ps1
│ └── Split-PDF.ps1
├── Publish
└── Manage-Module.ps1
├── README.md
└── Tests
├── Input
├── SampleAcroForm.pdf
└── SampleToSplit.pdf
├── New-PDF.Tests.ps1
├── New-PDFTable.Tests.ps1
└── Set-PDFForm.Tests.ps1
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: PrzemyslawKlys
4 | custom: https://paypal.me/PrzemyslawKlys
--------------------------------------------------------------------------------
/CHANGELOG.MD:
--------------------------------------------------------------------------------
1 | ## Changelog
2 |
3 | #### 0.0.20 - 2022.10.02
4 | - Added Text-Extractionstrategys [#40](https://github.com/EvotecIT/PSWritePDF/pull/40) - thank you **MathisDukatz**
5 |
6 | #### 0.0.19 - 2022.05.03
7 | - Library updated to itext 7.2.2
8 | - Fixes **Register-PDFFont** not registering fonts properly
9 |
10 | #### 0.0.18 - 2021.12.23
11 | - Added `New-PDFImage` basic functionality
12 | - Added `Convert-HTMLToPDF`
13 | - Added `IgnoreProtection` switch to `Get-PDF`, `Convert-PDFToText`, `Merge-PDF`, `Set-PDFForm`, `Split-PDF` - thank you @mccbryan3 [#29](https://github.com/EvotecIT/PSWritePDF/pull/29)
14 |
15 | #### 0.0.17 - 2021.05.23
16 | - ☑ `Set-PDFForm` can now flatten forms with `Flatten` switch. Thank you markdem! in [#23](https://github.com/EvotecIT/PSWritePDF/pull/23)
17 | - ☑ Improved `Set-PDFForm` by removing Out-Null and replacing it with $null which is faster
18 | - ☑ Improved `Set-PDFForm` logic
19 | #### 0.0.16 - 2021.05.06
20 | - ☑ Added basic support for check box style form fields - added by ChrisMagnuson in [#20](https://github.com/EvotecIT/PSWritePDF/pull/20)
21 | #### 0.0.15 - 2021.03.17
22 | - ☑ Implemented `Set-PDFForm` and `Get-PDFFormField` - added by ChrisMagnuson in [#19](https://github.com/EvotecIT/PSWritePDF/pull/19)
23 | #### 0.0.14 - 2021.03.11
24 | - ☑ Improved error handling
25 | #### 0.0.13 - 2021.03.09
26 | - ☑ Improved error handling
27 | #### 0.0.12 - 2021.03.09
28 | - ☑ Removed `Exit` in favor of `return`
29 | #### 0.0.11 - 2021.03.09
30 | - ☑ Added `Register-PDFFont` that allows adding custom fonts (see examples for usage)
31 | - ☑ This also allows to use unicode chars (the built-in fonts don't seem to have unicode)
32 | - ☑ Usage: `Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default`
33 | - ☑ Improved `New-PDFListItem` allowing same options as `New-PDFText`
34 | #### 0.0.10 - 2020.8.3
35 | - ☑ Fixed issue with `New-PDFText` - problem with `Remove-EmptyValue`
36 | #### 0.0.9 - 2020.8.1
37 | - ☑ Fixed problem with `Remove-EmptyValue`
38 | #### 0.0.8 - 2020.7.21
39 | - Fixes
40 | - ☑ Silly mistake for processing hasthables - tnx Greyland99 [#7](https://github.com/EvotecIT/PSWritePDF/issues/7)
41 | - Updates
42 | - ☑ Module (psm1/ps1/psd1) and all it's DLL's are now signed. Hopefully it won't break anything
43 |
44 | #### 0.0.7 - 2020.05.02
45 | - Fixes
46 | - ☑ Fix for UNC paths [#4](https://github.com/EvotecIT/PSWritePDF/issues/4) - tnx sporkabob
47 | - ☑ Fix for `Split-PDF` not closing source file
48 | - ☑ Fix for `Convert-PDFToText` not closing source file
49 |
50 | #### 0.0.6 - 2020.01.14
51 | - Fixes
52 | - ☑ Added missing `[CmdletBinding()]`
53 | - ☑ Fixes New-PDF crash if no FilePath is given (#3)
54 |
55 | #### 0.0.5 - 2019.12.28
56 | - Fixes
57 | - ☑ Margins support in multiple scenarios
58 | - Additional commands
59 | - ☑ Get-PDF
60 | - ☑ Get-PDFDetails
61 | - ☑ Close-PDF
62 | - Updated iText to 7.1.9
63 |
64 | #### 0.0.4 - 2019.11.29
65 | - ☑ Convert-PDFToText - Fix for resolving paths properly
66 | - ☑ Split-PDF - fix for resolving paths properly
67 | - ☑ Merge-PDF - fix for resolving paths properly
68 | #### 0.0.3 - 2019.11.29
69 | - Fix for loading module from PowerShellGallery
70 |
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_MoreOptions.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_MoreOptions.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_MoreOptions.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF -MarginLeft 520 { #520 -MarginRight 20 -MarginTop 20 -MarginBottom 20 -PageSize B4 -Rotate {
4 | New-PDFText -Text 'Test ', 'Me', 'Oooh' -FontColor BLUE, YELLOW, RED
5 | New-PDFList {
6 | New-PDFListItem -Text 'Test'
7 | New-PDFListItem -Text '2nd'
8 | }
9 | } -FilePath "$PSScriptRoot\Example01_MoreOptions.pdf" -Show
10 |
11 | $Document = Get-PDF -FilePath "$PSScriptRoot\Example01_MoreOptions.pdf"
12 | $Details = Get-PDFDetails -Document $Document
13 | $Details | Format-List
14 | $Details.Pages | Format-Table
15 |
16 | Close-PDF -Document $Document
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF {
4 | Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
5 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
6 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
7 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
8 | New-PDFList -Indent 3 {
9 | New-PDFListItem -Text 'Test'
10 | New-PDFListItem -Text '2nd'
11 | }
12 |
13 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
14 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
15 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
16 | New-PDFText -Text 'Following text written in polish with default font Verdana that we set in the beggining: '
17 | New-PDFText -Text 'Polski tekst ma się dobrze, tak dobrze, że aż za dobrze'
18 | New-PDFText -Text 'łomatko' -Font 'HELVETICA'
19 | New-PDFList -Indent 3 {
20 | New-PDFListItem -Text 'Test'
21 | New-PDFListItem -Text '2nd'
22 | New-PDFListItem -Text 'ąłęć - unicode with Verdana must work', ' and bold' -FontBold $null, $true -Font Verdana, HELVETICA -FontColor GRAY, BLUE
23 | New-PDFListItem -Text 'ąłęć - must work', ' and bold'
24 | }
25 | } -FilePath "$PSScriptRoot\Example01_Simple.pdf" -Show
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple1.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple2.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple3-1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple3-1.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple3-2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple3-2.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple3-3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_Simple3-3.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple3.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | # This shows handling of edge cases where this shouldnt throw errors, but warnings.
4 |
5 | New-PDF -FilePath "$PSScriptRoot\Example01_Simple3-1.pdf" -PDFContent {
6 | Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
7 | New-PDFText -Text 'Hello ', 'Привет !'
8 | } -Show
9 | New-PDF -FilePath "$PSScriptRoot\Example01_Simple3-2.pdf" -PDFContent {
10 | Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
11 | New-PDFText -Text 'Hello ', 'Привет !'
12 | } -Show
13 |
14 | New-PDF -FilePath "$PSScriptRoot\Example01_Simple3-3.pdf" -PDFContent {
15 |
16 | }
17 |
18 | New-PDF -FilePath "D:\Example01_Simple2.pdf" -PDFContent { 'Test' }
19 |
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_Simple4.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF -FilePath "D:\Example01_Simple4.1.pdf" -PDFContent { New-PDFText -Text 'Hello ', 'Привет !' } -Show
4 | New-PDF -FilePath "D:\Example01_Simple4.2.pdf" -PDFContent {
5 | Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
6 | New-PDFText -Text 'Hello ', 'Привет !'
7 | } -Show
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSections.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_WithSections.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSections.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF {
4 | New-PDFPage -PageSize A5 -MarginLeft 150 {
5 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
6 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
7 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
8 | New-PDFList -Indent 3 {
9 | New-PDFListItem -Text 'Test'
10 | New-PDFListItem -Text '2nd'
11 | }
12 | }
13 | New-PDFPage -PageSize A4 -Rotate -MarginTop 10 -MarginLeft 10 {
14 | New-PDFText -Text 'Hello 1', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
15 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
16 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
17 | New-PDFList -Indent 3 {
18 | New-PDFListItem -Text 'Test'
19 | New-PDFListItem -Text '2nd'
20 | }
21 | }
22 | } -FilePath "$PSScriptRoot\Example01_WithSections.pdf" -Show
23 |
24 | $Document = Get-PDF -FilePath "$PSScriptRoot\Example01_WithSections.pdf"
25 | $Details = Get-PDFDetails -Document $Document
26 | $Details | Format-List
27 | $Details.Pages | Format-Table
28 | Close-PDF -Document $Document
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSectionsMargins.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_WithSectionsMargins.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSectionsMargins.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF -MarginTop 200 {
4 | New-PDFPage -PageSize A5 {
5 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
6 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
7 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
8 | New-PDFList -Indent 3 {
9 | New-PDFListItem -Text 'Test'
10 | New-PDFListItem -Text '2nd'
11 | }
12 | }
13 | New-PDFPage -PageSize A4 -Rotate -MarginLeft 10 -MarginTop 50 {
14 | New-PDFText -Text 'Hello 1', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
15 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
16 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
17 | New-PDFList -Indent 3 {
18 | New-PDFListItem -Text 'Test'
19 | New-PDFListItem -Text '2nd'
20 | }
21 | }
22 | } -FilePath "$PSScriptRoot\Example01_WithSectionsMargins.pdf" -Show
23 |
24 | $Document = Get-PDF -FilePath "$PSScriptRoot\Example01_WithSections.pdf"
25 | $Details = Get-PDFDetails -Document $Document
26 | $Details | Format-List
27 | $Details.Pages | Format-Table
28 | Close-PDF -Document $Document
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSectionsMix.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example01.HelloWorld/Example01_WithSectionsMix.pdf
--------------------------------------------------------------------------------
/Example/Example01.HelloWorld/Example01_WithSectionsMix.ps1:
--------------------------------------------------------------------------------
1 | #Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF -PageSize A4 -Rotate {
4 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
5 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
6 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
7 | New-PDFList -Indent 3 {
8 | New-PDFListItem -Text 'Test'
9 | New-PDFListItem -Text '2nd'
10 | }
11 |
12 | New-PDFPage -PageSize A5 {
13 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
14 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
15 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
16 | New-PDFList -Indent 3 {
17 | New-PDFListItem -Text 'Test'
18 | New-PDFListItem -Text '2nd'
19 | }
20 | }
21 |
22 | } -FilePath "$PSScriptRoot\Example01_WithSectionsMix.pdf" -Show
--------------------------------------------------------------------------------
/Example/Example02.Splitting/Example02.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | Split-PDF -FilePath "$PSScriptRoot\SampleToSplit.pdf" -OutputFolder "$PSScriptRoot\Output"
4 |
5 | Split-PDF -FilePath "\\ad1\c$\SampleToSplit.pdf" -OutputFolder "\\ad1\c$\Output"
--------------------------------------------------------------------------------
/Example/Example02.Splitting/Output/OutputDocument0.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example02.Splitting/Output/OutputDocument0.pdf
--------------------------------------------------------------------------------
/Example/Example02.Splitting/Output/OutputDocument1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example02.Splitting/Output/OutputDocument1.pdf
--------------------------------------------------------------------------------
/Example/Example02.Splitting/SampleToSplit.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example02.Splitting/SampleToSplit.pdf
--------------------------------------------------------------------------------
/Example/Example03.Merging/Example03.MergeMultiple.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | # get all files to merge
4 | $Files = Get-ChildItem -LiteralPath "C:\Temp\AllFiles" -Filter "*.pdf" -Recurse
5 | # start with first file
6 | $FirstFile = $Files[0].FullName
7 | for ($i = 1; $i -lt $Files.Count; $i++) {
8 | # get the file to merge
9 | $File = $Files[$i]
10 | # define where to merge the file
11 | $OutputFile = "C:\Temp\MergedFile$i.pdf"
12 | Write-Host -ForegroundColor Green -Object "Merging $FirstFile and $($File.FullName) to $OutputFile"
13 | # merge first file with the next file
14 | Merge-PDF -InputFile $FirstFile, $File.FullName -OutputFile $OutputFile
15 | # delete the first merged file if it exists
16 | $OldOutputFile = "C:\Temp\MergedFile$($i-1).pdf"
17 | if (Test-Path -LiteralPath $OldOutputFile) {
18 | Remove-Item -LiteralPath $OldOutputFile
19 | }
20 | # assign the output file as the first file for the next iteration
21 | $FirstFile = $OutputFile
22 | }
--------------------------------------------------------------------------------
/Example/Example03.Merging/Example03.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $FilePath1 = "$PSScriptRoot\Input\OutputDocument0.pdf"
4 | $FilePath2 = "$PSScriptRoot\Input\OutputDocument1.pdf"
5 |
6 | $OutputFile = "$PSScriptRoot\Output\OutputDocument.pdf" # Shouldn't exist / will be overwritten
7 |
8 | Merge-PDF -InputFile $FilePath1, $FilePath2 -OutputFile $OutputFile -Verbose
--------------------------------------------------------------------------------
/Example/Example03.Merging/Input/OutputDocument0.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.Merging/Input/OutputDocument0.pdf
--------------------------------------------------------------------------------
/Example/Example03.Merging/Input/OutputDocument1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.Merging/Input/OutputDocument1.pdf
--------------------------------------------------------------------------------
/Example/Example03.Merging/Output/OutputDocument.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.Merging/Output/OutputDocument.pdf
--------------------------------------------------------------------------------
/Example/Example03.MergingSign/Example03.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $FilePath = Get-ChildItem -Path $PSScriptRoot\Input -Filter *.pdf
4 | $OutputFile = "$PSScriptRoot\Output\OutputDocument.pdf" # Shouldn't exist / will be overwritten
5 |
6 | Merge-PDF -InputFile $FilePath.FullName -OutputFile $OutputFile
--------------------------------------------------------------------------------
/Example/Example03.MergingSign/Input/sample01.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.MergingSign/Input/sample01.pdf
--------------------------------------------------------------------------------
/Example/Example03.MergingSign/Input/sample06.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.MergingSign/Input/sample06.pdf
--------------------------------------------------------------------------------
/Example/Example03.MergingSign/Output/OutputDocument.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example03.MergingSign/Output/OutputDocument.pdf
--------------------------------------------------------------------------------
/Example/Example04.ExtractText/Example04.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example04.ExtractText/Example04.pdf
--------------------------------------------------------------------------------
/Example/Example04.ExtractText/Example04.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | # Get all pages text
4 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf"
5 |
6 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -ExtractionStrategy LocationTextExtractionStrategy
7 |
8 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -ExtractionStrategy SimpleTextExtractionStrategy
9 |
10 | # Get page 1 text only
11 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -Page 1 -IgnoreProtection
--------------------------------------------------------------------------------
/Example/Example06.AddingTables/Example06.01.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example06.AddingTables/Example06.01.pdf
--------------------------------------------------------------------------------
/Example/Example06.AddingTables/Example06.01.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $Data1 = @(
4 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
5 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
6 | )
7 |
8 | $Data2 = @(
9 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
10 | )
11 | $Data3 = [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
12 |
13 | $FilePath = [IO.Path]::Combine("$PSScriptRoot", 'Example06.01.pdf')
14 | New-PDF {
15 | New-PDFTable -DataTable $Data1
16 | New-PDFTable -DataTable $Data2
17 | } -FilePath $FilePath
18 |
19 | Close-PDF -Document $Document
--------------------------------------------------------------------------------
/Example/Example06.AddingTables/Example06.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example06.AddingTables/Example06.pdf
--------------------------------------------------------------------------------
/Example/Example06.AddingTables/Example06.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $DataTable123 = @(
4 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
5 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
6 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
7 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
8 | )
9 |
10 | $DataTable1234 = @(
11 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
12 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
13 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
14 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
15 | )
16 |
17 | $DataTable12345 = [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
18 |
19 | New-PDF {
20 | New-PDFText -Text 'Hello ', 'World' -Font HELVETICA, TIMES_ITALIC -FontColor GRAY, BLUE -FontBold $true, $false, $true
21 | New-PDFText -Text 'Testing adding text. ', 'Keep in mind that this works like array.' -Font HELVETICA -FontColor RED
22 | New-PDFText -Text 'This text is going by defaults.', ' This will continue...', ' and we can continue working like that.'
23 |
24 | New-PDFText -Text 'This table is representation of ', 'PSCustomObject', ' or other', ', ', 'standard types' -FontColor BLACK, RED, BLACK, BLACK, RED -FontBold $false, $true, $false, $false, $true
25 |
26 | New-PDFTable -DataTable $DataTable123
27 |
28 | New-PDFText -Text 'This shows how to create a list' -FontColor MAGENTA
29 |
30 | New-PDFList -Indent 3 {
31 | New-PDFListItem -Text 'Test'
32 | New-PDFListItem -Text '2nd'
33 | }
34 |
35 | New-PDFText -Text 'This table is representation of ', 'Array of Hashtable/OrderedDictionary' -FontColor BLACK, BLUE
36 |
37 | New-PDFTable -DataTable $DataTable1234
38 |
39 | New-PDFText -Text 'This table is representation of ', 'Hashtable/OrderedDictionary' -FontColor BLACK, BLUE
40 |
41 | New-PDFTable -DataTable $DataTable12345
42 |
43 | } -FilePath "$PSScriptRoot\Example06.pdf" -Show
--------------------------------------------------------------------------------
/Example/Example07.Details/Examples07.Details.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $Document = Get-PDF -FilePath "C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSWritePDF\Example\Example01.HelloWorld\Example01_WithSectionsMix.pdf"
4 | $Details = Get-PDFDetails -Document $Document
5 | $Details | Format-List
6 | $Details.Pages | Format-Table
7 |
8 | Close-PDF -Document $Document
--------------------------------------------------------------------------------
/Example/Example08.Forms/Example.Forms.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $FilePath = [IO.Path]::Combine("$PSScriptRoot", "Output", "SampleAcroFormOutput.pdf")
4 | $FilePathSource = [IO.Path]::Combine("$PSScriptRoot", "Input", "SampleAcroForm.pdf")
5 |
6 | $FieldNameAndValueHashTable = [ordered] @{
7 | "Text 1" = "Text 1 input"
8 | "Text 2" = "Text 2 input"
9 | "Text 3" = "Text 3 input"
10 | "Check Box 1 True" = $true
11 | "Check Box 2 False" = $false
12 | "Check Box 3 False" = $false
13 | "Check Box 4 True" = $true
14 | "Doesn't Exist" = "will not be used"
15 | }
16 |
17 | Set-PDFForm -SourceFilePath $FilePathSource -DestinationFilePath $FilePath -FieldNameAndValueHashTable $FieldNameAndValueHashTable
18 |
19 | # Reading PDF forms
20 | $PDF = Get-PDF -FilePath $FilePath
21 | $AcrobatFormFields = Get-PDFFormField -PDF $PDF
22 | $AcrobatFormFields | Format-Table
23 | Close-PDF -Document $PDF
--------------------------------------------------------------------------------
/Example/Example08.Forms/Example.FormsFlattening.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $FilePath = [IO.Path]::Combine("$PSScriptRoot", "Output", "SampleAcroFormOutput.pdf")
4 | $FilePathSource = [IO.Path]::Combine("$PSScriptRoot", "Input", "SampleAcroForm.pdf")
5 |
6 | $FieldNameAndValueHashTable = [ordered] @{
7 | "Text 1" = "Text 1 input"
8 | "Text 2" = "Text 2 input"
9 | "Text 3" = "Text 3 input"
10 | "Check Box 1 True" = $true
11 | "Check Box 2 False" = $false
12 | "Check Box 3 False" = $false
13 | "Check Box 4 True" = $true
14 | "Doesn't Exist" = "will not be used"
15 | }
16 |
17 | Set-PDFForm -SourceFilePath $FilePathSource -DestinationFilePath $FilePath -FieldNameAndValueHashTable $FieldNameAndValueHashTable -Flatten
18 |
19 |
20 | # Reading PDF forms
21 | $PDF = Get-PDF -FilePath $FilePath
22 | $AcrobatFormFields = Get-PDFFormField -PDF $PDF
23 | $AcrobatFormFields | Format-Table
24 | Close-PDF -Document $PDF
25 |
--------------------------------------------------------------------------------
/Example/Example08.Forms/Example.FormsFlatteningOnly.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $FilePathSource = [IO.Path]::Combine("$PSScriptRoot", "Input", "SampleAcroForm.pdf")
4 | #$FilePath = [IO.Path]::Combine("$PSScriptRoot", "Output", "SampleAcroFormOutput.pdf")
5 | $FilePath = ".\Example\Example08.Forms\Output\SampleAcroFormOutput.pdf"
6 |
7 | Set-PDFForm -SourceFilePath $FilePathSource -DestinationFilePath $FilePath -Flatten
--------------------------------------------------------------------------------
/Example/Example08.Forms/Input/SampleAcroForm.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example08.Forms/Input/SampleAcroForm.pdf
--------------------------------------------------------------------------------
/Example/Example08.Forms/Output/SampleAcroFormOutput.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example08.Forms/Output/SampleAcroFormOutput.pdf
--------------------------------------------------------------------------------
/Example/Example09.Images/Evotec-Logo-600x190.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example09.Images/Evotec-Logo-600x190.png
--------------------------------------------------------------------------------
/Example/Example09.Images/Example09-Images01.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example09.Images/Example09-Images01.pdf
--------------------------------------------------------------------------------
/Example/Example09.Images/Example09-Images01.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-PDF -MarginLeft 20 { #520 -MarginRight 20 -MarginTop 20 -MarginBottom 20 -PageSize B4 -Rotate {
4 | New-PDFImage -ImagePath "$PSScriptRoot\Evotec-Logo-600x190.png" -BackgroundColor Red -BackgroundColorOpacity 0.5
5 | New-PDFImage -ImagePath "$PSScriptRoot\Evotec-Logo-600x190.png"
6 | New-PDFText -Text 'Test ', 'Me', 'Oooh' -FontColor BLUE, YELLOW, RED
7 | New-PDFList {
8 | New-PDFListItem -Text 'Test'
9 | New-PDFListItem -Text '2nd'
10 | }
11 | } -FilePath "$PSScriptRoot\Example09-Images01.pdf" -Show
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromFilePath.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example10.ConvertFromHTML/Example10-FromFilePath.pdf
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromFilePath.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | New-HTML {
4 | New-HTMLTable -DataTable (Get-Process | Select-Object -First 3)
5 | } -FilePath "$PSScriptRoot\Example10-FromFilePath.html" -Online
6 |
7 | Convert-HTMLToPDF -FilePath "$PSScriptRoot\Example10-FromFilePath.html" -OutputFilePath "$PSScriptRoot\Example10-FromFilePath.pdf" -Open
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromHTML.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example10.ConvertFromHTML/Example10-FromHTML.pdf
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromHTML.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | $HTMLInput = New-HTML {
4 | New-HTMLText -Text 'Test 1'
5 | New-HTMLTable -DataTable (Get-Process | Select-Object -First 3)
6 | }
7 |
8 | Convert-HTMLToPDF -Content $HTMLInput -OutputFilePath "$PSScriptRoot\Example10-FromHTML.pdf" -Open
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromURL.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/Example10.ConvertFromHTML/Example10-FromURL.pdf
--------------------------------------------------------------------------------
/Example/Example10.ConvertFromHTML/Example10-FromUri.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 | Convert-HTMLToPDF -Uri 'https://evotec.xyz/hub/scripts/pswritehtml-powershell-module/' -OutputFilePath "$PSScriptRoot\Example10-FromURL.pdf" -Open
--------------------------------------------------------------------------------
/Example/ExperimentalCode/CodeADSI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/ExperimentalCode/CodeADSI.png
--------------------------------------------------------------------------------
/Example/ExperimentalCode/Experiment1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EvotecIT/PSWritePDF/fb1afeba53f5ba21b3cf1d562881a98d8843b086/Example/ExperimentalCode/Experiment1.pdf
--------------------------------------------------------------------------------
/Example/ExperimentalCode/Experminent1.ps1:
--------------------------------------------------------------------------------
1 | Import-Module .\PSWritePDF.psd1 -Force
2 |
3 |
4 | $DataTable1 = @(
5 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
6 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
7 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
8 | [PSCustomObject] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
9 | )
10 |
11 | $DataTable2 = @(
12 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
13 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
14 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
15 | [ordered] @{ Test = 'Name'; Test2 = 'Name2'; Test3 = 'Name3' }
16 | )
17 |
18 | $OutputFile = "$PSScriptRoot\Experiment1.pdf"
19 |
20 | $PDF = New-PDF -PageSize A4 -Rotate -FilePath $OutputFile
21 |
22 | New-PDFInfo -PDF $PDF -Title 'PSWritePDF Example' -Creator 'Przemyslaw Klys' -AddModificationDate -AddCreationDate
23 |
24 | $Document = New-PDFDocument -PDF $PDF
25 |
26 | $Text = New-PDFText -Text "Be prepared to read a story about a London lawyer named Gabriel John Utterson who investigates strange occurrences between his old friend, Dr. Henry Jekyll, and the evil Edward Hyde."
27 | $null = $Document.Add($Text)
28 |
29 | $AreaBreak1 = New-PDFArea -Rotate -PageSize B3
30 |
31 | $null = $Document.Add($AreaBreak1)
32 |
33 | $Table1 = New-PDFTable -DataTable $DataTable2
34 | $null = $Document.Add($Table1)
35 |
36 |
37 | $AreaBreak2 = New-PDFArea -PageSize A4 #-Rotate
38 | $null = $Document.Add($AreaBreak2)
39 |
40 | $Text = New-PDFText -Text "Be prepared to read a story about a London lawyer named Gabriel John Utterson who investigates strange occurrences between his old friend, Dr. Henry Jekyll, and the evil Edward Hyde."
41 | $null = $Document.Add($Text)
42 |
43 |
44 | $AreaBreak1 = New-PDFArea -PageSize A4
45 | $null = $Document.Add($AreaBreak1)
46 |
47 | $Text = New-PDFText -Text "Be prepared to read a story about a London lawyer named Gabriel John Utterson who investigates strange occurrences between his old friend, Dr. Henry Jekyll, and the evil Edward Hyde."
48 | $Null = $Document.Add($Text)
49 | #>
50 | $Document.Close()
51 | if (Test-Path -LiteralPath $OutputFile) {
52 | Invoke-Item -LiteralPath $OutputFile
53 | }
54 |
55 |
56 | <#
57 | iText.Layout.Renderer.DocumentRenderer new(iText.Layout.Document document)
58 | iText.Layout.Renderer.DocumentRenderer new(iText.Layout.Document document, bool immediateFlush)
59 | #>
60 | #$DocumentRenderer = [iText.Layout.Renderer.DocumentRenderer]::new
61 |
62 | <#
63 | iText.Layout.ColumnDocumentRenderer new(iText.Layout.Document document, iText.Kernel.Geom.Rectangle[] columns)
64 | iText.Layout.ColumnDocumentRenderer new(iText.Layout.Document document, bool immediateFlush, iText.Kernel.Geom.Rectangle[] columns)
65 | #>
66 | #$ColumnRenderer = [iText.Layout.ColumnDocumentRenderer]::new($Document)
67 |
68 | #$Document.SetRenderer
69 |
70 |
71 |
72 |
73 | #$PDFPage = $PDF.AddNewPage([iText.Kernel.Geom.PageSize]::A4)
74 |
75 | #$PageSize = [iText.Kernel.Geom.PageSize]::A4
76 | #$PageSize = $Pagesize.Rotate()
77 |
78 |
79 |
80 | #$Text1 = New-PDFText -Text 'test2'
81 |
82 | #$AreaBreak1 = [iText.Layout.Element.AreaBreak]::new($PageSize)
83 | #$AreaBreak.
84 | #$Document.add($AreaBreak1)
85 |
86 | <#
87 | iText.Layout.Element.AreaBreak new()
88 | iText.Layout.Element.AreaBreak new(System.Nullable[iText.Layout.Properties.AreaBreakType] areaBreakType)
89 | iText.Layout.Element.AreaBreak new(iText.Kernel.Geom.PageSize pageSize)
90 |
91 | #>
92 |
93 | #$Rectangle = [iText.Kernel.Geom.Rectangle]::new(36, 650, 100, 100)
94 | #$Canvas = [iText.Layout.Canvas]::new($PDFPage, $Rectangle)
95 |
96 | #$Can = [iText.Kernel.Pdf.Canvas.PdfCanvas]::new($PDFPage)
97 | #$Can.Add('t')
98 |
99 | #[iText.Layout.RootElement] $T = [iText.Layout.RootElement]
100 |
101 | <#
102 | iText.Layout.Canvas new(iText.Kernel.Pdf.PdfPage page, iText.Kernel.Geom.Rectangle rootArea)
103 | iText.Layout.Canvas new(iText.Kernel.Pdf.Canvas.PdfCanvas pdfCanvas, iText.Kernel.Pdf.PdfDocument pdfDocument, iText.Kernel.Geom.Rectangle rootArea)
104 | iText.Layout.Canvas new(iText.Kernel.Pdf.Canvas.PdfCanvas pdfCanvas, iText.Kernel.Pdf.PdfDocument pdfDocument, iText.Kernel.Geom.Rectangle rootArea, bool immediateFlush)
105 | iText.Layout.Canvas new(iText.Kernel.Pdf.Xobject.PdfFormXObject formXObject, iText.Kernel.Pdf.PdfDocument pdfDocument)
106 |
107 | #>
108 |
109 | #$PDFPage = $PDF.AddNewPage($PageSize)
110 |
111 |
112 |
113 | #$Canvas = [iText.Kernel.Pdf.Canvas.PdfCanvas]::new($PDFPage)
114 | #$Canvas.AddXObject
115 | <#
116 | iText.Kernel.Pdf.Canvas.PdfCanvas new(iText.Kernel.Pdf.PdfStream contentStream, iText.Kernel.Pdf.PdfResources resources, iText.Kernel.Pdf.PdfDocument document)
117 | iText.Kernel.Pdf.Canvas.PdfCanvas new(iText.Kernel.Pdf.PdfPage page)
118 | iText.Kernel.Pdf.Canvas.PdfCanvas new(iText.Kernel.Pdf.PdfPage page, bool wrapOldContent)
119 | iText.Kernel.Pdf.Canvas.PdfCanvas new(iText.Kernel.Pdf.Xobject.PdfFormXObject xObj, iText.Kernel.Pdf.PdfDocument document)
120 | iText.Kernel.Pdf.Canvas.PdfCanvas new(iText.Kernel.Pdf.PdfDocument doc, int pageNum)
121 | #>
122 |
123 | #$Rectangle = [iText.Kernel.Geom.Rectangle]::new(36, 650, 100, 100)
124 |
125 |
126 | #[iText.Layout.Document] $Document = [iText.Layout.Document]::new($PDF)
127 |
128 |
129 | #[int] $n = $pdf.getNumberOfPages();
130 |
131 | #for ($page = 1; $page -le $n; $page++) {
132 | # [iText.Layout.Element.Paragraph] $footer = [iText.Layout.Element.Paragraph]::new("Page nr $Page of $n")
133 | # $Document.ShowTextAligned($footer, 297.5, 20, $page, [iText.Layout.Properties.TextAlignment]::CENTER, [iText.Layout.Properties.VerticalAlignment]::MIDDLE, 0)
134 |
135 | <#
136 | iText.Layout.Document ShowTextAligned(string text, float x, float y, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign)
137 | iText.Layout.Document ShowTextAligned(string text, float x, float y, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign, float angle)
138 | iText.Layout.Document ShowTextAligned(string text, float x, float y, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign, System.Nullable[iText.Layout.Properties.VerticalAlignment] vertAlign, float angle)
139 | iText.Layout.Document ShowTextAligned(iText.Layout.Element.Paragraph p, float x, float y, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign)
140 | iText.Layout.Document ShowTextAligned(iText.Layout.Element.Paragraph p, float x, float y, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign, System.Nullable[iText.Layout.Properties.VerticalAlignment] vertAlign)
141 | iText.Layout.Document ShowTextAligned(iText.Layout.Element.Paragraph p, float x, float y, int pageNumber, System.Nullable[iText.Layout.Properties.TextAlignment] textAlign, System.Nullable[iText.Layout.Properties.VerticalAlignment] vertAlign, float radAngle)
142 | #>
143 | #}
144 | #document.close();
145 |
146 |
147 | #$PDF.GetCatalog().
148 |
149 | <#
150 |
151 | $Table = New-PDFTable -DataTable $DataTable1
152 | $null = $Document.Add($Table)
153 | #>
154 |
155 |
156 | # Add image
157 | <#
158 | $FoxPNG = "$PSScriptRoot\CodeADSI.png"
159 | $Fox = [iText.IO.Image.ImageDataFactory]::Create($FoxPNG)
160 | [iText.Layout.Element.Image] $foxImage = [iText.Layout.Element.Image]::new($Fox)
161 | $Document.Add($foxImage)
162 | #>
163 |
164 |
165 |
166 | <#
167 | # Another table
168 | $Table1 = New-PDFTable -DataTable $DataTable2
169 | $null = $Document.Add($Table1)
170 |
171 | #>
172 | #[iText.Kernel.Pdf.PdfName] $Name = [iText.Kernel.Pdf.PdfName].
173 | #$info.SetMoreInfo('something','something else')
174 |
175 | <#
176 | $PageSize = [iText.Kernel.Geom.PageSize]::A4
177 | $PDFPage = $PDF.AddNewPage($PageSize)
178 |
179 | $PageSize = [iText.Kernel.Geom.PageSize]::A10
180 | $PDFPage = $PDF.AddNewPage($PageSize)
181 |
182 | [iText.Layout.Document] $Document1 = [iText.Layout.Document]::new($PDFPage)
183 |
184 | $Table = New-PDFTable -DataTable $DataTable2
185 | $null = $Document1.Add($Table)
186 |
187 | $PDFPage.GetRotation()
188 | #$PDFPage.
189 | #>
190 | #$pdf.SetDefaultPageSize([iText.Kernel.Geom.PageSize]::A4.Rotate())
191 |
192 |
193 | #[iText.Kernel.Pdf.PdfDocument] $PDF = [iText.Kernel.Pdf.PdfDocument]::new($Writer);
194 | #[iText.Layout.Document] $Document = [iText.Layout.Document]::new($PDF)
195 |
196 | #$Table = New-PDFTable -DataTable $DataTable2
197 | #$null = $Document.Add($Table)
198 |
199 | <#
200 |
201 | #[iText.layout.element.Table] $Table = [iText.layout.element.Table]::new([iText.Layout.Properties.UnitValue]::CreatePercentArray(8)).useAllAvailableWidth()
202 | [iText.layout.element.Table] $Table = [iText.layout.element.Table]::new(10).UseAllAvailableWidth()
203 |
204 | for ($i = 0; $i -lt 16; $i++) {
205 | $Paragraph = New-PDFText -Text 'Hello in Cell' -FontColor BLUE
206 |
207 | [iText.Layout.Element.Cell] $Cell = [iText.Layout.Element.Cell]::new().Add($Paragraph)
208 | $null = $table.AddCell($Cell)
209 | }
210 |
211 | $null = $Document.Add($Table)
212 | #>
--------------------------------------------------------------------------------
/Example/ExperimentalCode/README.MD:
--------------------------------------------------------------------------------
1 | DO NOT USE, THIS IS EXPERIMENTAL CODE
2 | NOT FOR USE
--------------------------------------------------------------------------------
/Ignore/itext7.7.1.8/LICENSE.md:
--------------------------------------------------------------------------------
1 | This program is free software; you can redistribute it and/or modify
2 | it under the terms of the GNU Affero General Public License version 3
3 | as published by the Free Software Foundation with the addition of the
4 | following permission added to Section 15 as permitted in Section 7(a):
5 | FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
6 | ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
7 | OF THIRD PARTY RIGHTS
8 |
9 | This program is distributed in the hope that it will be useful, but
10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 | or FITNESS FOR A PARTICULAR PURPOSE.
12 | See the GNU Affero General Public License for more details.
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program; if not, see http://www.gnu.org/licenses or write to
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 | Boston, MA, 02110-1301 USA, or download the license from the following URL:
17 | http://itextpdf.com/terms-of-use/
18 |
19 | The interactive user interfaces in modified source and object code versions
20 | of this program must display Appropriate Legal Notices, as required under
21 | Section 5 of the GNU Affero General Public License.
22 |
23 | In accordance with Section 7(b) of the GNU Affero General Public License,
24 | a covered work must retain the producer line in every PDF that is created
25 | or manipulated using iText.
26 |
27 | You can be released from the requirements of the license by purchasing
28 | a commercial license. Buying such a license is mandatory as soon as you
29 | develop commercial activities involving the iText software without
30 | disclosing the source code of your own applications.
31 | These activities include: offering paid services to customers as an ASP,
32 | serving PDFs on the fly in a web application, shipping iText with a closed
33 | source product.
34 |
35 | For more information, please contact iText Software Corp. at this
36 | address: sales@itextpdf.com
37 |
--------------------------------------------------------------------------------
/Ignore/itext7.7.1.8/[Content_Types].xml:
--------------------------------------------------------------------------------
1 |
2 |
");
43 | }
44 | #//Create an HTML tag with appropriate styles
45 | $this.result.AppendFormat("", $curFont, $curFontSize);
46 | }
47 | #//Append the current text
48 | $this.result.Append($renderInfo.GetText());
49 |
50 | #//Set currently used properties
51 | $this.lastBaseLine = curBaseline;
52 | $this.lastFontSize = curFontSize;
53 | $this.lastFont = curFont;
54 | }
55 | #>
--------------------------------------------------------------------------------
/Private/Class.TextWithFontExtractionStategy.ps1:
--------------------------------------------------------------------------------
1 | Enum TextRenderMode {
2 | FillText = 0
3 | StrokeText = 1
4 | FillThenStrokeText = 2
5 | Invisible = 3
6 | FillTextAndAddToPathForClipping = 4
7 | StrokeTextAndAddToPathForClipping = 5
8 | FillThenStrokeTextAndAddToPathForClipping = 6
9 | AddTextToPaddForClipping = 7
10 | }
11 | class TextWithFontExtractionStategy : iText.Kernel.Pdf.Canvas.Parser.Listener.ITextExtractionStrategy {
12 | #HTML buffer
13 | [System.Text.StringBuilder] $result = [System.Text.StringBuilder]::new()
14 |
15 | #Store last used properties
16 | [iText.Kernel.Geom.Vector] $lastBaseLine
17 | [string] $lastFont
18 | [single] $lastFontSize
19 |
20 | RenderText([iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo] $renderInfo) {
21 | [string] $curFont = $renderInfo.GetFont().PostscriptFontName;
22 | #//Check if faux bold is used
23 | if ($renderInfo.GetTextRenderMode() -eq [int][TextRenderMode]::FillThenStrokeText) {
24 | $curFont += "-Bold";
25 | }
26 |
27 | #//This code assumes that if the baseline changes then we're on a newline
28 | [iText.Kernel.Geom.Vector] $curBaseline = $renderInfo.GetBaseline().GetStartPoint();
29 | [iText.Kernel.Geom.Vector] $topRight = $renderInfo.GetAscentLine().GetEndPoint();
30 | [iText.Kernel.Geom.Rectangle] $rect = [iText.Kernel.Geom.Rectangle]::new($curBaseline, $curBaseline, $topRight, $topRight);
31 | [Single] $curFontSize = $rect.Height;
32 |
33 | #//See if something has changed, either the baseline, the font or the font size
34 | if (($null -eq $this.lastBaseLine) -or ($curBaseline -ne $this.lastBaseLine) -or ($curFontSize -ne $this.lastFontSize) -or ($curFont -ne $this.lastFont)) {
35 | #//if we've put down at least one span tag close it
36 | if ($null -ne $this.lastBaseLine) {
37 | $this.result.AppendLine("");
38 | }
39 | #//If the baseline has changed then insert a line break
40 | if (($null -ne $this.lastBaseLine) -and ($curBaseline -ne $this.lastBaseLine)) {
41 | $this.result.AppendLine("
");
42 | }
43 | #//Create an HTML tag with appropriate styles
44 | $this.result.AppendFormat("", $curFont, $curFontSize);
45 | }
46 | #//Append the current text
47 | $this.result.Append($renderInfo.GetText());
48 |
49 | #//Set currently used properties
50 | $this.lastBaseLine = $curBaseline;
51 | $this.lastFontSize = $curFontSize;
52 | $this.lastFont = $curFont;
53 | }
54 |
55 | [string] GetResultantText() {
56 | #//If we wrote anything then we'll always have a missing closing tag so close it here
57 | if ($this.result.Length -gt 0) {
58 | $this.result.Append("");
59 | }
60 | return $this.result.ToString();
61 | }
62 | [System.Collections.Generic.ICollection[iText.Kernel.Pdf.Canvas.Parser.EventType]] GetSupportedEvents() {
63 | return $null
64 | }
65 | [void] EventOccurred([iText.Kernel.Pdf.Canvas.Parser.Data.IEventData] $data, [iText.Kernel.Pdf.Canvas.Parser.EventType] $type) {
66 | return
67 | }
68 | }
--------------------------------------------------------------------------------
/Private/Class.Validations.ps1:
--------------------------------------------------------------------------------
1 | # Validation for Fonts
2 | $Script:PDFFont = {
3 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
4 | ([iText.IO.Font.Constants.StandardFonts] | Get-Member -Static -MemberType Property).Name | Where-Object { $_ -like "*$wordToComplete*" }
5 | }
6 | $Script:PDFFontValidation = {
7 | $Array = @(
8 | (& $Script:PDFFont)
9 | ''
10 | )
11 | $_ -in $Array
12 | }
13 |
14 | $Script:PDFTextAlignments = {
15 | ([iText.Layout.Properties.TextAlignment] | Get-Member -static -MemberType Property).Name
16 | }
17 | $Script:PDFTextAlignmentValidation = {
18 | $Array = @(
19 | (& $Script:PDFTextAlignments)
20 | ''
21 | )
22 | $_ -in $Array
23 | }
24 |
25 | $Script:PDFFontList = {
26 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
27 | @(
28 | ([iText.IO.Font.Constants.StandardFonts] | Get-Member -Static -MemberType Property).Name
29 | if ($Script:Fonts.Keys) { $Script:Fonts.Keys }
30 | ) | Where-Object { $_ -like "*$wordToComplete*" }
31 | }
32 | $Script:PDFFontValidationList = {
33 | $Array = @(
34 | (& $Script:PDFFont)
35 | $Script:Fonts.Keys
36 | ''
37 | )
38 | $_ -in $Array
39 | }
--------------------------------------------------------------------------------
/Private/Get-InternalPDFFont.ps1:
--------------------------------------------------------------------------------
1 | function Get-InternalPDFFont {
2 | [cmdletBinding()]
3 | param(
4 | [ValidateScript( { & $Script:PDFFontValidationList } )][string] $Font
5 | )
6 | if (-not $Script:Fonts[$Font]) {
7 | # If not defined font, we use contstant fonts
8 | $ConvertedFont = Get-PDFConstantFont -Font $Font
9 | $ApplyFont = [iText.Kernel.Font.PdfFontFactory]::CreateFont($ConvertedFont)
10 | } else {
11 | # if defined we use whatever we defined
12 | $ApplyFont = $Script:Fonts[$Font]
13 | }
14 | $ApplyFont
15 | }
16 |
17 | Register-ArgumentCompleter -CommandName Get-InternalPDFFont -ParameterName Font -ScriptBlock $Script:PDFFontList
--------------------------------------------------------------------------------
/Private/Get-PDFNamedPageSize.ps1:
--------------------------------------------------------------------------------
1 | function Get-PDFNamedPageSize {
2 | [CmdletBinding()]
3 | param(
4 | [int] $Height,
5 | [int] $Width
6 | )
7 |
8 | $PDFSizes = @{
9 | '33702384' = [PSCustomObject] @{ PageSize = 'A0'; Rotated = $false }
10 | '23843370' = [PSCustomObject] @{ PageSize = 'A0'; Rotated = $true }
11 | '23841684' = [PSCustomObject] @{ PageSize = 'A1'; Rotated = $false }
12 | '16842384' = [PSCustomObject] @{ PageSize = 'A1'; Rotated = $true }
13 | '10574' = [PSCustomObject] @{ PageSize = 'A10'; Rotated = $false }
14 | '74105' = [PSCustomObject] @{ PageSize = 'A10'; Rotated = $true }
15 | '16841190' = [PSCustomObject] @{ PageSize = 'A2'; Rotated = $false }
16 | '11901684' = [PSCustomObject] @{ PageSize = 'A2'; Rotated = $true }
17 | '1190842' = [PSCustomObject] @{ PageSize = 'A3'; Rotated = $false }
18 | '8421190' = [PSCustomObject] @{ PageSize = 'A3'; Rotated = $true }
19 | '842595' = [PSCustomObject] @{ PageSize = 'A4'; Rotated = $false }
20 | '595842' = [PSCustomObject] @{ PageSize = 'A4'; Rotated = $true }
21 | '595420' = [PSCustomObject] @{ PageSize = 'A5'; Rotated = $false }
22 | '420595' = [PSCustomObject] @{ PageSize = 'A5'; Rotated = $true }
23 | '420298' = [PSCustomObject] @{ PageSize = 'A6'; Rotated = $false }
24 | '298420' = [PSCustomObject] @{ PageSize = 'A6'; Rotated = $true }
25 | '298210' = [PSCustomObject] @{ PageSize = 'A7'; Rotated = $false }
26 | '210298' = [PSCustomObject] @{ PageSize = 'A7'; Rotated = $true }
27 | '210148' = [PSCustomObject] @{ PageSize = 'A8'; Rotated = $false }
28 | '148210' = [PSCustomObject] @{ PageSize = 'A8'; Rotated = $true }
29 | '547105' = [PSCustomObject] @{ PageSize = 'A9'; Rotated = $false }
30 | '105547' = [PSCustomObject] @{ PageSize = 'A9'; Rotated = $true }
31 | '40082834' = [PSCustomObject] @{ PageSize = 'B0'; Rotated = $false }
32 | '28344008' = [PSCustomObject] @{ PageSize = 'B0'; Rotated = $true }
33 | '28342004' = [PSCustomObject] @{ PageSize = 'B1'; Rotated = $false }
34 | '20042834' = [PSCustomObject] @{ PageSize = 'B1'; Rotated = $true }
35 | '12488' = [PSCustomObject] @{ PageSize = 'B10'; Rotated = $false }
36 | '88124' = [PSCustomObject] @{ PageSize = 'B10'; Rotated = $true }
37 | '20041417' = [PSCustomObject] @{ PageSize = 'B2'; Rotated = $false }
38 | '14172004' = [PSCustomObject] @{ PageSize = 'B2'; Rotated = $true }
39 | '14171000' = [PSCustomObject] @{ PageSize = 'B3'; Rotated = $false }
40 | '10001417' = [PSCustomObject] @{ PageSize = 'B3'; Rotated = $true }
41 | '1000708' = [PSCustomObject] @{ PageSize = 'B4'; Rotated = $false }
42 | '7081000' = [PSCustomObject] @{ PageSize = 'B4'; Rotated = $true }
43 | '708498' = [PSCustomObject] @{ PageSize = 'B5'; Rotated = $false }
44 | '498708' = [PSCustomObject] @{ PageSize = 'B5'; Rotated = $true }
45 | '498354' = [PSCustomObject] @{ PageSize = 'B6'; Rotated = $false }
46 | '354498' = [PSCustomObject] @{ PageSize = 'B6'; Rotated = $true }
47 | '354249' = [PSCustomObject] @{ PageSize = 'B7'; Rotated = $false }
48 | '249354' = [PSCustomObject] @{ PageSize = 'B7'; Rotated = $true }
49 | '249175' = [PSCustomObject] @{ PageSize = 'B8'; Rotated = $false }
50 | '175249' = [PSCustomObject] @{ PageSize = 'B8'; Rotated = $true }
51 | '175124' = [PSCustomObject] @{ PageSize = 'B9'; Rotated = $false }
52 | '124175' = [PSCustomObject] @{ PageSize = 'B9'; Rotated = $true }
53 | '756522' = [PSCustomObject] @{ PageSize = 'EXECUTIVE'; Rotated = $false }
54 | '522756' = [PSCustomObject] @{ PageSize = 'EXECUTIVE'; Rotated = $true }
55 | '7921224' = [PSCustomObject] @{ PageSize = 'LEDGER or TABLOID'; Rotated = $false }
56 | '1224792' = [PSCustomObject] @{ PageSize = 'LEDGER or TABLOID'; Rotated = $true }
57 | '1008612' = [PSCustomObject] @{ PageSize = 'LEGAL'; Rotated = $false }
58 | '6121008' = [PSCustomObject] @{ PageSize = 'LEGAL'; Rotated = $true }
59 | '792612' = [PSCustomObject] @{ PageSize = 'LETTER'; Rotated = $false }
60 | '612792' = [PSCustomObject] @{ PageSize = 'LETTER'; Rotated = $true }
61 | }
62 | $Size = $PDFSizes["$Height$Width"]
63 | if ($Size) {
64 | $Size
65 | } else {
66 | [PSCustomObject] @{ PageSize = 'Unknown'; Rotated = $null }
67 | }
68 | }
--------------------------------------------------------------------------------
/Private/Initialize-PDF.ps1:
--------------------------------------------------------------------------------
1 | function Initialize-PDF {
2 | [CmdletBinding()]
3 | param(
4 | [Array] $Elements
5 | )
6 | foreach ($Element in $Elements) {
7 | $Splat = $Element.Settings
8 | if ($Splat) {
9 | Remove-EmptyValue -Hashtable $Splat
10 | }
11 | if ($Element.Type -eq 'Page') {
12 | if (-not $Script:PDFStart.FirstPageUsed) {
13 | #$Area = New-PDFArea -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate -AreaType ([iText.Layout.Properties.AreaBreakType]::LAST_PAGE)
14 | #New-InternalPDFPage -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
15 |
16 | # This adds margings to first page if New-PDFOptions is used but no margins were defined on New-PDFPage
17 | if (-not $Splat.Margins.MarginBottom) {
18 | $Splat.Margins.MarginBottom = $Script:PDFStart.DocumentSettings.MarginBottom
19 | }
20 | if (-not $Splat.Margins.MarginTop) {
21 | $Splat.Margins.MarginTop = $Script:PDFStart.DocumentSettings.MarginTop
22 | }
23 | if (-not $Splat.Margins.MarginLeft) {
24 | $Splat.Margins.MarginLeft = $Script:PDFStart.DocumentSettings.MarginLeft
25 | }
26 | if (-not $Splat.Margins.MarginRight) {
27 | $Splat.Margins.MarginRight = $Script:PDFStart.DocumentSettings.MarginRight
28 | }
29 | New-InternalPDFPage -PageSize $Splat.PageSize -Rotate:$Splat.Rotate -MarginLeft $Splat.Margins.MarginLeft -MarginTop $Splat.Margins.MarginTop -MarginBottom $Splat.Margins.MarginBottom -MarginRight $Splat.Margins.MarginRight
30 | #Add-PDFDocumentContent -Object $Area
31 | $Script:PDFStart.FirstPageUsed = $true
32 | } else {
33 | # This fixes margins. Margins have to be added before new PageArea
34 | $SplatMargins = $Splat.Margins
35 | New-InternalPDFOptions @SplatMargins
36 |
37 | $Area = New-PDFArea -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
38 | Add-PDFDocumentContent -Object $Area
39 | }
40 | # New-InternalPDFPage -PageSize $Element.Settings.PageSize -Rotate:$Element.Settings.Rotate
41 | # New-InternalPDFOptions -Settings $Element.Settings
42 | if ($Element.Settings.PageContent) {
43 | Initialize-PDF -Elements $Element.Settings.PageContent
44 | }
45 | } elseif ($Element.Type -eq 'Text') {
46 | $Paragraph = New-InternalPDFText @Splat
47 | foreach ($P in $Paragraph) {
48 | Add-PDFDocumentContent -Object $P
49 | }
50 | } elseif ($Element.Type -eq 'List') {
51 | New-InternalPDFList -Settings $Element.Settings
52 | } elseif ($Element.Type -eq 'Paragraph') {
53 |
54 | } elseif ($Element.Type -eq 'Options') {
55 | $SplatMargins = $Splat.Margins
56 | New-InternalPDFOptions @SplatMargins
57 | } elseif ($Element.Type -eq 'Table') {
58 | $Table = New-InteralPDFTable @Splat
59 | #$null = $Script:Document.Add($Table)
60 | Add-PDFDocumentContent -Object $Table
61 | } elseif ($Element.Type -eq 'Image') {
62 | New-InternalPDFImage @Splat
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/Private/New-InternalPDF.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDF {
2 | [CmdletBinding()]
3 | param(
4 | [string] $FilePath,
5 | [string] $Version #,
6 | # [ValidateScript( { & $Script:PDFPageSizeValidation } )][string] $PageSize,
7 | # [switch] $Rotate
8 | )
9 |
10 | if ($Version) {
11 | $PDFVersion = Get-PDFConstantVersion -Version $Version
12 | $WriterProperties = [iText.Kernel.Pdf.WriterProperties]::new()
13 | $null = $WriterProperties.SetPdfVersion($PDFVersion)
14 | }
15 |
16 | try {
17 | if ($Version) {
18 | $Script:Writer = [iText.Kernel.Pdf.PdfWriter]::new($FilePath, $WriterProperties)
19 | } else {
20 | $Script:Writer = [iText.Kernel.Pdf.PdfWriter]::new($FilePath)
21 | }
22 | } catch {
23 | if ($_.Exception.Message -like '*The process cannot access the file*because it is being used by another process.*') {
24 | Write-Warning "New-InternalPDF - File $FilePath is in use. Terminating."
25 | return
26 | } else {
27 | Write-Warning "New-InternalPDF - Terminating error: $($_.Exception.Message)"
28 | return
29 | }
30 | }
31 |
32 | if ($Script:Writer) {
33 | $PDF = [iText.Kernel.Pdf.PdfDocument]::new($Script:Writer)
34 | } else {
35 | Write-Warning "New-InternalPDF - Terminating as writer doesn't exists."
36 | return
37 | }
38 | return $PDF
39 | }
40 |
41 |
42 |
43 | <#
44 | function New-InternalPDF {
45 | param(
46 |
47 | )
48 | if ($Script:Writer) {
49 | if ($Script:PDF) {
50 | #$Script:PDF.Close()
51 | }
52 | $Script:PDF = [iText.Kernel.Pdf.PdfDocument]::new($Script:Writer)
53 | } else {
54 | Write-Warning "New-InternalPDF - Terminating as writer doesn't exists."
55 | Exit
56 | }
57 | }
58 | #>
59 | Register-ArgumentCompleter -CommandName New-InternalPDF -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
60 | Register-ArgumentCompleter -CommandName New-InternalPDF -ParameterName Version -ScriptBlock $Script:PDFVersion
--------------------------------------------------------------------------------
/Private/New-InternalPDFImage.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDFImage {
2 | [CmdletBinding()]
3 | param(
4 | [string] $ImagePath,
5 | [int] $Width,
6 | [int] $Height,
7 | [object] $BackgroundColor,
8 | [double] $BackgroundColorOpacity
9 | )
10 |
11 | $ImageData = [iText.IO.Image.ImageDataFactory]::Create($ImagePath)
12 | $Image = [iText.Layout.Element.Image]::new($ImageData)
13 |
14 | if ($Width) {
15 | $null = $Image.SetWidth($Width)
16 | }
17 | if ($Height) {
18 | $null = $Image.SetHeight($Height)
19 |
20 | }
21 | if ($BackgroundColor) {
22 | <#
23 | iText.Layout.Element.Image SetBackgroundColor(iText.Kernel.Colors.Color backgroundColor)
24 | iText.Layout.Element.Image SetBackgroundColor(iText.Kernel.Colors.Color backgroundColor, float opacity)
25 | iText.Layout.Element.Image SetBackgroundColor(iText.Kernel.Colors.Color backgroundColor, float extraLeft, float extraTop, float extraRight, float extraBottom)
26 | iText.Layout.Element.Image SetBackgroundColor(iText.Kernel.Colors.Color backgroundColor, float opacity, float extraLeft, float extraTop, float extraRight, float extraBottom)
27 | #>
28 | $RGB = [iText.Kernel.Colors.DeviceRgb]::new($BackgroundColor.R, $BackgroundColor.G, $BackgroundColor.B)
29 | $null = $Image.SetBackgroundColor($RGB)
30 | if ($BackgroundColorOpacity) {
31 | $null = $Image.SetOpacity($BackgroundColorOpacity)
32 | }
33 | }
34 | $null = $Script:Document.Add($Image)
35 | }
--------------------------------------------------------------------------------
/Private/New-InternalPDFList.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDFList {
2 | [CmdletBinding()]
3 | param(
4 | [System.Collections.IDictionary] $Settings
5 | )
6 |
7 | $List = [iText.Layout.Element.List]::new()
8 | if ($null -ne $Settings.Indent) {
9 | $null = $List.SetSymbolIndent($Settings.Indent)
10 | }
11 | if ($Settings.Symbol) {
12 | if ($Settings.Symbol -eq 'hyphen') {
13 | # Default
14 | } elseif ($Settings.Symbol -eq 'bullet') {
15 | $Symbol = [regex]::Unescape("\u2022")
16 | $null = $List.SetListSymbol($Symbol)
17 | }
18 |
19 | }
20 | foreach ($ItemSettings in $Settings.Items) {
21 | $Paragraph = New-InternalPDFText @ItemSettings
22 | $ListItem = [iText.Layout.Element.ListItem]::new()
23 | $null = $ListItem.Add($Paragraph)
24 | $null = $List.Add($ListItem)
25 | }
26 | $null = $Script:Document.Add($List)
27 | }
--------------------------------------------------------------------------------
/Private/New-InternalPDFOptions.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDFOptions {
2 | [CmdletBinding()]
3 | param(
4 | [nullable[float]] $MarginLeft,
5 | [nullable[float]] $MarginRight,
6 | [nullable[float]] $MarginTop,
7 | [nullable[float]] $MarginBottom
8 | )
9 |
10 | if ($Script:Document) {
11 | if ($MarginLeft) {
12 | $Script:Document.SetLeftMargin($MarginLeft)
13 | }
14 | if ($MarginRight) {
15 | $Script:Document.SetRightMargin($MarginRight)
16 | }
17 | if ($MarginTop) {
18 | $Script:Document.SetTopMargin($MarginTop)
19 | }
20 | if ($MarginBottom) {
21 | $Script:Document.SetBottomMargin($MarginBottom)
22 | }
23 | } else {
24 | # If Document doesn't exists it means we're using New-PDFOptions before New-PDFPage
25 | # We update DocumentSettings and use it just in case New-PDFPage doesn't have those values used.
26 | # Workaround, ugly but don't see a better way
27 | $Script:PDFStart['DocumentSettings']['MarginTop'] = $MarginTop
28 | $Script:PDFStart['DocumentSettings']['MarginBottom'] = $MarginBottom
29 | $Script:PDFStart['DocumentSettings']['MarginLeft'] = $MarginLeft
30 | $Script:PDFStart['DocumentSettings']['MarginRight'] = $MarginRight
31 | }
32 |
33 | #if ($Settings.PageSize) {
34 | # $Script:Document.GetPdfDocument().SetDefaultPageSize([iText.Kernel.Geom.PageSize]::($Settings.PageSize))
35 | # }
36 | }
--------------------------------------------------------------------------------
/Private/New-InternalPDFPage.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDFPage {
2 | [CmdletBinding()]
3 | param(
4 | [string] $PageSize,
5 | [switch] $Rotate,
6 | [nullable[float]] $MarginLeft,
7 | [nullable[float]] $MarginRight,
8 | [nullable[float]] $MarginTop,
9 | [nullable[float]] $MarginBottom
10 | )
11 |
12 | if ($PageSize -or $Rotate) {
13 | if ($PageSize) {
14 | $Page = [iText.Kernel.Geom.PageSize]::($PageSize)
15 | } else {
16 | $Page = [iText.Kernel.Geom.PageSize]::Default
17 | }
18 | if ($Rotate) {
19 | $Page = $Page.Rotate()
20 | }
21 | }
22 | if ($Page) {
23 | $null = $Script:PDF.AddNewPage($Page)
24 | } else {
25 | $null = $Script:PDF.AddNewPage()
26 | }
27 | $Script:Document = [iText.Layout.Document]::new($Script:PDF)
28 |
29 | if ($Script:Document) {
30 | if ($MarginLeft) {
31 | $Script:Document.SetLeftMargin($MarginLeft)
32 | }
33 | if ($MarginRight) {
34 | $Script:Document.SetRightMargin($MarginRight)
35 | }
36 | if ($MarginTop) {
37 | $Script:Document.SetTopMargin($MarginTop)
38 | }
39 | if ($MarginBottom) {
40 | $Script:Document.SetBottomMargin($MarginBottom)
41 | }
42 | }
43 | }
44 |
45 | Register-ArgumentCompleter -CommandName New-InternalPDFPage -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
--------------------------------------------------------------------------------
/Private/New-InternalPDFTable.ps1:
--------------------------------------------------------------------------------
1 | function New-InteralPDFTable {
2 | [CmdletBinding()]
3 | param(
4 | [Array] $DataTable
5 | )
6 |
7 | if ($DataTable[0] -is [System.Collections.IDictionary]) {
8 | [Array] $ColumnNames = 'Name', 'Value' # $DataTable[0].Keys
9 | [Array] $TemporaryTable = foreach ($_ in $DataTable) {
10 | $_.GetEnumerator() | Select-Object Name, Value
11 | }
12 | } else {
13 | [Array] $ColumnNames = $DataTable[0].PSObject.Properties.Name
14 | [Array] $TemporaryTable = $DataTable
15 | }
16 |
17 | [iText.layout.element.Table] $Table = [iText.Layout.Element.Table]::new($ColumnNames.Count)
18 | $Table = $Table.UseAllAvailableWidth()
19 |
20 | foreach ($Column in $ColumnNames) {
21 | $Splat = @{
22 | Text = $Column
23 | #Font = $Font
24 | #FontFamily = $FontFamily
25 | #FontColor = $FontColor
26 | #FontBold = $FontBold
27 | }
28 | $Paragraph = New-InternalPDFText @Splat
29 | #$Paragraph = New-PDFText -Text $Column
30 | [iText.Layout.Element.Cell] $Cell = [iText.Layout.Element.Cell]::new().Add($Paragraph)
31 | $null = $Table.AddCell($Cell)
32 | }
33 | foreach ($_ in $TemporaryTable) {
34 | foreach ($Column in $ColumnNames) {
35 | $Splat = @{
36 | Text = $_.$Column
37 | #Font = $Font
38 | #FontFamily = $FontFamily
39 | #FontColor = $FontColor
40 | #FontBold = $FontBold
41 | }
42 | $Paragraph = New-InternalPDFText @Splat
43 | #$Paragraph = New-PDFText -Text $_.$Column
44 | [iText.Layout.Element.Cell] $Cell = [iText.Layout.Element.Cell]::new().Add($Paragraph)
45 | $null = $Table.AddCell($Cell)
46 | }
47 | }
48 | $Table
49 | }
--------------------------------------------------------------------------------
/Private/New-InternalPDFText.ps1:
--------------------------------------------------------------------------------
1 | function New-InternalPDFText {
2 | [CmdletBinding()]
3 | param(
4 | [string[]] $Text,
5 | [ValidateScript( { & $Script:PDFFontValidationList } )][string[]] $Font,
6 | #[string[]] $FontFamily,
7 | [ValidateScript( { & $Script:PDFColorValidation } )][string[]] $FontColor,
8 | [nullable[bool][]] $FontBold,
9 | [int] $FontSize,
10 | [string] $TextAlignment,
11 | [nullable[float]] $MarginTop,
12 | [nullable[float]] $MarginBottom,
13 | [nullable[float]] $MarginLeft,
14 | [nullable[float]] $MarginRight
15 | )
16 |
17 | $Paragraph = [iText.Layout.Element.Paragraph]::New()
18 |
19 | if ($FontBold) {
20 | [Array] $FontBold = $FontBold
21 | $DefaultBold = $FontBold[0]
22 | }
23 | if ($FontColor) {
24 | [Array] $FontColor = $FontColor
25 | $DefaultColor = $FontColor[0]
26 | }
27 | if ($Font) {
28 | [Array] $Font = $Font
29 | $DefaultFont = $Font[0]
30 | }
31 |
32 | for ($i = 0; $i -lt $Text.Count; $i++) {
33 | [iText.Layout.Element.Text] $PDFText = $Text[$i]
34 |
35 | if ($FontBold) {
36 | if ($null -ne $FontBold[$i]) {
37 | if ($FontBold[$i]) {
38 | $PDFText = $PDFText.SetBold()
39 | }
40 | } else {
41 | if ($DefaultBold) {
42 | $PDFText = $PDFText.SetBold()
43 | }
44 | }
45 | }
46 | if ($FontColor) {
47 | if ($null -ne $FontColor[$i]) {
48 | if ($FontColor[$i]) {
49 | $ConvertedColor = Get-PDFConstantColor -Color $FontColor[$i]
50 | $PDFText = $PDFText.SetFontColor($ConvertedColor)
51 | }
52 | } else {
53 | if ($DefaultColor) {
54 | $ConvertedColor = Get-PDFConstantColor -Color $DefaultColor
55 | $PDFText = $PDFText.SetFontColor($ConvertedColor)
56 | }
57 | }
58 | }
59 | if ($FontSize) {
60 | $PDFText = $PDFText.SetFontSize($FontSize)
61 | }
62 | if ($Font) {
63 | if ($null -ne $Font[$i]) {
64 | if ($Font[$i]) {
65 | #$ConvertedFont = Get-PDFConstantFont -Font $Font[$i]
66 | #$ApplyFont = [iText.Kernel.Font.PdfFontFactory]::CreateFont($ConvertedFont, [iText.IO.Font.PdfEncodings]::IDENTITY_H, $false)
67 | #$ApplyFont = [iText.Kernel.Font.PdfFontFactory]::CreateFont('TIMES_ROMAN', [iText.IO.Font.PdfEncodings]::IDENTITY_H, $false)
68 | #$PDFText = $PDFText.SetFont($ApplyFont)
69 | $ApplyFont = Get-InternalPDFFont -Font $Font[$i]
70 | $PDFText = $PDFText.SetFont($ApplyFont)
71 | }
72 | } else {
73 | if ($DefaultColor) {
74 | # $ConvertedFont = Get-PDFConstantFont -Font $DefaultFont
75 | # $ApplyFont = [iText.Kernel.Font.PdfFontFactory]::CreateFont($ConvertedFont, [iText.IO.Font.PdfEncodings]::IDENTITY_H, $false)
76 | # $PDFText = $PDFText.SetFont($ApplyFont)
77 | $ApplyFont = Get-InternalPDFFont -Font $DefaultFont
78 | $PDFText = $PDFText.SetFont($ApplyFont)
79 | }
80 | }
81 | } else {
82 | if ($Script:DefaultFont) {
83 | $PDFText = $PDFText.SetFont($Script:DefaultFont)
84 | }
85 | }
86 | $null = $Paragraph.Add($PDFText)
87 | }
88 | if ($TextAlignment) {
89 | $ConvertedTextAlignment = Get-PDFConstantTextAlignment -TextAlignment $TextAlignment
90 | $null = $Paragraph.SetTextAlignment($ConvertedTextAlignment)
91 | }
92 | $null = $Paragraph.SetMarginTop($MarginTop)
93 | $null = $Paragraph.SetMarginBottom($MarginBottom)
94 | if ($MarginLeft) {
95 | $null = $Paragraph.SetMarginLeft($MarginLeft)
96 | }
97 | if ($MarginRight) {
98 | $null = $Paragraph.SetMarginRight($MarginRight)
99 | }
100 | $Paragraph
101 | }
--------------------------------------------------------------------------------
/Private/ScriptBlock.RGBColors.ps1:
--------------------------------------------------------------------------------
1 | $Script:ScriptBlockColors = {
2 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
3 | $Script:RGBColors.Keys | Where-Object { $_ -like "*$wordToComplete*" }
4 | }
--------------------------------------------------------------------------------
/Public/Close-PDF.ps1:
--------------------------------------------------------------------------------
1 | function Close-PDF {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Kernel.Pdf.PdfDocument] $Document
5 | )
6 | if ($Document) {
7 | $Document.Close()
8 | }
9 | }
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantAction.ps1:
--------------------------------------------------------------------------------
1 | # Validation for Actions
2 | $Script:PDFAction = {
3 | ([iText.Kernel.Pdf.Action.PdfAction] | Get-Member -static -MemberType Property).Name
4 | }
5 | $Script:PDFActionValidation = {
6 | $Array = @(
7 | (& $Script:PDFAction)
8 | ''
9 | )
10 | $_ -in $Array
11 | }
12 |
13 | function Get-PDFConstantAction {
14 | [CmdletBinding()]
15 | param(
16 | [ValidateScript( { & $Script:PDFActionValidation } )][string] $Action
17 | )
18 | return [iText.Kernel.Pdf.Action.PdfAction]::$Action
19 | }
20 |
21 | Register-ArgumentCompleter -CommandName Get-PDFConstantAction -ParameterName Action -ScriptBlock $Script:PDFAction
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantColor.ps1:
--------------------------------------------------------------------------------
1 | # Validation for Colors
2 | $Script:PDFColor = {
3 | ([iText.Kernel.Colors.ColorConstants] | Get-Member -static -MemberType Property).Name
4 | }
5 | $Script:PDFColorValidation = {
6 | $Array = @(
7 | (& $Script:PDFColor)
8 | ''
9 | )
10 | $_ -in $Array
11 | }
12 |
13 | function Get-PDFConstantColor {
14 | [CmdletBinding()]
15 | param(
16 | [ValidateScript( { & $Script:PDFColorValidation } )][string] $Color
17 | )
18 | return [iText.Kernel.Colors.ColorConstants]::$Color
19 | }
20 |
21 | Register-ArgumentCompleter -CommandName Get-PDFConstantColor -ParameterName Color -ScriptBlock $Script:PDFColor
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantFont.ps1:
--------------------------------------------------------------------------------
1 | function Get-PDFConstantFont {
2 | [CmdletBinding()]
3 | param(
4 | [ValidateScript( { & $Script:PDFFontValidation } )][string] $Font
5 | )
6 | return [iText.IO.Font.Constants.StandardFonts]::$Font
7 | }
8 |
9 | Register-ArgumentCompleter -CommandName Get-PDFConstantFont -ParameterName Font -ScriptBlock $Script:PDFFont
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantPageSize.ps1:
--------------------------------------------------------------------------------
1 | # Validation for PageSize
2 | $Script:PDFPageSize = {
3 | ([iText.Kernel.Geom.PageSize] | Get-Member -static -MemberType Property).Name
4 | }
5 | $Script:PDFPageSizeValidation = {
6 | # Empty element is added to allow no parameter value
7 | $Array = @(
8 | (& $Script:PDFPageSize)
9 | ''
10 | )
11 | $_ -in $Array
12 | }
13 |
14 | function Get-PDFConstantPageSize {
15 | [CmdletBinding()]
16 | param(
17 | [ValidateScript( { & $Script:PDFPageSizeValidation } )][string] $PageSize,
18 | [switch] $All
19 | )
20 | if (-not $All) {
21 | return [iText.Kernel.Geom.PageSize]::$PageSize
22 | } else {
23 | return & $Script:PDFPageSize
24 | }
25 | }
26 |
27 | Register-ArgumentCompleter -CommandName Get-PDFConstantPageSize -ParameterName Version -ScriptBlock $Script:PDFPageSize
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantTextAlignment.ps1:
--------------------------------------------------------------------------------
1 | # Validation for Colors
2 | $Script:PDFTextAlignments = {
3 | ([iText.Layout.Properties.TextAlignment] | Get-Member -static -MemberType Property).Name
4 | }
5 |
6 | function Get-PDFConstantTextAlignment {
7 | [CmdletBinding()]
8 | param(
9 | [ValidateScript( { & $Script:PDFTextAlignmentValidation } )][string] $TextAlignment
10 | )
11 | return [iText.Layout.Properties.TextAlignment]::$TextAlignment
12 | }
13 |
14 | Register-ArgumentCompleter -CommandName Get-PDFConstantTextAlignment -ParameterName TextAlignment -ScriptBlock $Script:PDFTextAlignments
--------------------------------------------------------------------------------
/Public/Constants/Get-PDFConstantVersion.ps1:
--------------------------------------------------------------------------------
1 | # Validation for Fonts
2 | $Script:PDFVersion = {
3 | ([iText.Kernel.Pdf.PdfVersion] | Get-Member -static -MemberType Property).Name
4 | }
5 | $Script:PDFVersionValidation = {
6 | $Array = @(
7 | (& $Script:PDFVersion)
8 | ''
9 | )
10 | $_ -in $Array
11 | }
12 |
13 | function Get-PDFConstantVersion {
14 | [CmdletBinding()]
15 | param(
16 | [ValidateScript( { & $Script:PDFVersionValidation } )][string] $Version
17 | )
18 | return [iText.Kernel.Pdf.PdfVersion]::$Version
19 | }
20 |
21 | Register-ArgumentCompleter -CommandName Get-PDFConstantVersion -ParameterName Version -ScriptBlock $Script:PDFVersion
--------------------------------------------------------------------------------
/Public/Get-PDF.ps1:
--------------------------------------------------------------------------------
1 | function Get-PDF {
2 | <#
3 | .SYNOPSIS
4 | Gets PDF file and returns it as an PDF object
5 |
6 | .DESCRIPTION
7 | Gets PDF file and returns it as an PDF object
8 |
9 | .PARAMETER FilePath
10 | Path to the PDF file to be processed
11 |
12 | .PARAMETER IgnoreProtection
13 | The switch will allow reading of PDF files that are "owner password" encrypted for protection/security (e.g. preventing copying of text, printing etc).
14 | The switch doesn't allow reading of PDF files that are "user password" encrypted (i.e. you cannot open them without the password)
15 |
16 | .EXAMPLE
17 | $Document = Get-PDF -FilePath "C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSWritePDF\Example\Example01.HelloWorld\Example01_WithSectionsMix.pdf"
18 | $Details = Get-PDFDetails -Document $Document
19 | $Details | Format-List
20 | $Details.Pages | Format-Table
21 |
22 | Close-PDF -Document $Document
23 |
24 | .NOTES
25 | General notes
26 | #>
27 | [CmdletBinding()]
28 | param(
29 | [string] $FilePath,
30 | [switch] $IgnoreProtection
31 | )
32 |
33 | if ($FilePath -and (Test-Path -LiteralPath $FilePath)) {
34 | $ResolvedPath = Convert-Path -LiteralPath $FilePath
35 |
36 | try {
37 | $PDFFile = [iText.Kernel.Pdf.PdfReader]::new($ResolvedPath)
38 | if ($IgnoreProtection) {
39 | $null = $PDFFile.SetUnethicalReading($true)
40 | }
41 | $Document = [iText.Kernel.Pdf.PdfDocument]::new($PDFFile)
42 | } catch {
43 | $ErrorMessage = $_.Exception.Message
44 | Write-Warning "Get-PDF - Processing document $FilePath failed with error: $ErrorMessage"
45 | }
46 | $Document
47 |
48 | }
49 | }
--------------------------------------------------------------------------------
/Public/Get-PDFDetails.ps1:
--------------------------------------------------------------------------------
1 | function Get-PDFDetails {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Kernel.Pdf.PdfDocument] $Document
5 | )
6 | if ($Document) {
7 | [iText.Layout.Document] $LayoutDocument = [iText.Layout.Document]::new($Document)
8 |
9 | $Output = [ordered] @{
10 | Author = $Document.GetDocumentInfo().GetAuthor()
11 | Creator = $Document.GetDocumentInfo().GetCreator()
12 | HashCode = $Document.GetDocumentInfo().GetHashCode()
13 | Keywords = $Document.GetDocumentInfo().GetKeywords()
14 | Producer = $Document.GetDocumentInfo().GetProducer()
15 | Subject = $Document.GetDocumentInfo().GetSubject()
16 | Title = $Document.GetDocumentInfo().GetTitle()
17 | Trapped = $Document.GetDocumentInfo().GetTrapped()
18 | Version = $Document.GetPdfVersion()
19 | PagesNumber = $Document.GetNumberOfPages()
20 | MarginLeft = $LayoutDocument.GetLeftMargin()
21 | MarginRight = $LayoutDocument.GetRightMargin()
22 | MarginBottom = $LayoutDocument.GetBottomMargin()
23 | MarginTop = $LayoutDocument.GetTopMargin()
24 | Pages = [ordered] @{ }
25 | }
26 | for ($a = 1; $a -le $Output.PagesNumber; $a++) {
27 | $Height = $Document.GetPage($a).GetPageSizeWithRotation().GetHeight()
28 | $Width = $Document.GetPage($a).GetPageSizeWithRotation().GetWidth()
29 | $NamedSize = Get-PDFNamedPageSize -Height $Height -Width $Width
30 | $Output['Pages']["$a"] = [PSCustomObject] @{
31 | Height = $Height
32 | Width = $Width
33 | Rotation = $Document.GetPage($a).GetRotation()
34 | Size = $NamedSize.PageSize
35 | Rotated = $NamedSize.Rotated
36 | }
37 | }
38 | [PSCustomObject] $Output
39 | }
40 | }
--------------------------------------------------------------------------------
/Public/Get-PDFFormField.ps1:
--------------------------------------------------------------------------------
1 | function Get-PDFFormField {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Kernel.Pdf.PdfDocument]$PDF
5 | )
6 | try {
7 | $PDFAcroForm = [iText.Forms.PdfAcroForm]::getAcroForm($PDF, $true)
8 | $PDFAcroForm.GetFormFields()
9 | } catch {
10 | if ($PSBoundParameters.ErrorAction -eq 'Stop') {
11 | Write-Error $_
12 | return
13 | } else {
14 | Write-Warning -Message "Get-PDFFormField - There was an error reading forms or no form exists. Exception: $($_.Error.Exception)"
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Public/New-PDF.ps1:
--------------------------------------------------------------------------------
1 | function New-PDF {
2 | [CmdletBinding()]
3 | param(
4 | [scriptblock] $PDFContent,
5 | [Parameter(Mandatory)][string] $FilePath,
6 | [string] $Version,
7 |
8 | [nullable[float]] $MarginLeft,
9 | [nullable[float]] $MarginRight,
10 | [nullable[float]] $MarginTop,
11 | [nullable[float]] $MarginBottom,
12 | [ValidateScript( { & $Script:PDFPageSizeValidation } )][string] $PageSize,
13 | [switch] $Rotate,
14 |
15 | [alias('Open')][switch] $Show
16 | )
17 | # The types needs filling in for the workaround below. DONT FORGET!
18 | $Script:Types = 'Text', 'List', 'Paragraph', 'Table', 'Image'
19 | $Script:PDFStart = @{
20 | Start = $true
21 | FilePath = $FilePath
22 | DocumentSettings = @{
23 | MarginTop = $MarginTop
24 | MarginBottom = $MarginBottom
25 | MarginLeft = $MarginLeft
26 | MarginRight = $MarginRight
27 | PageSize = $PageSize
28 | Rotate = $Rotate.IsPresent
29 | }
30 | FirstPageFound = $false
31 | FirstPageUsed = $false
32 | UsedTypes = [System.Collections.Generic.List[string]]::new()
33 | }
34 | if ($PDFContent) {
35 | [Array] $Elements = @(
36 | [Array] $Content = & $PDFContent
37 | # This is workaround to support multiple scenarios:
38 | # New-PDF { New-PDFPage, New-PDFPage }
39 | # New-PDF { }
40 | # New-PDF { New-PDFText, New-PDFPage }
41 | # This is there to make sure we allow for New-PDF to allow control for -Rotate/PageSize to either whole document or to text/tables
42 | # and other types until New-PDFPage is given
43 | # It's ugly but seems to wrok
44 | foreach ($_ in $Content) {
45 | if ($_.Type -in $Script:Types) {
46 | $Script:PDFStart.UsedTypes.Add($_.Type)
47 | } elseif ($_.Type -eq 'Page') {
48 | if ($Script:PDFStart.UsedTypes.Count -ne 0) {
49 | New-PDFPage -PageSize $PageSize -Rotate:$Rotate -MarginLeft $MarginLeft -MarginTop $MarginTop -MarginBottom $MarginBottom -MarginRight $MarginRight
50 | $Script:PDFStart.FirstPageFound = $true
51 | }
52 | break
53 | }
54 | }
55 | if (-not $Script:PDFStart.FirstPageFound -and $Script:PDFStart.UsedTypes.Count -ne 0) {
56 | New-PDFPage -PageSize $PageSize -Rotate:$Rotate -MarginLeft $MarginLeft -MarginTop $MarginTop -MarginBottom $MarginBottom -MarginRight $MarginRight
57 | $Script:PDFStart.FirstPageFound = $true
58 | }
59 | $Content
60 | )
61 | if ($Elements) {
62 | $Script:PDF = New-InternalPDF -FilePath $FilePath -Version $Version #-PageSize $PageSize -Rotate:$Rotate
63 | if (-not $Script:PDF) {
64 | return
65 | }
66 | } else {
67 | Write-Warning "New-PDF - No content was provided. Terminating."
68 | return
69 | }
70 | } else {
71 | $Script:PDFStart['Start'] = $false
72 | # if there's no scriptblock that means we're using standard way of working with PDF
73 | $Script:PDF = New-InternalPDF -FilePath $FilePath -Version $Version #-PageSize $PageSize -Rotate:$Rotate
74 | return $Script:PDF
75 | }
76 |
77 | $Script:PDFStart['Start'] = $true
78 | #[iText.Layout.Document] $Script:Document = New-PDFDocument -PDF $Script:PDF
79 | #New-InternalPDFOptions -MarginLeft $MarginLeft -MarginRight $MarginRight -MarginTop $MarginTop -MarginBottom $MarginBottom
80 |
81 | Initialize-PDF -Elements $Elements
82 | if ($Script:Document) {
83 | $Script:Document.Close();
84 | }
85 | if ($Show) {
86 | if (Test-Path -LiteralPath $FilePath) {
87 | Invoke-Item -LiteralPath $FilePath
88 | }
89 | }
90 | $Script:PDFStart = $null
91 | #$Script:PDFStart['Start'] = $false
92 | }
93 |
94 | Register-ArgumentCompleter -CommandName New-PDF -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
95 | Register-ArgumentCompleter -CommandName New-PDF -ParameterName Version -ScriptBlock $Script:PDFVersion
--------------------------------------------------------------------------------
/Public/New-PDFArea.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFArea {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Layout.Properties.AreaBreakType] $AreaType = [iText.Layout.Properties.AreaBreakType]::NEXT_AREA,
5 | [string] $PageSize,
6 | [switch] $Rotate
7 | )
8 | # https://api.itextpdf.com/iText7/dotnet/7.1.8/classi_text_1_1_kernel_1_1_geom_1_1_page_size.html
9 | $AreaBreak = [iText.Layout.Element.AreaBreak]::new($AreaType)
10 | if ($PageSize) {
11 | $Page = [iText.Kernel.Geom.PageSize]::($PageSize)
12 | } else {
13 | $Page = [iText.Kernel.Geom.PageSize]::Default
14 | }
15 | if ($Rotate) {
16 | $Page = $Page.Rotate()
17 | }
18 | $AreaBreak.SetPageSize($Page)
19 | return $AreaBreak
20 | }
21 |
22 | Register-ArgumentCompleter -CommandName New-PDFArea -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
23 |
24 | <#
25 | TypeName: iText.Layout.Element.AreaBreak
26 |
27 | Name MemberType Definition
28 | ---- ---------- ----------
29 | AddStyle Method iText.Layout.Element.AreaBreak AddStyle(iText.Layout.Style style)
30 | CreateRendererSubTree Method iText.Layout.Renderer.IRenderer CreateRendererSubTree(), iText.Layout.Renderer.IRenderer IElement.CreateRendererSubTree()
31 | DeleteOwnProperty Method void DeleteOwnProperty(int property), void IPropertyContainer.DeleteOwnProperty(int property)
32 | Equals Method bool Equals(System.Object obj)
33 | GetAreaType Method System.Nullable[iText.Layout.Properties.AreaBreakType] GetAreaType()
34 | GetChildren Method System.Collections.Generic.IList[iText.Layout.Element.IElement] GetChildren()
35 | GetDefaultProperty Method T1 GetDefaultProperty[T1](int property), T1 IPropertyContainer.GetDefaultProperty[T1](int property)
36 | GetHashCode Method int GetHashCode()
37 | GetOwnProperty Method T1 GetOwnProperty[T1](int property), T1 IPropertyContainer.GetOwnProperty[T1](int property)
38 | GetPageSize Method iText.Kernel.Geom.PageSize GetPageSize()
39 | GetProperty Method T1 GetProperty[T1](int property), T1 IPropertyContainer.GetProperty[T1](int property)
40 | GetRenderer Method iText.Layout.Renderer.IRenderer GetRenderer(), iText.Layout.Renderer.IRenderer IElement.GetRenderer()
41 | GetSplitCharacters Method iText.Layout.Splitting.ISplitCharacters GetSplitCharacters()
42 | GetStrokeColor Method iText.Kernel.Colors.Color GetStrokeColor()
43 | GetStrokeWidth Method System.Nullable[float] GetStrokeWidth()
44 | GetTextRenderingMode Method System.Nullable[int] GetTextRenderingMode()
45 | GetType Method type GetType()
46 | HasOwnProperty Method bool HasOwnProperty(int property), bool IPropertyContainer.HasOwnProperty(int property)
47 | HasProperty Method bool HasProperty(int property), bool IPropertyContainer.HasProperty(int property)
48 | IsEmpty Method bool IsEmpty()
49 | SetAction Method iText.Layout.Element.AreaBreak SetAction(iText.Kernel.Pdf.Action.PdfAction action)
50 | SetBackgroundColor Method iText.Layout.Element.AreaBreak SetBackgroundColor(iText.Kernel.Colors.Color backgroundColor), iText.Layout.Element.AreaBreak SetBackgroun...
51 | SetBaseDirection Method iText.Layout.Element.AreaBreak SetBaseDirection(System.Nullable[iText.Layout.Properties.BaseDirection] baseDirection)
52 | SetBold Method iText.Layout.Element.AreaBreak SetBold()
53 | SetBorder Method iText.Layout.Element.AreaBreak SetBorder(iText.Layout.Borders.Border border)
54 | SetBorderBottom Method iText.Layout.Element.AreaBreak SetBorderBottom(iText.Layout.Borders.Border border)
55 | SetBorderBottomLeftRadius Method iText.Layout.Element.AreaBreak SetBorderBottomLeftRadius(iText.Layout.Properties.BorderRadius borderRadius)
56 | SetBorderBottomRightRadius Method iText.Layout.Element.AreaBreak SetBorderBottomRightRadius(iText.Layout.Properties.BorderRadius borderRadius)
57 | SetBorderLeft Method iText.Layout.Element.AreaBreak SetBorderLeft(iText.Layout.Borders.Border border)
58 | SetBorderRadius Method iText.Layout.Element.AreaBreak SetBorderRadius(iText.Layout.Properties.BorderRadius borderRadius)
59 | SetBorderRight Method iText.Layout.Element.AreaBreak SetBorderRight(iText.Layout.Borders.Border border)
60 | SetBorderTop Method iText.Layout.Element.AreaBreak SetBorderTop(iText.Layout.Borders.Border border)
61 | SetBorderTopLeftRadius Method iText.Layout.Element.AreaBreak SetBorderTopLeftRadius(iText.Layout.Properties.BorderRadius borderRadius)
62 | SetBorderTopRightRadius Method iText.Layout.Element.AreaBreak SetBorderTopRightRadius(iText.Layout.Properties.BorderRadius borderRadius)
63 | SetCharacterSpacing Method iText.Layout.Element.AreaBreak SetCharacterSpacing(float charSpacing)
64 | SetDestination Method iText.Layout.Element.AreaBreak SetDestination(string destination)
65 | SetFixedPosition Method iText.Layout.Element.AreaBreak SetFixedPosition(float left, float bottom, float width), iText.Layout.Element.AreaBreak SetFixedPosition(f...
66 | SetFont Method iText.Layout.Element.AreaBreak SetFont(iText.Kernel.Font.PdfFont font), iText.Layout.Element.AreaBreak SetFont(string font)
67 | SetFontColor Method iText.Layout.Element.AreaBreak SetFontColor(iText.Kernel.Colors.Color fontColor), iText.Layout.Element.AreaBreak SetFontColor(iText.Kerne...
68 | SetFontFamily Method iText.Layout.Element.AreaBreak SetFontFamily(Params string[] fontFamilyNames), iText.Layout.Element.AreaBreak SetFontFamily(System.Collec...
69 | SetFontKerning Method iText.Layout.Element.AreaBreak SetFontKerning(iText.Layout.Properties.FontKerning fontKerning)
70 | SetFontScript Method iText.Layout.Element.AreaBreak SetFontScript(System.Nullable[iText.IO.Util.UnicodeScript] script)
71 | SetFontSize Method iText.Layout.Element.AreaBreak SetFontSize(float fontSize)
72 | SetHorizontalAlignment Method iText.Layout.Element.AreaBreak SetHorizontalAlignment(System.Nullable[iText.Layout.Properties.HorizontalAlignment] horizontalAlignment)
73 | SetHyphenation Method iText.Layout.Element.AreaBreak SetHyphenation(iText.Layout.Hyphenation.HyphenationConfig hyphenationConfig)
74 | SetItalic Method iText.Layout.Element.AreaBreak SetItalic()
75 | SetLineThrough Method iText.Layout.Element.AreaBreak SetLineThrough()
76 | SetNextRenderer Method void SetNextRenderer(iText.Layout.Renderer.IRenderer renderer), void IElement.SetNextRenderer(iText.Layout.Renderer.IRenderer renderer)
77 | SetOpacity Method iText.Layout.Element.AreaBreak SetOpacity(System.Nullable[float] opacity)
78 | SetPageNumber Method iText.Layout.Element.AreaBreak SetPageNumber(int pageNumber)
79 | SetPageSize Method void SetPageSize(iText.Kernel.Geom.PageSize pageSize)
80 | SetProperty Method void SetProperty(int property, System.Object value), void IPropertyContainer.SetProperty(int property, System.Object value)
81 | SetRelativePosition Method iText.Layout.Element.AreaBreak SetRelativePosition(float left, float top, float right, float bottom)
82 | SetSplitCharacters Method iText.Layout.Element.AreaBreak SetSplitCharacters(iText.Layout.Splitting.ISplitCharacters splitCharacters)
83 | SetStrokeColor Method iText.Layout.Element.AreaBreak SetStrokeColor(iText.Kernel.Colors.Color strokeColor)
84 | SetStrokeWidth Method iText.Layout.Element.AreaBreak SetStrokeWidth(float strokeWidth)
85 | SetTextAlignment Method iText.Layout.Element.AreaBreak SetTextAlignment(System.Nullable[iText.Layout.Properties.TextAlignment] alignment)
86 | SetTextRenderingMode Method iText.Layout.Element.AreaBreak SetTextRenderingMode(int textRenderingMode)
87 | SetUnderline Method iText.Layout.Element.AreaBreak SetUnderline(), iText.Layout.Element.AreaBreak SetUnderline(float thickness, float yPosition), iText.Layou...
88 | SetWordSpacing Method iText.Layout.Element.AreaBreak SetWordSpacing(float wordSpacing)
89 | ToString Method string ToString()
90 | #>
--------------------------------------------------------------------------------
/Public/New-PDFDocument.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFDocument {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Kernel.Pdf.PdfDocument] $PDF
5 | )
6 | [iText.Layout.Document] $Document = [iText.Layout.Document]::new($PDF)
7 | return $Document
8 | }
--------------------------------------------------------------------------------
/Public/New-PDFImage.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFImage {
2 | [CmdletBinding()]
3 | param(
4 | [string] $ImagePath,
5 | [int] $Width,
6 | [int] $Height,
7 | [string] $BackgroundColor,
8 | [double] $BackgroundColorOpacity
9 | )
10 |
11 | [PSCustomObject] @{
12 | Type = 'Image'
13 | Settings = @{
14 | ImagePath = $ImagePath
15 | Width = $Width
16 | Height = $Height
17 | BackgroundColor = ConvertFrom-Color -Color $BackgroundColor -AsDrawingColor
18 | BackgroundColorOpacity = $BackgroundColorOpacity
19 | }
20 | }
21 | }
22 |
23 | Register-ArgumentCompleter -CommandName New-PDFImage -ParameterName BackgroundColor -ScriptBlock $Script:ScriptBlockColors
--------------------------------------------------------------------------------
/Public/New-PDFInfo.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFInfo {
2 | [CmdletBinding()]
3 | param(
4 | [iText.Kernel.Pdf.PdfDocument] $PDF,
5 | [string] $Title,
6 | [string] $Author,
7 | [string] $Creator,
8 | [string] $Subject,
9 | [string[]] $Keywords,
10 | [switch] $AddCreationDate,
11 | [switch] $AddModificationDate
12 | )
13 |
14 | try {
15 | [iText.Kernel.Pdf.PdfDocumentInfo] $info = $pdf.GetDocumentInfo()
16 | } catch {
17 | Write-Warning "New-PDFInfo - Error: $($_.Exception.Message)"
18 | return
19 | }
20 |
21 | if ($Title) {
22 | $null = $info.SetTitle($Title)
23 | }
24 | if ($AddCreationDate) {
25 | $null = $info.AddCreationDate()
26 | }
27 | if ($AddModificationDate) {
28 | $null = $info.AddModDate()
29 | }
30 | if ($Author) {
31 | $null = $info.SetAuthor($Author)
32 | }
33 | if ($Creator) {
34 | $null = $info.SetCreator($Creator)
35 | }
36 | if ($Subject) {
37 | $null = $info.SetSubject($Subject)
38 | }
39 | if ($Keywords) {
40 | $KeywordsString = $Keywords -join ','
41 | $null = $info.SetKeywords($KeywordsString)
42 | }
43 | }
--------------------------------------------------------------------------------
/Public/New-PDFList.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFList {
2 | [CmdletBinding()]
3 | param(
4 | [ScriptBlock] $ListItems,
5 | [nullable[float]] $Indent,
6 | [ValidateSet('bullet', 'hyphen')][string] $Symbol = 'hyphen'
7 | )
8 |
9 | $Output = & $ListItems
10 | $Items = foreach ($_ in $Output) {
11 | if ($_.Type -eq 'ListItem') {
12 | $_.Settings
13 | }
14 | }
15 |
16 | [PSCustomObject] @{
17 | Type = 'List'
18 | Settings = @{
19 | Items = $Items
20 | Indent = $Indent
21 | Symbol = $Symbol
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Public/New-PDFListItem.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFListItem {
2 | [CmdletBinding()]
3 | param(
4 | [string[]] $Text,
5 | [ValidateScript( { & $Script:PDFFontValidationList } )][string[]] $Font,
6 | [ValidateScript( { & $Script:PDFColorValidation } )][string[]] $FontColor,
7 | [nullable[bool][]] $FontBold
8 | )
9 |
10 | $Splat = @{ }
11 | if ($Text) {
12 | $Splat['Text'] = $Text
13 | }
14 | if ($Font) {
15 | $Splat['Font'] = $Font
16 | }
17 | if ($FontColor) {
18 | $Splat['FontColor'] = $FontColor
19 | }
20 | if ($FontBold) {
21 | $Splat['FontBold'] = $FontBold
22 | }
23 |
24 | [PSCustomObject] @{
25 | Type = 'ListItem'
26 | Settings = $Splat
27 | }
28 | }
29 |
30 | Register-ArgumentCompleter -CommandName New-PDFListItem -ParameterName Font -ScriptBlock $Script:PDFFontList
31 | Register-ArgumentCompleter -CommandName New-PDFListItem -ParameterName FontColor -ScriptBlock $Script:PDFColor
--------------------------------------------------------------------------------
/Public/New-PDFOptions.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFOptions {
2 | [CmdletBinding()]
3 | param(
4 | [nullable[float]] $MarginLeft,
5 | [nullable[float]] $MarginRight,
6 | [nullable[float]] $MarginTop,
7 | [nullable[float]] $MarginBottom
8 | #[ValidateScript( { & $Script:PDFPageSizeValidation } )][string] $PageSize
9 | )
10 |
11 | [PSCustomObject] @{
12 | Type = 'Options'
13 | Settings = @{
14 | Margins = @{
15 | MarginLeft = $MarginLeft
16 | MarginRight = $MarginRight
17 | MarginTop = $MarginTop
18 | MarginBottom = $MarginBottom
19 | }
20 | #PageSize = $PageSize
21 | }
22 | }
23 | }
24 |
25 | Register-ArgumentCompleter -CommandName New-PDFOptions -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
--------------------------------------------------------------------------------
/Public/New-PDFPage.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFPage {
2 | [CmdletBinding()]
3 | param(
4 | [ScriptBlock] $PageContent,
5 | [nullable[float]] $MarginLeft,
6 | [nullable[float]] $MarginRight,
7 | [nullable[float]] $MarginTop,
8 | [nullable[float]] $MarginBottom,
9 | [ValidateScript( { & $Script:PDFPageSizeValidation } )][string] $PageSize,
10 | [switch] $Rotate
11 | )
12 | if ($null -ne $Script:PDFStart -and $Script:PDFStart['Start']) {
13 | $Page = [PSCustomObject] @{
14 | Type = 'Page'
15 | Settings = @{
16 | Margins = @{
17 | MarginLeft = $MarginLeft
18 | MarginRight = $MarginRight
19 | MarginTop = $MarginTop
20 | MarginBottom = $MarginBottom
21 | }
22 | PageSize = $PageSize
23 | Rotate = $Rotate.IsPresent
24 | PageContent = if ($PageContent) { & $PageContent } else { $null }
25 | }
26 | }
27 | $Page
28 | } else {
29 | # New-InternalPDFPage -PageSize $PageSize -Rotate:$Rotate.IsPresent
30 | }
31 | }
32 |
33 | Register-ArgumentCompleter -CommandName New-PDFPage -ParameterName PageSize -ScriptBlock $Script:PDFPageSize
--------------------------------------------------------------------------------
/Public/New-PDFTable.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFTable {
2 | [CmdletBinding()]
3 | param(
4 | [Array] $DataTable
5 | )
6 | if ($null -ne $Script:PDFStart -and $Script:PDFStart['Start']) {
7 | $Settings = [PSCustomObject] @{
8 | Type = 'Table'
9 | Settings = @{
10 | DataTable = $DataTable
11 | }
12 | }
13 | $Settings
14 | } else {
15 | New-InteralPDFTable -DataTable $DataTable
16 | }
17 | }
--------------------------------------------------------------------------------
/Public/New-PDFText.ps1:
--------------------------------------------------------------------------------
1 | function New-PDFText {
2 | [CmdletBinding()]
3 | param(
4 | [string[]] $Text,
5 | [ValidateScript( { & $Script:PDFFontValidationList } )][string[]] $Font,
6 | [ValidateScript( { & $Script:PDFColorValidation } )][string[]] $FontColor,
7 | [nullable[bool][]] $FontBold,
8 | [int] $FontSize,
9 | [ValidateScript( { & $Script:PDFTextAlignmentValidation } )][string] $TextAlignment,
10 | [nullable[float]] $MarginTop = 2,
11 | [nullable[float]] $MarginBottom = 2,
12 | [nullable[float]] $MarginLeft,
13 | [nullable[float]] $MarginRight
14 | )
15 | $Splat = @{ }
16 | if ($Text) {
17 | $Splat['Text'] = $Text
18 | }
19 | if ($Font) {
20 | $Splat['Font'] = $Font
21 | }
22 | if ($FontColor) {
23 | $Splat['FontColor'] = $FontColor
24 | }
25 | if ($FontBold) {
26 | $Splat['FontBold'] = $FontBold
27 | }
28 | if ($FontSize) {
29 | $Splat['FontSize'] = $FontSize
30 | }
31 | if ($TextAlignment) {
32 | $Splat['TextAlignment'] = $TextAlignment
33 | }
34 | if ($MarginTop) {
35 | $Splat['MarginTop'] = $MarginTop
36 | }
37 | if ($MarginBottom) {
38 | $Splat['MarginBottom'] = $MarginBottom
39 | }
40 | if ($MarginLeft) {
41 | $Splat['MarginLeft'] = $MarginLeft
42 | }
43 | if ($MarginRight) {
44 | $Splat['MarginRight'] = $MarginRight
45 | }
46 |
47 | if ($null -ne $Script:PDFStart -and $Script:PDFStart['Start']) {
48 | $Settings = [PSCustomObject] @{
49 | Type = 'Text'
50 | Settings = $Splat
51 | }
52 | $Settings
53 | } else {
54 | New-InternalPDFText @Splat
55 | }
56 | }
57 |
58 | Register-ArgumentCompleter -CommandName New-PDFText -ParameterName Font -ScriptBlock $Script:PDFFontList
59 | Register-ArgumentCompleter -CommandName New-PDFText -ParameterName FontColor -ScriptBlock $Script:PDFColor
60 | Register-ArgumentCompleter -CommandName New-PDFText -ParameterName HorizontalAlignment -ScriptBlock $Script:PDFTextAlignments
--------------------------------------------------------------------------------
/Public/Register-PDFFont.ps1:
--------------------------------------------------------------------------------
1 | function Register-PDFFont {
2 | [cmdletBinding()]
3 | param(
4 | [Parameter(Mandatory)][string] $FontName,
5 | [Parameter(Mandatory)][string] $FontPath,
6 | [ValidateScript( { & $Script:PDFFontEncodingValidation } )][string] $Encoding,
7 | [iText.Kernel.Font.PdfFontFactory+EmbeddingStrategy] $EmbeddingStrategy = [iText.Kernel.Font.PdfFontFactory+EmbeddingStrategy]::PREFER_EMBEDDED,
8 | [switch] $Cached,
9 | [switch] $Default
10 | )
11 | if (Test-Path -LiteralPath $FontPath) {
12 | try {
13 | if ($FontPath -and $Encoding) {
14 | $Script:Fonts[$FontName] = [iText.Kernel.Font.PdfFontFactory]::CreateFont($FontPath, [iText.IO.Font.PdfEncodings]::$Encoding, $EmbeddingStrategy, $Cached.IsPresent)
15 | } elseif ($FontPath) {
16 | $Script:Fonts[$FontName] = [iText.Kernel.Font.PdfFontFactory]::CreateFont($FontPath, $EmbeddingStrategy)
17 | }
18 | } catch {
19 | if ($PSBoundParameters.ErrorAction -eq 'Stop') {
20 | throw
21 | } else {
22 | Write-Warning "Register-PDFFont - Font registration failed. Error: $($_.Exception.Message)"
23 | return
24 | }
25 | }
26 | if (($Default -or $Script:Fonts.Count -eq 0) -and $Script:Fonts[$FontName]) {
27 | $Script:DefaultFont = $Script:Fonts[$FontName]
28 | }
29 | } else {
30 | if ($PSBoundParameters.ErrorAction -eq 'Stop') {
31 | throw "Font path '$FontPath' does not exist."
32 | } else {
33 | Write-Warning "Register-PDFFont - Font path does not exist. Path: $FontPath"
34 | }
35 | }
36 | }
37 |
38 | $Script:Fonts = [ordered] @{}
39 | # Validation for Fonts Encoding
40 | $Script:PDFFontEncoding = {
41 | ([iText.IO.Font.PdfEncodings] | Get-Member -Static -MemberType Property).Name
42 | }
43 | $Script:PDFFontEncodingValidation = {
44 | $Array = @(
45 | (& $Script:PDFFontEncoding)
46 | ''
47 | )
48 | $_ -in $Array
49 | }
50 | Register-ArgumentCompleter -CommandName Register-PDFFont -ParameterName Encoding -ScriptBlock $Script:PDFFontEncoding
--------------------------------------------------------------------------------
/Public/Standalone/Convert-HtmlToPDF.ps1:
--------------------------------------------------------------------------------
1 | function Convert-HTMLToPDF {
2 | <#
3 | .SYNOPSIS
4 | Converts HTML to PDF.
5 |
6 | .DESCRIPTION
7 | Converts HTML to PDF from one of three sources:
8 | 1. A file on the local file system.
9 | 2. A URL.
10 | 3. A string of HTML.
11 |
12 | .PARAMETER Uri
13 | The URI of the HTML to convert.
14 |
15 | .PARAMETER Content
16 | The HTML (as a string) to convert.
17 |
18 | .PARAMETER FilePath
19 | The path to the file containing the HTML to convert.
20 |
21 | .PARAMETER OutputFilePath
22 | The path to the file to write the PDF to.
23 |
24 | .PARAMETER Open
25 | If true, opens the PDF after it is created.
26 |
27 | .EXAMPLE
28 | Convert-HTMLToPDF -Uri 'https://evotec.xyz/hub/scripts/pswritehtml-powershell-module/' -OutputFilePath "$PSScriptRoot\Example10-FromURL.pdf" -Open
29 |
30 | .EXAMPLE
31 | $HTMLInput = New-HTML {
32 | New-HTMLText -Text 'Test 1'
33 | New-HTMLTable -DataTable (Get-Process | Select-Object -First 3)
34 | }
35 |
36 | Convert-HTMLToPDF -Content $HTMLInput -OutputFilePath "$PSScriptRoot\Example10-FromHTML.pdf" -Open
37 |
38 | .EXAMPLE
39 | New-HTML {
40 | New-HTMLTable -DataTable (Get-Process | Select-Object -First 3)
41 | } -FilePath "$PSScriptRoot\Example10-FromFilePath.html" -Online
42 |
43 | Convert-HTMLToPDF -FilePath "$PSScriptRoot\Example10-FromFilePath.html" -OutputFilePath "$PSScriptRoot\Example10-FromFilePath.pdf" -Open
44 |
45 | .NOTES
46 | General notes
47 | #>
48 | [CmdletBinding(DefaultParameterSetName = 'Uri')]
49 | param(
50 | [Parameter(Mandatory, ParameterSetName = 'Uri')][alias('Url')][string] $Uri,
51 | [Parameter(Mandatory, ParameterSetName = 'Content')][string] $Content,
52 | [Parameter(Mandatory, ParameterSetName = 'FilePath')][string] $FilePath,
53 | [Parameter(Mandatory)][string] $OutputFilePath,
54 | [switch] $Open
55 | )
56 | # Load from file or text
57 | if ($FilePath) {
58 | if (Test-Path -LiteralPath $FilePath) {
59 | $Content = [IO.File]::ReadAllText($FilePath)
60 | } else {
61 | Write-Warning "Convert-HTMLToPDF - File $FilePath doesn't exists"
62 | return
63 | }
64 | } elseif ($Content) {
65 |
66 | } elseif ($Uri) {
67 | $ProgressPreference = 'SilentlyContinue'
68 | $Content = (Invoke-WebRequest -Uri $Uri).Content
69 | } else {
70 | Write-Warning 'Convert-HTMLToPDF - No choice file or content or url. Termninated.'
71 | return
72 | }
73 | if (-not $Content) {
74 | return
75 | }
76 |
77 | $OutputFile = [System.IO.FileInfo]::new($OutputFilePath)
78 | <#
79 | static void ConvertToPdf(string html, System.IO.Stream pdfStream)
80 | static void ConvertToPdf(string html, System.IO.Stream pdfStream, iText.Html2pdf.ConverterProperties converterProperties)
81 | static void ConvertToPdf(string html, iText.Kernel.Pdf.PdfWriter pdfWriter)
82 | static void ConvertToPdf(string html, iText.Kernel.Pdf.PdfWriter pdfWriter, iText.Html2pdf.ConverterProperties converterProperties)
83 | static void ConvertToPdf(string html, iText.Kernel.Pdf.PdfDocument pdfDocument, iText.Html2pdf.ConverterProperties converterProperties)
84 | static void ConvertToPdf(System.IO.FileInfo htmlFile, System.IO.FileInfo pdfFile)
85 | static void ConvertToPdf(System.IO.FileInfo htmlFile, System.IO.FileInfo pdfFile, iText.Html2pdf.ConverterProperties converterProperties)
86 | static void ConvertToPdf(System.IO.Stream htmlStream, System.IO.Stream pdfStream)
87 | static void ConvertToPdf(System.IO.Stream htmlStream, System.IO.Stream pdfStream, iText.Html2pdf.ConverterProperties converterProperties)
88 | static void ConvertToPdf(System.IO.Stream htmlStream, iText.Kernel.Pdf.PdfDocument pdfDocument)
89 | static void ConvertToPdf(System.IO.Stream htmlStream, iText.Kernel.Pdf.PdfWriter pdfWriter)
90 | static void ConvertToPdf(System.IO.Stream htmlStream, iText.Kernel.Pdf.PdfWriter pdfWriter, iText.Html2pdf.ConverterProperties converterProperties)
91 | static void ConvertToPdf(System.IO.Stream htmlStream, iText.Kernel.Pdf.PdfDocument pdfDocument, iText.Html2pdf.ConverterProperties converterProperties)
92 | #>
93 | try {
94 | [iText.Html2pdf.HtmlConverter]::ConvertToPdf($Content, $OutputFile)
95 | } catch {
96 | Write-Warning "Convert-HTMLToPDF - Error converting to PDF. Error: $($_.Exception.Message)"
97 | return
98 | }
99 | if ($Open) {
100 | Start-Process -FilePath $OutputFilePath -Wait
101 | }
102 | }
--------------------------------------------------------------------------------
/Public/Standalone/Convert-PDFToText.ps1:
--------------------------------------------------------------------------------
1 | function Convert-PDFToText {
2 | <#
3 | .SYNOPSIS
4 | Converts PDF to TEXT
5 |
6 | .DESCRIPTION
7 | Converts PDF to TEXT
8 |
9 | .PARAMETER FilePath
10 | The path to the PDF file to convert
11 |
12 | .PARAMETER Page
13 | The page number to convert (default is all pages)
14 |
15 | .PARAMETER ExtractionStrategy
16 | The iText Extractiostrategey that is used to parse the text. Currently supports LocationTextExtractionStrategy (LT) and SimpleTextExtractionStrategy (ST)(Default).
17 |
18 | .PARAMETER IgnoreProtection
19 | The switch will allow reading of PDF files that are "owner password" encrypted for protection/security (e.g. preventing copying of text, printing etc).
20 | The switch doesn't allow reading of PDF files that are "user password" encrypted (i.e. you cannot open them without the password)
21 |
22 | .EXAMPLE
23 | # Get all pages text
24 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf"
25 |
26 | .EXAMPLE
27 | # Get all pages text with Location-Extractionstrategy
28 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -ExtractionStrategy "LT"
29 |
30 | .EXAMPLE
31 | # Get page 1 text only
32 | Convert-PDFToText -FilePath "$PSScriptRoot\Example04.pdf" -Page 1
33 |
34 | .NOTES
35 | General notes
36 | #>
37 | [CmdletBinding()]
38 | param(
39 | [string] $FilePath,
40 | [int[]] $Page,
41 | [ValidateSet("SimpleTextExtractionStrategy","LocationTextExtractionStrategy","ST","LT")]
42 | [string] $ExtractionStrategy = "SimpleTextExtractionStrategy",
43 | [switch] $IgnoreProtection
44 | )
45 | if ($FilePath -and (Test-Path -LiteralPath $FilePath)) {
46 | $ResolvedPath = Convert-Path -LiteralPath $FilePath
47 | $Source = [iText.Kernel.Pdf.PdfReader]::new($ResolvedPath)
48 | if ($IgnoreProtection) {
49 | $null = $Source.SetUnethicalReading($true)
50 | }
51 | try {
52 | [iText.Kernel.Pdf.PdfDocument] $SourcePDF = [iText.Kernel.Pdf.PdfDocument]::new($Source);
53 | if($ExtractionStrategy -eq "SimpleTextExtractionStrategy" -or $ExtractionStrategy -eq "ST") {
54 | [iText.Kernel.Pdf.Canvas.Parser.Listener.SimpleTextExtractionStrategy] $iTextExtractionStrategy = [iText.Kernel.Pdf.Canvas.Parser.Listener.SimpleTextExtractionStrategy]::new()
55 | } elseif ($ExtractionStrategy -eq "LocationTextExtractionStrategy" -or $ExtractionStrategy -eq "LT") {
56 | [iText.Kernel.Pdf.Canvas.Parser.Listener.LocationTextExtractionStrategy] $iTextExtractionStrategy = [iText.Kernel.Pdf.Canvas.Parser.Listener.LocationTextExtractionStrategy]::new()
57 | }
58 | } catch {
59 | $ErrorMessage = $_.Exception.Message
60 | Write-Warning "Convert-PDFToText - Processing document $ResolvedPath failed with error: $ErrorMessage"
61 | }
62 |
63 | $PagesCount = $SourcePDF.GetNumberOfPages()
64 | if ($Page.Count -eq 0) {
65 | for ($Count = 1; $Count -le $PagesCount; $Count++) {
66 | try {
67 | $ExtractedPage = $SourcePDF.GetPage($Count)
68 | [iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor]::GetTextFromPage($ExtractedPage, $iTextExtractionStrategy)
69 | } catch {
70 | $ErrorMessage = $_.Exception.Message
71 | Write-Warning "Convert-PDFToText - Processing document $ResolvedPath failed with error: $ErrorMessage"
72 | }
73 | }
74 | } else {
75 | foreach ($Count in $Page) {
76 | if ($Count -le $PagesCount -and $Count -gt 0) {
77 | try {
78 | $ExtractedPage = $SourcePDF.GetPage($Count)
79 | [iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor]::GetTextFromPage($ExtractedPage, $iTextExtractionStrategy)
80 | } catch {
81 | $ErrorMessage = $_.Exception.Message
82 | Write-Warning "Convert-PDFToText - Processing document $ResolvedPath failed with error: $ErrorMessage"
83 | }
84 | } else {
85 | Write-Warning "Convert-PDFToText - File $ResolvedPath doesn't contain page number $Count. Skipping."
86 | }
87 | }
88 | }
89 | try {
90 | $SourcePDF.Close()
91 | } catch {
92 | $ErrorMessage = $_.Exception.Message
93 | Write-Warning "Convert-PDFToText - Closing document $FilePath failed with error: $ErrorMessage"
94 | }
95 | } else {
96 | Write-Warning "Convert-PDFToText - Path $FilePath doesn't exists. Terminating."
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Public/Standalone/Merge-PDF.ps1:
--------------------------------------------------------------------------------
1 | function Merge-PDF {
2 | <#
3 | .SYNOPSIS
4 | Merge PDF files into one.
5 |
6 | .DESCRIPTION
7 | Merge PDF files into one.
8 |
9 | .PARAMETER InputFile
10 | The PDF files to be merged.
11 |
12 | .PARAMETER OutputFile
13 | The output file path.
14 |
15 | .PARAMETER IgnoreProtection
16 | The switch will allow reading of PDF files that are "owner password" encrypted for protection/security (e.g. preventing copying of text, printing etc).
17 | The switch doesn't allow reading of PDF files that are "user password" encrypted (i.e. you cannot open them without the password)
18 |
19 | .EXAMPLE
20 | $FilePath1 = "$PSScriptRoot\Input\OutputDocument0.pdf"
21 | $FilePath2 = "$PSScriptRoot\Input\OutputDocument1.pdf"
22 |
23 | $OutputFile = "$PSScriptRoot\Output\OutputDocument.pdf" # Shouldn't exist / will be overwritten
24 |
25 | Merge-PDF -InputFile $FilePath1, $FilePath2 -OutputFile $OutputFile
26 |
27 | .NOTES
28 | General notes
29 | #>
30 | [CmdletBinding()]
31 | param(
32 | [string[]] $InputFile,
33 | [string] $OutputFile,
34 | [switch] $IgnoreProtection
35 | )
36 |
37 | if ($OutputFile) {
38 | $ResolvedOutputFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputFile)
39 | Write-Verbose -Message "Merge-PDF - Preparing document $ResolvedOutputFile"
40 | try {
41 | [iText.Kernel.Pdf.PdfWriter] $Writer = [iText.Kernel.Pdf.PdfWriter]::new($ResolvedOutputFile)
42 | [iText.Kernel.Pdf.PdfDocument] $PDF = [iText.Kernel.Pdf.PdfDocument]::new($Writer);
43 | [iText.Kernel.Utils.PdfMerger] $Merger = [iText.Kernel.Utils.PdfMerger]::new($PDF)
44 | } catch {
45 | $ErrorMessage = $_.Exception.Message
46 | Write-Warning "Merge-PDF - Processing document $ResolvedOutputFile failed with error: $ErrorMessage"
47 | }
48 | foreach ($File in $InputFile) {
49 | $ResolvedFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($File)
50 | if ($File -and (Test-Path -LiteralPath $ResolvedFile)) {
51 | Write-Verbose -Message "Merge-PDF - Processing document $ResolvedFile"
52 | try {
53 | $Source = [iText.Kernel.Pdf.PdfReader]::new($ResolvedFile)
54 | if ($IgnoreProtection) {
55 | $null = $Source.SetUnethicalReading($true)
56 | }
57 | [iText.Kernel.Pdf.PdfDocument] $SourcePDF = [iText.Kernel.Pdf.PdfDocument]::new($Source);
58 | $null = $Merger.merge($SourcePDF, 1, $SourcePDF.getNumberOfPages())
59 | $SourcePDF.close()
60 | } catch {
61 | $ErrorMessage = $_.Exception.Message
62 | Write-Warning "Merge-PDF - Processing document $ResolvedFile failed with error: $ErrorMessage"
63 | }
64 | }
65 | }
66 | try {
67 | $PDF.Close()
68 | } catch {
69 | $ErrorMessage = $_.Exception.Message
70 | Write-Warning "Merge-PDF - Saving document $OutputFile failed with error: $ErrorMessage"
71 | }
72 | } else {
73 | Write-Warning "Merge-PDF - Output file was empty. Please give a name to file. Terminating."
74 | }
75 | }
--------------------------------------------------------------------------------
/Public/Standalone/Set-PDFForm.ps1:
--------------------------------------------------------------------------------
1 | function Set-PDFForm {
2 | <#
3 | .SYNOPSIS
4 | Will try to fill form fields in source PDF with values from hash table.
5 | Can also flatten the form to prevent changes with -flatten.
6 |
7 | .DESCRIPTION
8 | Adds a file name extension to a supplied name.
9 | Takes any strings for the file name or extension.
10 |
11 | .PARAMETER SourceFilePath
12 | Specifies the to be filled in PDF Form.
13 |
14 | .PARAMETER DestinationFilePath
15 | Specifies the output filepath for the completed form.
16 |
17 | .PARAMETER FieldNameAndValueHashTable
18 | Specifies the hashtable for the fields data. Key in the hashtable needs to match the feild name in the PDF.
19 |
20 | .PARAMETER Flatten
21 | Will flatten the output PDF so form fields will no longer be able to be changed.
22 |
23 | .PARAMETER IgnoreProtection
24 | The switch will allow reading of PDF files that are "owner password" encrypted for protection/security (e.g. preventing copying of text, printing etc).
25 | The switch doesn't allow reading of PDF files that are "user password" encrypted (i.e. you cannot open them without the password)
26 |
27 | .EXAMPLE
28 | $FilePath = [IO.Path]::Combine("$PSScriptRoot", "Output", "SampleAcroFormOutput.pdf")
29 | $FilePathSource = [IO.Path]::Combine("$PSScriptRoot", "Input", "SampleAcroForm.pdf")
30 |
31 | $FieldNameAndValueHashTable = [ordered] @{
32 | "Text 1" = "Text 1 input"
33 | "Text 2" = "Text 2 input"
34 | "Text 3" = "Text 3 input"
35 | "Check Box 1 True" = $true
36 | "Check Box 2 False" = $false
37 | "Check Box 3 False" = $false
38 | "Check Box 4 True" = $true
39 | "Doesn't Exist" = "will not be used"
40 | }
41 | Set-PDFForm -SourceFilePath $FilePathSource -DestinationFilePath $FilePath -FieldNameAndValueHashTable $FieldNameAndValueHashTable -Flatten
42 |
43 | .EXAMPLE
44 | $FilePath = [IO.Path]::Combine("$PSScriptRoot", "Output", "SampleAcroFormOutput.pdf")
45 | $FilePathSource = [IO.Path]::Combine("$PSScriptRoot", "Input", "SampleAcroForm.pdf")
46 | Set-PDFForm -SourceFilePath $FilePathSource -DestinationFilePath $FilePath -Flatten
47 |
48 | #>
49 | [CmdletBinding()]
50 | param(
51 | [Parameter(Mandatory)][ValidateNotNullOrEmpty()] $SourceFilePath,
52 | [Parameter(Mandatory)][ValidateNotNullOrEmpty()] $DestinationFilePath,
53 | [System.Collections.IDictionary] $FieldNameAndValueHashTable,
54 | [alias('FlattenFields')][Switch] $Flatten,
55 | [switch] $IgnoreProtection
56 | )
57 | $SourceFilePath = Convert-Path -LiteralPath $SourceFilePath
58 | $DestinationFolder = Split-Path -LiteralPath $DestinationFilePath
59 | $DestinationFolderPath = Convert-Path -LiteralPath $DestinationFolder -ErrorAction SilentlyContinue
60 |
61 | if ($DestinationFolderPath -and (Test-Path -LiteralPath $SourceFilePath) -and (Test-Path -LiteralPath $DestinationFolderPath)) {
62 | $File = Split-Path -Path $DestinationFilePath -Leaf
63 | $DestinationFilePath = Join-Path -Path $DestinationFolderPath -ChildPath $File
64 |
65 | try {
66 | $Script:Reader = [iText.Kernel.Pdf.PdfReader]::new($SourceFilePath)
67 | if ($IgnoreProtection) {
68 | $null = $Script:Reader.SetUnethicalReading($true)
69 | }
70 | $Script:Writer = [iText.Kernel.Pdf.PdfWriter]::new($DestinationFilePath)
71 | $PDF = [iText.Kernel.Pdf.PdfDocument]::new($Script:Reader, $Script:Writer)
72 | $PDFAcroForm = [iText.Forms.PdfAcroForm]::getAcroForm($PDF, $true)
73 | } catch {
74 | Write-Warning "Set-PDFForm - Error has occured: $($_.Exception.Message)"
75 | }
76 | foreach ($Key in $FieldNameAndValueHashTable.Keys) {
77 | $FormField = $PDFAcroForm.getField($Key)
78 | if ( -not $FormField) {
79 | Write-Warning "Set-PDFForm - No form field with name '$Key' found"
80 | continue
81 | }
82 |
83 | if ($FormField.GetType().Name -match "Button") {
84 | $null = $FormField.setValue(
85 | $FormField.GetAppearanceStates()[[Int]$FieldNameAndValueHashTable[$Key]]
86 | )
87 | } else {
88 | $null = $FormField.setValue($FieldNameAndValueHashTable[$Key])
89 | }
90 | }
91 |
92 | if ($Flatten) {
93 | $PDFAcroForm.flattenFields()
94 | }
95 |
96 | try {
97 | $PDF.Close()
98 | } catch {
99 | if ($PSBoundParameters.ErrorAction -eq 'Stop') {
100 | Write-Error $_
101 | return
102 | } else {
103 | $ErrorMessage = $_.Exception.Message
104 | Write-Warning "Set-PDFForm - Error has occured: $ErrorMessage"
105 | }
106 | }
107 | } else {
108 | if (-not (Test-Path -LiteralPath $SourceFilePath)) {
109 | Write-Warning "Set-PDFForm - Path $SourceFilePath doesn't exists. Terminating."
110 | }
111 |
112 | if (-not (Test-Path -LiteralPath $DestinationFolder)) {
113 | Write-Warning "Set-PDFForm - Folder $DestinationFolder doesn't exists. Terminating."
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/Public/Standalone/Split-PDF.ps1:
--------------------------------------------------------------------------------
1 | function Split-PDF {
2 | <#
3 | .SYNOPSIS
4 | Split PDF file into multiple files.
5 |
6 | .DESCRIPTION
7 | Split PDF file into multiple files. The output files will be named based on OutputName variable with appended numbers
8 |
9 | .PARAMETER FilePath
10 | The path to the PDF file to split.
11 |
12 | .PARAMETER OutputFolder
13 | The folder to output the split files to.
14 |
15 | .PARAMETER OutputName
16 | The name of the output files. Default is OutputDocument
17 |
18 | .PARAMETER SplitCount
19 | The number of pages to split the PDF file into. Default is 1
20 |
21 | .PARAMETER IgnoreProtection
22 | The switch will allow reading of PDF files that are "owner password" encrypted for protection/security (e.g. preventing copying of text, printing etc).
23 | The switch doesn't allow reading of PDF files that are "user password" encrypted (i.e. you cannot open them without the password)
24 |
25 | .EXAMPLE
26 | Split-PDF -FilePath "$PSScriptRoot\SampleToSplit.pdf" -OutputFolder "$PSScriptRoot\Output"
27 |
28 | .EXAMPLE
29 | Split-PDF -FilePath "\\ad1\c$\SampleToSplit.pdf" -OutputFolder "\\ad1\c$\Output"
30 |
31 | .NOTES
32 | General notes
33 | #>
34 | [CmdletBinding()]
35 | param(
36 | [Parameter(Mandatory)][string] $FilePath,
37 | [Parameter(Mandatory)][string] $OutputFolder,
38 | [string] $OutputName = 'OutputDocument',
39 | [int] $SplitCount = 1,
40 | [switch] $IgnoreProtection
41 | )
42 | if ($SplitCount -eq 0) {
43 | Write-Warning "Split-PDF - SplitCount is 0. Terminating."
44 | return
45 | }
46 |
47 | if ($FilePath -and (Test-Path -LiteralPath $FilePath)) {
48 | $ResolvedPath = Convert-Path -LiteralPath $FilePath
49 | if ($OutputFolder -and (Test-Path -LiteralPath $OutputFolder)) {
50 | try {
51 | $PDFFile = [iText.Kernel.Pdf.PdfReader]::new($ResolvedPath)
52 | if ($IgnoreProtection) {
53 | $null = $PDFFile.SetUnethicalReading($true)
54 | }
55 | $Document = [iText.Kernel.Pdf.PdfDocument]::new($PDFFile)
56 | $Splitter = [CustomSplitter]::new($Document, $OutputFolder, $OutputName)
57 | $List = $Splitter.SplitByPageCount($SplitCount)
58 | foreach ($_ in $List) {
59 | $_.Close()
60 | }
61 | } catch {
62 | $ErrorMessage = $_.Exception.Message
63 | Write-Warning "Split-PDF - Error has occured: $ErrorMessage"
64 | }
65 | try {
66 | $PDFFile.Close()
67 | } catch {
68 | $ErrorMessage = $_.Exception.Message
69 | Write-Warning "Split-PDF - Closing document $FilePath failed with error: $ErrorMessage"
70 | }
71 | } else {
72 | Write-Warning "Split-PDF - Destination folder $OutputFolder doesn't exists. Terminating."
73 | }
74 | } else {
75 | Write-Warning "Split-PDF - Path $FilePath doesn't exists. Terminating."
76 | }
77 | }
--------------------------------------------------------------------------------
/Publish/Manage-Module.ps1:
--------------------------------------------------------------------------------
1 | Clear-Host
2 | Import-Module 'C:\Support\GitHub\PSPublishModule\PSPublishModule.psm1' -Force
3 |
4 | $Configuration = @{
5 | Information = @{
6 | ModuleName = 'PSWritePDF'
7 | DirectoryProjects = 'C:\Support\GitHub'
8 | LibrariesCore = 'Lib\Core'
9 | LibrariesDefault = 'Lib\Default'
10 | Manifest = @{
11 | # Minimum version of the Windows PowerShell engine required by this module
12 | PowerShellVersion = '5.1'
13 | # Supported PSEditions
14 | CompatiblePSEditions = @('Desktop', 'Core')
15 | # ID used to uniquely identify this module
16 | GUID = '19fcb43c-d8c5-44a9-84e4-bccf29765490'
17 | # Version number of this module.
18 | ModuleVersion = '0.0.X'
19 | # Author of this module
20 | Author = 'Przemyslaw Klys'
21 | # Company or vendor of this module
22 | CompanyName = 'Evotec'
23 | # Copyright statement for this module
24 | Copyright = "(c) 2011 - $((Get-Date).Year) Przemyslaw Klys @ Evotec. All rights reserved."
25 | # Description of the functionality provided by this module
26 | Description = 'Little project to create, read, modify, split, merge PDF files on Windows, Linux and Mac.'
27 | # Tags applied to this module. These help with module discovery in online galleries.
28 | Tags = @('PDF', 'macOS', 'linux', 'windows')
29 | # A URL to the main website for this project.
30 | ProjectUri = 'https://github.com/EvotecIT/PSWritePDF'
31 |
32 | LicenseUri = 'https://github.com/EvotecIT/PSWritePDF/blob/master/LICENSE'
33 |
34 | IconUri = 'https://evotec.xyz/wp-content/uploads/2019/11/PSWritePDF.png'
35 |
36 | RequiredModules = @(
37 | @{ ModuleName = 'PSSharedGoods'; ModuleVersion = 'Latest'; Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe' }
38 | )
39 | }
40 | }
41 | Options = @{
42 | Merge = @{
43 | Sort = 'None'
44 | FormatCodePSM1 = @{
45 | Enabled = $true
46 | RemoveComments = $false
47 | FormatterSettings = @{
48 | IncludeRules = @(
49 | 'PSPlaceOpenBrace',
50 | 'PSPlaceCloseBrace',
51 | 'PSUseConsistentWhitespace',
52 | 'PSUseConsistentIndentation',
53 | 'PSAlignAssignmentStatement',
54 | 'PSUseCorrectCasing'
55 | )
56 |
57 | Rules = @{
58 | PSPlaceOpenBrace = @{
59 | Enable = $true
60 | OnSameLine = $true
61 | NewLineAfter = $true
62 | IgnoreOneLineBlock = $true
63 | }
64 |
65 | PSPlaceCloseBrace = @{
66 | Enable = $true
67 | NewLineAfter = $false
68 | IgnoreOneLineBlock = $true
69 | NoEmptyLineBefore = $false
70 | }
71 |
72 | PSUseConsistentIndentation = @{
73 | Enable = $true
74 | Kind = 'space'
75 | PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline'
76 | IndentationSize = 4
77 | }
78 |
79 | PSUseConsistentWhitespace = @{
80 | Enable = $true
81 | CheckInnerBrace = $true
82 | CheckOpenBrace = $true
83 | CheckOpenParen = $true
84 | CheckOperator = $true
85 | CheckPipe = $true
86 | CheckSeparator = $true
87 | }
88 |
89 | PSAlignAssignmentStatement = @{
90 | Enable = $true
91 | CheckHashtable = $true
92 | }
93 |
94 | PSUseCorrectCasing = @{
95 | Enable = $true
96 | }
97 | }
98 | }
99 | }
100 | FormatCodePSD1 = @{
101 | Enabled = $true
102 | RemoveComments = $false
103 | }
104 | Integrate = @{
105 | ApprovedModules = @('PSSharedGoods', 'PSWriteColor', 'Connectimo', 'PSUnifi', 'PSWebToolbox', 'PSMyPassword')
106 | }
107 | }
108 | Standard = @{
109 | FormatCodePSM1 = @{
110 |
111 | }
112 | FormatCodePSD1 = @{
113 | Enabled = $true
114 | #RemoveComments = $true
115 | }
116 | }
117 | ImportModules = @{
118 | Self = $true
119 | RequiredModules = $false
120 | Verbose = $false
121 | }
122 | PowerShellGallery = @{
123 | ApiKey = 'C:\Support\Important\PowerShellGalleryAPI.txt'
124 | FromFile = $true
125 | }
126 | GitHub = @{
127 | ApiKey = 'C:\Support\Important\GithubAPI.txt'
128 | FromFile = $true
129 | UserName = 'EvotecIT'
130 | #RepositoryName = 'PSWriteHTML'
131 | }
132 | Documentation = @{
133 | Path = 'Docs'
134 | PathReadme = 'Docs\Readme.md'
135 | }
136 | }
137 | Steps = @{
138 | BuildModule = @{ # requires Enable to be on to process all of that
139 | Enable = $true
140 | DeleteBefore = $true
141 | Merge = $true
142 | MergeMissing = $true
143 | SignMerged = $true
144 | Releases = $true
145 | LibrarySeparateFile = $true
146 | ReleasesUnpacked = $false
147 | RefreshPSD1Only = $false
148 | }
149 | BuildDocumentation = $false
150 | ImportModules = @{
151 | Self = $true
152 | RequiredModules = $false
153 | Verbose = $false
154 | }
155 | PublishModule = @{ # requires Enable to be on to process all of that
156 | Enabled = $false
157 | Prerelease = ''
158 | RequireForce = $false
159 | GitHub = $false
160 | }
161 | }
162 | }
163 |
164 | New-PrepareModule -Configuration $Configuration
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |