From 5984acfca0c29ca1b368bdc4d4c08581aee13094 Mon Sep 17 00:00:00 2001
From: Mikael Karlsson <43226266+Micke-K@users.noreply.github.com>
Date: Sun, 25 May 2025 21:07:57 +1000
Subject: [PATCH] 3.10.0.4
Fixed issue with Word Interop not loading
Added support for PDF output
---
Extensions/DocumentationCustom.psm1 | 2 +-
Extensions/DocumentationWord.psm1 | 36 +++++++++++++++++++++++++++--
Xaml/DocumentationWordOptions.xaml | 7 ++++++
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/Extensions/DocumentationCustom.psm1 b/Extensions/DocumentationCustom.psm1
index 0590956..f7a3b66 100644
--- a/Extensions/DocumentationCustom.psm1
+++ b/Extensions/DocumentationCustom.psm1
@@ -422,7 +422,7 @@ function Add-CDDocumentCustomProfileValue
$value = $obj.startMenuAppListVisibility
if($value.IndexOf(", ") -eq -1)
{
- $value = $value -replace ",",", " # Option values in json file has space afte , but value in object don't
+ $value = $value -replace ",",", " # Option values in json file has space after , but value in object don't
}
Invoke-TranslateOption $obj $prop -PropValue $value
return $false
diff --git a/Extensions/DocumentationWord.psm1 b/Extensions/DocumentationWord.psm1
index a9bd12b..5352ffc 100644
--- a/Extensions/DocumentationWord.psm1
+++ b/Extensions/DocumentationWord.psm1
@@ -10,15 +10,32 @@ function Invoke-InitializeModule
{
if(!("Microsoft.Office.Interop.Word.Application" -as [Type]))
{
+ $loaded = $false
try
{
Add-Type -AssemblyName Microsoft.Office.Interop.Word
+ $loaded = $true
+ }
+ catch { }
+ try
+ {
+ $wordFile = Get-ChildItem -path "$($env:windir)\assembly\GAC_MSIL" -Filter "Microsoft.Office.Interop.Word.dll" -Recurse
+ if($wordFile -and $wordFile.Exists)
+ {
+ Add-Type -Path $wordFile.FullName
+ $loaded = $true
+ }
}
catch
{
Write-LogError "Failed to add Word Interop type. Cannot create word documents. Verify that Word is installed properly." $_.Exception
return
}
+
+ if(-not $loaded) {
+ Write-LogError "Word Interop type not found. Cannot create word documents. Verify that Word is installed properly." $_.Exception
+ return
+ }
}
Add-OutputType ([PSCustomObject]@{
@@ -46,6 +63,9 @@ function Add-WordOptionsControl
$global:spWordCustomProperties.Visibility = (?: ($global:cbWordDocumentationProperties.SelectedValue -ne "custom") "Collapsed" "Visible")
$global:txtWordCustomProperties.Visibility = (?: ($global:cbWordDocumentationProperties.SelectedValue -ne "custom") "Collapsed" "Visible")
+ $global:cbWordDocumentationFormat.ItemsSource = ("[ { Name: `"Docx`",Value: `"docx`" }, { Name: `"PDF`",Value: `"pdf`" }]" | ConvertFrom-Json)
+ $global:cbWordDocumentationFormat.SelectedValue = (Get-Setting "Documentation" "WordDocumentFormat" "docx")
+
$global:cbWordDocumentationLevel.ItemsSource = ("[ { Name: `"Full`",Value: `"full`" }, { Name: `"Limited`",Value: `"limited`" }, { Name: `"Basic`",Value: `"basic`" }]" | ConvertFrom-Json)
$global:cbWordDocumentationLevel.SelectedValue = (Get-Setting "Documentation" "WordDocumentationLevel" "full")
@@ -112,8 +132,9 @@ function Invoke-WordActivate
function Invoke-WordPreProcessItems
{
- Save-Setting "Documentation" "WordExportProperties" $global:cbWordDocumentationProperties.SelectedValue
+ Save-Setting "Documentation" "WordExportProperties" $global:cbWordDocumentationProperties.SelectedValue
Save-Setting "Documentation" "WordCustomDisplayProperties" $global:txtWordCustomProperties.Text
+ Save-Setting "Documentation" "WordDocumentFormat" $global:cbWordDocumentationFormat.SelectedValue
Save-Setting "Documentation" "WordDocumentTemplate" $global:txtWordDocumentTemplate.Text
Save-Setting "Documentation" "WordDocumentName" $global:txtWordDocumentName.Text
@@ -384,6 +405,14 @@ function Invoke-WordPostProcessItems
$script:doc.TablesOfFigures | ForEach-Object -Process { $_.Update() | Out-Null }
$script:doc.TablesOfAuthorities | ForEach-Object -Process { $_.Update() | Out-Null }
+ if($global:cbWordDocumentationFormat.SelectedValue -eq "pdf")
+ {
+ $format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatPDF
+ }
+ else {
+ $format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatDocumentDefault
+ }
+
$fileName = $global:txtWordDocumentName.Text
if(-not $fileName)
{
@@ -392,7 +421,10 @@ function Invoke-WordPostProcessItems
$fileName = Expand-FileName $fileName
- $format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatDocumentDefault
+ if($format -eq [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatPDF -and $fileName -notlike "*.pdf")
+ {
+ $fileName = [IO.Path]::ChangeExtension($fileName, ".pdf")
+ }
try
{
diff --git a/Xaml/DocumentationWordOptions.xaml b/Xaml/DocumentationWordOptions.xaml
index 414c891..b601d20 100644
--- a/Xaml/DocumentationWordOptions.xaml
+++ b/Xaml/DocumentationWordOptions.xaml
@@ -57,6 +57,13 @@
+
+
+
+
+
+