-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathword2jpg.ps1
53 lines (39 loc) · 1.52 KB
/
word2jpg.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
function word2pdf {
param ($documents_path)
if (-not (test-path "$PSScriptRoot\jpg")) {
mkdir "$PSScriptRoot\jpg"
}
else {
Remove-Item "$PSScriptRoot\jpg\*" -Recurse
}
$word_app = New-Object -ComObject Word.Application
Get-ChildItem -Path $documents_path -Filter *.doc? -r | ForEach-Object {
$document = $word_app.Documents.Open($_.FullName)
$pdf_fullname = "$($PSScriptRoot)\jpg\$($_.BaseName).pdf"
$document.SaveAs($pdf_fullname, 17)
$document.Close()
write-host $pdf_fullname
}
$word_app.Quit()
}
function pdf2jpg {
param ($documents_path)
Get-ChildItem $documents_path *.pdf -r | ForEach-Object {
$pdf_fullname = "$($_.DirectoryName)\$($_.basename).pdf"
$jpg_path = "$PSScriptRoot\jpg\$($_.basename).jpg"
write-host $jpg_path
$exe_path = "$PSScriptRoot\bin\gswin32c.exe"
& $exe_path -dNOPAUSE -sDEVICE=jpeg -o "$jpg_path" -dFirstPage=1 -dJPEGQ=80 -r300 -f "$pdf_fullname" -c quit
write-host $jpg_path
Remove-Item $pdf_fullname
}
}
if ($args.count -eq 1) {
write-host "Convert doc(x) files in '$args' directory to jpg:" -ForegroundColor Green -BackgroundColor Black
word2pdf($args)
pdf2jpg("$PSScriptRoot\jpg")
}
else {
write-host "Need only one Parameter: -Path documents_path" -ForegroundColor Red -BackgroundColor Black
}