我可以使用VB.Net在按钮点击事件上打印PDF。但我想要的是只打印我的PDF的第二页。 请帮忙我该怎么做。
Dim MyProcess As New Process
MyProcess.StartInfo.CreateNoWindow = False
MyProcess.StartInfo.Verb = "print"
MyProcess.StartInfo.FileName = "D:\765.pdf"
MyProcess.Start()
MyProcess.WaitForExit(10000)
MyProcess.CloseMainWindow()
MyProcess.Close()

答案 0 :(得分:0)
以下是我用于提取从现有PDF打印所需的页数
的功能
Private Shared Sub ExtractPages(inputFile As String, outputFile As String, start As Integer, [end] As Integer)
' get input document
Dim inputPdf As New PdfReader(inputFile)
' retrieve the total number of pages
Dim pageCount As Integer = inputPdf.NumberOfPages
If [end] < start OrElse [end] > pageCount Then
[end] = pageCount
End If
' load the input document
Dim inputDoc As New Document(inputPdf.GetPageSizeWithRotation(1))
' create the filestream
Using fs As New FileStream(outputFile, FileMode.Create)
' create the output writer
Dim outputWriter As PdfWriter = PdfWriter.GetInstance(inputDoc, fs)
inputDoc.Open()
Dim cb1 As PdfContentByte = outputWriter.DirectContent
' copy pages from input to output document
For i As Integer = start To [end]
inputDoc.SetPageSize(inputPdf.GetPageSizeWithRotation(i))
inputDoc.NewPage()
Dim page As PdfImportedPage = outputWriter.GetImportedPage(inputPdf, i)
Dim rotation As Integer = inputPdf.GetPageRotation(i)
If rotation = 90 OrElse rotation = 270 Then
cb1.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, _
inputPdf.GetPageSizeWithRotation(i).Height)
Else
cb1.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, _
0)
End If
Next
inputDoc.Close()
End Using
&#13;