- Microsoft Windows 10 (The "real thing" will run on Microsoft Windows Server 2012)
- Microsoft Office 365 (The "real thing" will use Microsoft Office 2016)
Jenkins build / test env notes
TODO: automate/script windows dev box (with vagrant?) This is to deep-slice test the whole "strawman"/"concept" of the whole PDF creation processing:
On a Linux Jenkins box:
- start a Microsoft windows dev virtualbox
- with a configured windows "shared drive" so the Linux host OS (acting here as the "Solaris env") can interact with it
- a dev/test/mock windows process (script) will produce the input ("patient record files") in order to trigger and test:
- the windows FileWatcher powersell script to parse the patient record input files, and create patient record sub-dir
- then convert the MS Office files to PDFs, and output those into some shared output dir (for the Linux host ("Solaris") for further processing (the PDF processing and merging).
This is the original script that was tested to convert the example patient record MS Office files to PDF on Windows box:
# This script converts all the .doc and .docx files in the `$documents_path` dir to .pdf
#
# It needs proper/robust error handling:
# - https://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf
# NOTE: the 2nd post about crashes, and their ("typical") m$ workaround
#
$documents_path = '.\test_files'
$word_app = New-Object -ComObject Word.Application
# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {
$document = $word_app.Documents.Open($_.FullName)
$pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
}
$word_app.Quit()
- NOTE: configuration information?; MS Office input files ("Filter") configured as env var ?
setx DEHS_PDF_PROCESSOR_INPUT_FILES "*.doc, *.docx, *.xls, *.xlsx, *.ppt, *.rtf"
CLEANUP and re-test script notes
# This script converts all the .doc and .docx files in the `$documents_path` dir to .pdf
#
# It needs proper/robust error handling:
# - https://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf
# NOTE: the 2nd post about crashes, and their ("typical") m$ workaround
#
$documents_path = '.\test_files'
$word_app = New-Object -ComObject Word.Application
# This filter will find .doc as well as .docx documents
#Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {
Get-ChildItem -Path $documents_path\* -Include *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.rtf | ForEach-Object {
try {
$document = $word_app.Documents.Open($_.FullName)
$pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
$document.SaveAs([ref] $pdf_filename, [ref] 17)
}
catch {
# NOTE: Write some error log info
Write-Host "An error occurred:"
Write-Host $_.ScriptStackTrace
}
finally {
# NOTE: during testing I got an error, that in turn ended-up:
# 1. opening 5 instances of word
# 2. hanging/crashing
#
$document.Close() // TEST: is this reference visible or do we have to declare it "above/before" the try?
}
}
$word_app.Quit()
# TODO: HOW are we going to handle errors?
- NOTE: The script does need proper error handling! try-catch or at least a proper if-else with
$document.Close()
to avoid opening multiple instances of MS Word and hanging.
PS C:\Users\marti\src> C:\Users\marti\src\convert_msoffice_to_pdf.ps1
File C:\Users\marti\src\convert_msoffice_to_pdf.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\marti\src> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
PS C:\Users\marti\src> Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
PS C:\Users\marti\src> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Unrestricted
LocalMachine Undefined
PS C:\Users\marti\src> C:\Users\marti\src\convert_msoffice_to_pdf.ps1
PS C:\Users\marti\src>
- https://developer.microsoft.com/en-us/windows/downloads/virtual-machines
- https://medium.com/@phasslr/access-microsoft-excel-from-java-the-low-budget-way-6b57eece4204 Might get handy if we are going to reimplement the powershell MS Office files to PDF conversion in Java 8
- TODO