xpdf可以在Powershell中接受变量作为路径参数吗?

时间:2018-05-29 19:16:29

标签: .net winforms powershell xpdf

我收到错误:

.\pdftotext.exe : pdftotext version 4.00
At C:\Users\eakinsa\Desktop\Style Guide Report\styleGuideReport.ps1:62 char:88
+ ... Style Guide Report\Includes\bin32\"; .\pdftotext.exe $selectedFile })
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (pdftotext version 4.00:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

使用以下代码行:

$okButton.Add_Click({cd "C:\Users\eakinsa\Desktop\Style Guide Report\Includes\bin32\"; .\pdftotext.exe $selectedFile })

我怀疑这是一个错误,因为我正在运行的可执行文件不接受Powershell变量作为参数,但我不确定。如果是这种情况,是否有解决方法?

背景资料:

我正在编写一个接受用户输入的pdf文件位置的脚本(通过文件打开对话框),并将结果存储在一个变量中,希望将其用作xpdf'的路径参数。 s pdftotext.exe。

[void][System.Reflection.Assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][System.Reflection.Assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
$MainForm = New-Object -TypeName System.Windows.Forms.Form
[System.Windows.Forms.Button]$okButton = $null
[System.Windows.Forms.Button]$cancelButton = $null
[System.Windows.Forms.PictureBox]$pictureBox1 = $null
[System.Windows.Forms.Label]$Label = $null
[System.Windows.Forms.OpenFileDialog]$openFileDialog1 = $null
[System.Windows.Forms.Button]$BrowseButton = $null
[System.Windows.Forms.Button]$button1 = $null
function InitializeComponent
{
$resources = Invoke-Expression (Get-Content "C:\Users\eakinsa\Desktop\Style Guide Report\Includes\Form1.resources.psd1" -Raw)
$okButton = (New-Object -TypeName System.Windows.Forms.Button)
$cancelButton = (New-Object -TypeName System.Windows.Forms.Button)
$pictureBox1 = (New-Object -TypeName System.Windows.Forms.PictureBox)
$Label = (New-Object -TypeName System.Windows.Forms.Label)
$openFileDialog1 = (New-Object -TypeName System.Windows.Forms.OpenFileDialog)
$BrowseButton = (New-Object -TypeName System.Windows.Forms.Button)
([System.ComponentModel.ISupportInitialize]$pictureBox1).BeginInit()
$MainForm.SuspendLayout()

#
#BrowseDialog Button
#

$browse = new-object system.windows.Forms.OpenFileDialog
$browse.InitialDirectory = "C:\"

$BrowseButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Popup
$BrowseButton.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]16,[System.Int32]212))
$BrowseButton.Name = [System.String]'BrowseButton'
$BrowseButton.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]75,[System.Int32]23))
$BrowseButton.TabIndex = [System.Int32]1
$BrowseButton.Text = [System.String]'Browse'
$BrowseButton.UseVisualStyleBackColor = $true
$BrowseButton.Add_Click({$browse.ShowDialog() | Out-Null})
$selectedFile = $browse.FileName


#
#cancelButton-Cancel
#
$cancelButton.ForeColor = [System.Drawing.Color]::Crimson
$cancelButton.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]545,[System.Int32]439))
$cancelButton.Name = [System.String]'cancelButton'
$cancelButton.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]75,[System.Int32]23))
$cancelButton.TabIndex = [System.Int32]2
$cancelButton.Text = [System.String]'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$cancelButton.UseVisualStyleBackColor = $true

#
#okButton-Okay
#
$okButton.ForeColor = [System.Drawing.Color]::ForestGreen
$okButton.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]626,[System.Int32]440))
$okButton.Name = [System.String]'okButton'
$okButton.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]75,[System.Int32]23))
$okButton.TabIndex = [System.Int32]3
$okButton.Text = [System.String]'OK'
$okButton.Add_Click({cd "C:\Users\eakinsa\Desktop\Style Guide Report\Includes\bin32\"; .\pdftotext.exe $selectedFile })
$okButton.UseVisualStyleBackColor = $true

#
#pictureBox1
#

$pictureBox1.Image = ([System.Drawing.Image]$resources.'pictureBox1.Image')
$pictureBox1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]12))
$pictureBox1.Name = [System.String]'pictureBox1'
$pictureBox1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]689,[System.Int32]165))
$pictureBox1.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
$pictureBox1.TabIndex = [System.Int32]2
$pictureBox1.TabStop = $false
$pictureBox1.add_Click($pictureBox1_Click)
#
#Label
#
$Label.AutoSize = $true
$Label.ForeColor = [System.Drawing.Color]::Black
$Label.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]184))
$Label.Name = [System.String]'Label'
$Label.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]570,[System.Int32]13))
$Label.TabIndex = [System.Int32]3
$Label.Text = [System.String]'Use this tool to get a custom report that flags potential style errors in a PDF based on the Elsevier style guide.'
#
#openFileDialog1
#
$openFileDialog1.FileName = [System.String]'openFileDialog1'

#MainForm
#
$MainForm.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]713,[System.Int32]475))
$MainForm.Controls.Add($BrowseButton)
$MainForm.Controls.Add($Label)
$MainForm.Controls.Add($pictureBox1)
$MainForm.Controls.Add($cancelButton)
$MainForm.Controls.Add($okButton)
$MainForm.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Segoe UI',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0)))
$MainForm.ForeColor = [System.Drawing.Color]::ForestGreen
$MainForm.Name = [System.String]'MainForm'
$MainForm.Text = [System.String]'PDF Style Reporting Tool'
([System.ComponentModel.ISupportInitialize]$pictureBox1).EndInit()
$MainForm.ResumeLayout($false)
$MainForm.PerformLayout()
$MainForm.ShowDialog()
Add-Member -InputObject $MainForm -Name base -Value $base -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name okButton -Value $okButton -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name cancelButton -Value $cancelButton -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name pictureBox1 -Value $pictureBox1 -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name Label -Value $Label -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name openFileDialog1 -Value $openFileDialog1 -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name BrowseButton -Value $BrowseButton -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name button1 -Value $button1 -MemberType NoteProperty
}
. InitializeComponent

0 个答案:

没有答案