我有一个Word (Office,2013)文档,我需要将文档的每一页分割成一个单独的PDF。因此,我使用PowerShell将其组合在一起。
$Word = New-Object -ComObject Word.Application
$Word.Visible = $true
$Doc = $Word.Documents.Open($SourceFile)
for ($pageNo = 1; $pageNo -le 50; $pageNo++)
{
$OutputFile = $OutputDirectory + "\MyFile_" + $pageNo + ".pdf"
$Doc.ExportAsFixedFormat($OutputFile, [Microsoft.Office.Interop.Word.WdExportFormat]::wdExportFormatPDF, $false, [Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForPrint, [Microsoft.Office.Interop.Word.WdExportRange]::wdExportFromTo, $pageNo, $pageNo, [Microsoft.Office.Interop.Word.WdExportItem]::wdExportDocumentContent, $false, $false, [Microsoft.Office.Interop.Word.WdExportCreateBookmarks]::wdExportCreateNoBookmarks, $false, $true, $false, $null)
}
$Doc.Close()
$Word.Quit()
我已经完成了最后一个参数,它期望这是对此的引用。
[ref] System.Object FixedFormatExtClassPtr
我尝试过传递$null,0,每个都有或没有引用,但是我得到了以下错误:
论据:“15”应该是System.Management.Automation.PSReference。使用参考文献。
对于最后一个参数我需要传递什么,有什么想法吗?或者,是否有更简单的方法来完成这项任务?
发布于 2014-03-02 13:43:19
我刚刚发现我做错了什么。对于最后一个参数,我需要使用System.Type.Missing。
$Word = New-Object -ComObject Word.Application
$Word.Visible = $true
$Doc = $Word.Documents.Open($SourceFile)
$fixedFromatExtClassPtr = [System.Type]::Missing
for ($pageNo = 1; $pageNo -le 50; $pageNo++)
{
$OutputFile = $OutputDirectory + "\MyFile_" + $pageNo + ".pdf"
$Doc.ExportAsFixedFormat($OutputFile, [Microsoft.Office.Interop.Word.WdExportFormat]::wdExportFormatPDF, $false, [Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForPrint, [Microsoft.Office.Interop.Word.WdExportRange]::wdExportFromTo, $pageNo, $pageNo, [Microsoft.Office.Interop.Word.WdExportItem]::wdExportDocumentContent, $false, $false, [Microsoft.Office.Interop.Word.WdExportCreateBookmarks]::wdExportCreateNoBookmarks, $false, $true, $false, [ref]$fixedFromatExtClassPtr)
}
$Doc.Close()
$Word.Quit()
https://stackoverflow.com/questions/22133373
复制