Aspose.Pdf.Facades.PdfViewer.PrintLargePdf(inputStream As Stream, printerSettings As PrinterSettings) is failing from windows container and getting error “Settings to access printer ‘Microsoft Print to PDF’ are not valid.”
Can you please share the sample code snippet along with the sample PDF document for our reference? We will test the scenario in our environment and address it accordingly.
Please find below the sample code. Attached the sample document used. If the file is not openng for you, you could use your own pdf file and modify the code accordingly.
Note: It is not working from Windows container (Docker)
Imports System.IO
Imports Aspose.Pdf
Imports Aspose.Pdf.Facades
Module Module1
Sub Main()
' Specify the path to your large PDF file
Dim pdfFilePath As String = "C:\app\dummy.Pdf"
' Create an instance of PdfViewer
Dim pdfViewer As New PdfViewer()
Try
'test'
Dim pdfFile As String = "C:\app\dummy.Pdf"
' Load the PDF document
Dim pdfDocument As New Document(pdfFile)
' Create a MemoryStream to hold the PDF content
Dim memoryStream As New MemoryStream()
' Save the PDF document to the MemoryStream
pdfDocument.Save(memoryStream)
' Optionally, you can use the MemoryStream as needed
' For example, you can write it to a file or send it as a response in a web application
' Reset the position of the MemoryStream to the beginning
memoryStream.Position = 0
' Example: Writing the MemoryStream to a file
Console.WriteLine("Before outputfilepath.")
Dim outputFilePath As String = "C:\app\dummy.Pdf"
Using fileStream1 As New FileStream(outputFilePath, FileMode.Create)
memoryStream.CopyTo(fileStream1)
End Using
'Test'
' Open the PDF file
pdfViewer.BindPdf(pdfFilePath)
Console.WriteLine("Before PrinterSettings.")
' Set the printer settings
Dim printerSettings As New System.Drawing.Printing.PrinterSettings()
Console.WriteLine("Before PrinterName assignment.")
printerSettings.PrinterName = "Microsoft Print to PDF"
printerSettings.PrintToFile = True
' You can customize printer settings here if needed
' Print the PDF document
Console.WriteLine("Before pdfViewer PrintLargePdf.")
pdfViewer.PrintLargePdf(memoryStream, printerSettings)
Console.WriteLine("PDF document printed successfully.")
Catch ex As Exception
Console.WriteLine("Error: " & ex.Message)
Finally
' Close the PdfViewer
pdfViewer.Close()
End Try
End Sub
End Module
dummy.pdf (13.0 KB)
We are sorry for the trouble. Can you please share the sample docker file as well OR its content with us? It would help us in investigating the scenario accordingly.
Please find below the content of DockerFile:
FROM mcr.microsoft.com/windows:1809
WORKDIR /app
COPY . .
EXPOSE 80
CMD [“AsposePrintWorkflow.exe”]
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-56159
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
We investigated the ticket. The described problem is related to the Windows container image itself, and not to our library.
Please try all the steps described in Print spooler in Windows containers | Microsoft Learn and Printers don't work inside container · Issue #187 · microsoft/Windows-Containers · GitHub
If nothing helps, you might need to report the problem to Microsoft in an appropriate GitHub repository Issues page: Issues · microsoft/Windows-Containers · GitHub
Thanks for the update.