Guest User

Untitled

a guest
Dec 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. param(
  2. [parameter(position=0)]
  3. [string] $Path
  4. )
  5.  
  6. # make the powershell process switch the current directory.
  7. $oldwd = [Environment]::CurrentDirectory
  8. [Environment]::CurrentDirectory = $pwd
  9.  
  10. $docFiles = (Get-ChildItem "$Path\*" -Include *.doc,*.docx) # -Recurse)
  11.  
  12. $word = New-Object -ComObject Word.Application
  13. $word.visible = $false
  14. [ref]$SaveFormat = "Microsoft.Office.Interop.Word.WdSaveFormat" -as [type]
  15.  
  16. function delpp ($inlineobj) {
  17. #"got $inlineobj"
  18. if ($inlineobj) {
  19. "Got NULL"
  20. return
  21. }
  22. else {
  23. Write-Host "DEL ", $inlineobj.Height, $inlineobj.Width
  24. $inlineobj.Delete()
  25. return
  26. }
  27. }
  28.  
  29. foreach ($dc in $docFiles)
  30. {
  31.  
  32. $dp = resolve-path $dc;
  33. $newdp = "$dp.docx"
  34.  
  35. $doc = $word.Documents.Open($dp.toString())
  36.  
  37. $doc.ActiveWindow.View = 3 #wdPrintView
  38.  
  39. $picnum = $doc.InlineShapes.Count
  40.  
  41. foreach ($pp in $doc.InlineShapes)
  42. {
  43. Write-Host "--> ", $pp.Height, $pp.Width
  44. $pp.LockAspectRatio = $true
  45.  
  46. # QRcode
  47. if ($pp.Width -eq $pp.Height) { delpp($pp) }
  48.  
  49. # looks not a pic
  50. if ($pp.Width -lt 100 -or $pp.Height -lt 50) { delpp($pp) }
  51.  
  52. if ($pp.Height -gt 340 -and $pp.Height -lt 350) { delpp($pp) }
  53.  
  54. if($pp.Width -ge 480) {
  55. #$pp.Width = $word.CentimetersToPoints(12)
  56. $pp.Width = 480
  57. Write-Host "<-- ", $pp.Height, $pp.Width
  58. }
  59.  
  60. # if ($pp.Width * 100 % 100 -eq 75 ) { delpp($pp) }
  61. }
  62. $doc.saveas([ref]$newdp, [ref]$SaveFormat::wdFormatDocumentDefault)
  63. $doc.close()
  64. #break
  65. }
  66.  
  67. $word.Quit()
  68. $word = $null
  69. [gc]::collect()
  70. [gc]::WaitForPendingFinalizers()
Add Comment
Please, Sign In to add comment