我正在旋轉我的輪子。我有一個使用vb.net的asp.net網站。我通過Intranet SharePoint頁面鏈接到此ASP.net站點。我有一些代碼可以從SSRS報告中生成PDF文件。現在在代碼的相同行中,我想打印PDF文件。我發現這個做,但沒有運氣得到它的工作:On Button點擊從服務器打印PDF
''''PRINT REPORT
''get default printer
Dim oPS As New System.Drawing.Printing.PrinterSettings
Dim defaultprintername As String = ""
Try
'Set my print ---- defaultprintername = "Dell 3330dn Laser Printer XL"
defaultprintername = oPS.PrinterName
Catch ex As System.Exception
defaultprintername = ""
SendAllLabel.Text = "ERROR - Could not set printer"
Finally
oPS = Nothing
End Try
Dim pathToExecutable As String = "AcroRd32.exe"
Dim starter As New ProcessStartInfo(pathToExecutable, "/t " + strReportOutput + " " + defaultprintername + "")
Dim Process As New Process()
Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
Process.StartInfo.UseShellExecute = True
Process.StartInfo.Verb = "print"
Process.StartInfo.CreateNoWindow = True
Process.StartInfo = starter
''WILL NOT START BUT NO EXCEPTION
Try
Process.Start()
Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
Catch ex As System.Exception
SendAllLabel.Text = "ERROR - Could not set print job."
End Try
System.Threading.Thread.Sleep(30000)
Process.CloseMainWindow()
Dim iLoop As Int16 = 0
'check the process has exited or not
If Process.HasExited = False Then
Try
Process.Kill()
Catch ex As Exception
SendAllLabel.Text = "ERROR - Could not stop process."
End Try
'if not then loop for 100 time to try and close the process'with 10 seconds delay
While Not Process.HasExited
System.Threading.Thread.Sleep(10000)
Process.CloseMainWindow()
iLoop = CShort(iLoop + 1)
If iLoop >= 100 Then
Try
Process.Kill()
Catch ex As Exception
SendAllLabel.Text = "ERROR - Could not stop process."
End Try
Exit While
End If
End While
End If
Process.Close()
Process.Dispose()
Process = Nothing
starter = Nothing
需要採取哪些措施來得到這個工作?我看到很多引用此代碼的網站,但沒有超出它的範圍。我需要授予權限嗎?如果是這樣,我該怎麼做?該服務器正在使用Adobe Reader 10.0,大多數用戶正在使用Reader 11.0。
請和謝謝你
你一定要明白,如果你告訴它在ASP代碼打印,你問它來打印你的服務器上,而不是客戶端計算機,對吧? – Steve
您可以在新的網頁瀏覽器中打開PDF,這會給您打印選項。這足夠嗎? – voddy
服務器上的默認打印機是打印機,它需要去客戶端。 – Schwimms