测试了一下pdf的静默打印太麻烦,换一种方式打印,只需要引用一下 iTextSharp.dll
Dim reader As New iTextSharp.text.pdf.PdfReader("d:\test.pdf")
Dim document As New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
Dim n As Integer = reader.NumberOfPages
Dim baos As New IO.FileStream("d:\temp.pdf", IO.FileMode.Create, IO.FileAccess.Write)
Dim copy As New iTextSharp.text.pdf.PdfCopy(document, baos)
copy.ViewerPreferences = iTextSharp.text.pdf.PdfWriter.HideToolbar Or iTextSharp.text.pdf.PdfWriter.HideMenubar Or iTextSharp.text.pdf.PdfWriter.HideWindowUI
'往pdf中写入内容
document.Open()
For i As Integer = 1 To n
Dim page As iTextSharp.text.pdf.PdfImportedPage = copy.GetImportedPage(reader, i)
copy.AddPage(page)
Next
document.Close()
reader.Close()
Dim pd As new Printing.PrintDocument()
Dim p As new Process()
Dim startInfo As new System.Diagnostics.ProcessStartInfo()
startInfo.CreateNoWindow = True
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
startInfo.UseShellExecute = True
startInfo.FileName = "d:\temp.pdf"
startInfo.Verb = "print"
'startInfo.Arguments = "/p /h \" + startInfo.FileName + """""" + pd.PrinterSettings.PrinterName + """"
p.StartInfo = startInfo
p.Start()