Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [parameter(position=0)]
- [string] $Path
- )
- # make the powershell process switch the current directory.
- $oldwd = [Environment]::CurrentDirectory
- [Environment]::CurrentDirectory = $pwd
- $docFiles = (Get-ChildItem "$Path\*" -Include *.doc,*.docx) # -Recurse)
- $word = New-Object -ComObject Word.Application
- $word.visible = $false
- [ref]$SaveFormat = "Microsoft.Office.Interop.Word.WdSaveFormat" -as [type]
- function delpp ($inlineobj) {
- #"got $inlineobj"
- if ($inlineobj) {
- "Got NULL"
- return
- }
- else {
- Write-Host "DEL ", $inlineobj.Height, $inlineobj.Width
- $inlineobj.Delete()
- return
- }
- }
- foreach ($dc in $docFiles)
- {
- $dp = resolve-path $dc;
- $newdp = "$dp.docx"
- $doc = $word.Documents.Open($dp.toString())
- $doc.ActiveWindow.View = 3 #wdPrintView
- $picnum = $doc.InlineShapes.Count
- foreach ($pp in $doc.InlineShapes)
- {
- Write-Host "--> ", $pp.Height, $pp.Width
- $pp.LockAspectRatio = $true
- # QRcode
- if ($pp.Width -eq $pp.Height) { delpp($pp) }
- # looks not a pic
- if ($pp.Width -lt 100 -or $pp.Height -lt 50) { delpp($pp) }
- if ($pp.Height -gt 340 -and $pp.Height -lt 350) { delpp($pp) }
- if($pp.Width -ge 480) {
- #$pp.Width = $word.CentimetersToPoints(12)
- $pp.Width = 480
- Write-Host "<-- ", $pp.Height, $pp.Width
- }
- # if ($pp.Width * 100 % 100 -eq 75 ) { delpp($pp) }
- }
- $doc.saveas([ref]$newdp, [ref]$SaveFormat::wdFormatDocumentDefault)
- $doc.close()
- #break
- }
- $word.Quit()
- $word = $null
- [gc]::collect()
- [gc]::WaitForPendingFinalizers()
Add Comment
Please, Sign In to add comment