C# Task Scheduler App in background fails to convert excel file to PDF
Posted: Wed Jun 08, 2022 4:44 pm
We have an app that we use to convert files from Excel, Word, and other extensions that have a viewer that handles the "printto" verb. We recently worked with a client on a server that when our code runs in the foreground and we convert an Excel (XLSX) file to PDF it works without issue. We then used Windows Task Scheduler to start this process in the background. When we try to convert the same Excel (XLSX) file this code below will error.
The user is the same user I am logged into in a windows session and with the Task Scheduler.
Run whether user is logged on or not
Run with highest privileges
Configure for: Windows Vista, Windows Server 2008
We are using PDFX7.exe 7.0.327.1 and PDFXCoreAPI.msi Content Created on 10/24/2018 5:11 PM Revision Number {09BDD4CB-DA8B-4FE3-8466-9DF41BD50B7B}
What can I post to debug what is happening? Should I grab a dump file? Look at DComConfig for permissions? Get the .NET Exception thrown? Is there logging available in the PDF-XChange product?
Regards,
Kevin
The user is the same user I am logged into in a windows session and with the Task Scheduler.
Run whether user is logged on or not
Run with highest privileges
Configure for: Windows Vista, Windows Server 2008
We are using PDFX7.exe 7.0.327.1 and PDFXCoreAPI.msi Content Created on 10/24/2018 5:11 PM Revision Number {09BDD4CB-DA8B-4FE3-8466-9DF41BD50B7B}
Code: Select all
Dim PDFPFactory As PXCComLib7.CPXCControlEx
Public Sub New()
PDFPFactory = New PXCComLib7.CPXCControlEx
End Sub
Private Sub InitSaverObj()
PDFPrinter = CType(PDFPFactory.Printer("", "PDF-XChange 7.0 DTPOLL", g_RegKey, ""), CPXCPrinter)
PrinterName = PDFPrinter.Name
PDFPrinter.SetAsDefaultPrinter()
End Sub
Public Sub ProcessDocument()
PDFPrinter.ResetDefaults()
PDFPrinter.Option("Save.File") = OutFileName
PDFPrinter.Option("Save.SaveType") = "Save"
PDFPrinter.Option("Save.ShowSaveDialog") = "No"
PDFPrinter.Option("Save.WhenExists") = "Overwrite"
With PDFPrinter
.Option("Compression.Graphics") = "Yes"
.Option("Compression.Text") = "Yes"
.Option("Compression.ASCII") = "No"
.Option("Compression.Color.Enabled") = "Yes"
.Option("Compression.Color.Method") = "Auto"
.Option("Compression.Indexed.Enabled") = "Yes"
.Option("Compression.Indexed.Method") = "Auto"
.Option("Compression.Mono.Enabled") = "Yes"
.Option("Compression.Mono.Method") = "Auto"
End With
PDFPrinter.Option("Fonts.EmbedAll") = 1
PDFPrinter.Option("Save.RunApp") = False
PDFPrinter.Option("Save.RunCustom") = "No"
PDFPrinter.Option("Saver.ShowProgress") = "No"
Dim procPrintto As Process = New Process
procPrintto.StartInfo.FileName = FileName
procPrintto.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
procPrintto.StartInfo.CreateNoWindow = True
procPrintto.StartInfo.Verb = "printto"
procPrintto.StartInfo.Arguments = """" + PrinterName + """"
procPrintto.StartInfo.UseShellExecute = True
procPrintto.Start()
End Sub
Regards,
Kevin