Как выполнить пакетную печать файлов XPS в Microsoft Print в PDF без запроса имени файла?
У меня много файлов dwfx, которые открываются с помощью средства просмотра XPS. Я хочу распечатать их как PDF-файл, я попытался использовать приведенный ниже код и выбрать "Microsoft Print to PDF" в качестве принтера по умолчанию, но он каждый раз запрашивает имя файла. Может быть, есть другой способ. Что я могу сделать? Благодаря,
Imports System.IO
Imports System.Printing
Imports System.Threading
Imports System.Windows.Xps
<System.MTAThreadAttribute()>
Public Shared Sub Main(ByVal args As String())
Dim printingThread As Thread = New Thread(AddressOf PrintXPS)
printingThread.SetApartmentState(ApartmentState.STA)
printingThread.Start()
End Sub
Public Shared Sub PrintXPS()
Dim localPrintServer As LocalPrintServer = New LocalPrintServer()
Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()
'Dim ps As LocalPrintServer = New LocalPrintServer()
'Dim pq As PrintQueue = ps.DefaultPrintQueue
'Dim xpsdw As XpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(pq)
'Console.Write("Enter the directory containing the XPS files: ")
Dim directoryPath As String = "write you folder here"
Dim dir As DirectoryInfo = New DirectoryInfo(directoryPath)
If Not dir.Exists Then
Console.WriteLine("There is no such directory.")
Else
If dir.GetFiles("*.dwfx").Length = 0 Then
Console.WriteLine("There are no XPS files in the directory.")
Else
Console.WriteLine(vbLf & "Jobs will now be added to the print queue.")
Console.WriteLine("If the queue is not paused and the printer is working, jobs will begin printing.")
For Each f As FileInfo In dir.GetFiles("*.dwfx")
Dim nextFile As String = directoryPath & "\" + f.Name
Console.WriteLine("Adding {0} to queue.", nextFile)
Try
Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob(f.Name, nextFile, False)
Catch e As PrintJobException
Console.WriteLine(vbLf & vbTab & "{0} could not be added to the print queue.", f.Name)
If e.InnerException.Message = "File contains corrupted data." Then
Console.WriteLine(vbTab & "It is not a valid XPS file. Use the isXPS Conformance Tool to debug it.")
End If
Console.WriteLine(vbTab & "Continuing with next XPS file." & vbLf)
End Try
Next
End If
End If
Console.WriteLine("Press Enter to end program.")
Console.ReadLine()
End Sub