使用 Powershell 和 Word 2013 在文档中保存图片
Save pictures in document using Powershell and Word 2013
我正在尝试通过 Powershell 命令使用 MS Word 2013 将具有外部链接图像的 HTML 文件转换为 RTF,当使用以下命令时文件被转换但是图片丢失
$wrd = New-Object -ComObject "Word.Application"
$doc = $wrd.Documents.Open('c:\test.html')
$opt = [ref][Microsoft.Office.Interop.Word.WdSaveFormat]::WdFormatRTF
$name= [ref]'C:\test.rtf'
$wrd.ActiveDocument.SaveAs($name, $opt)
$wrd.ActiveDocument.Close()
$wrd.Quit()
如果我通过使用 Word 打开 HTML 文件并将其另存为 RTF 文件来手动进行转换,同样的事情也会发生,没有图像,但是如果在 Word 中我转到文件,单击 "Edit Links to File"并突出显示所有图像,勾选 "Save picture in document",然后单击 "Break Link",然后另存为 RTF,这次图像以 RTF 格式显示(但质量较差,这是另一个问题..)[见图片以下]
有没有办法在 Powershell 中执行上述过程?
谢谢
这样就可以了
$images = $doc.InlineShapes
foreach ($image in $images) {
$linkFormat = $image.LinkFormat
$linkFormat.SavePictureWithDocument = 1
$linkFormat.BreakLink()
}
我正在尝试通过 Powershell 命令使用 MS Word 2013 将具有外部链接图像的 HTML 文件转换为 RTF,当使用以下命令时文件被转换但是图片丢失
$wrd = New-Object -ComObject "Word.Application"
$doc = $wrd.Documents.Open('c:\test.html')
$opt = [ref][Microsoft.Office.Interop.Word.WdSaveFormat]::WdFormatRTF
$name= [ref]'C:\test.rtf'
$wrd.ActiveDocument.SaveAs($name, $opt)
$wrd.ActiveDocument.Close()
$wrd.Quit()
如果我通过使用 Word 打开 HTML 文件并将其另存为 RTF 文件来手动进行转换,同样的事情也会发生,没有图像,但是如果在 Word 中我转到文件,单击 "Edit Links to File"并突出显示所有图像,勾选 "Save picture in document",然后单击 "Break Link",然后另存为 RTF,这次图像以 RTF 格式显示(但质量较差,这是另一个问题..)[见图片以下]
有没有办法在 Powershell 中执行上述过程?
谢谢
这样就可以了
$images = $doc.InlineShapes
foreach ($image in $images) {
$linkFormat = $image.LinkFormat
$linkFormat.SavePictureWithDocument = 1
$linkFormat.BreakLink()
}