I've done this and it work great , but is using the System.Printing library.
using (PrintServer ps = new PrintServer())
{
using (PrintQueue pq = new PrintQueue(ps, printerName, PrintSystemDesiredAccess.AdministratePrinter))
{
pq.Purge();
}
}
I need to use PrintQueueWatch library, here is where the function Job.Transfer is
using (PrinterQueueWatch.PrinterInformation PrinterInfo = new PrinterQueueWatch.PrinterInformation("HP LaserJet P1006", PrinterQueueWatch.SpoolerApiConstantEnumerations.PrinterAccessRights.SERVER_ALL_ACCESS, true))
{
PrinterInfo.PrintJobs.get_ItemByJobId(Id).Transfer("Microsoft Print to PDF", false);
}
I even trie the diferent options of PrinterQueueWatch.SpoolerApiConstantEnumerations.PrinterAccessRights and the result is the same
access denied.
Abhishek YadavPosted Aug 10, 2024, 4:42 AM
Regarding the issue with the
PrinterQueueWatchlibrary and the "access denied" error when trying to transfer print jobs, here are a few suggestions:Ensure Proper Permissions: Make sure that the user account running the application has sufficient permissions to manage print jobs and access the printer. You might need to grant administrative rights or ensure that the application is running with elevated privileges.
Verify Printer Name and Access Rights: Double-check that the printer name specified in
PrinterQueueWatch.PrinterInformationis correct and that the access rights you’re using match the required permissions for the operation.Check for Printer Status: Ensure that the printer is online and properly configured to accept print jobs. Sometimes, printers that are offline or have configuration issues can cause access errors.
Here’s a modified snippet that includes error handling which might help diagnose the issue:
If this resolves the issue, please accept my response to close the thread. If the problem persists, feel free to provide more details, and I’d be happy to assist further.
Jorge Carlos Iglesias AlvarezPosted Aug 12, 2024, 3:26 AM
Thanks for your answer.
I checked the following things and still the function Job.Transfer dosen't work
1.- Permissions.
The user account running the application belong to the administrator group and has sufficient permissions on both printer.
Has permissions for print job, manage documents and manage printer.
2.- I create a instance of PrintQueeuWatch.PrinterInformation
PrinterQueueWatch.PrinterInformation PrinterInfo = new PrinterQueueWatch.PrinterInformation("HP LaserJet P1006", PrinterQueueWatch.SpoolerApiConstantEnumerations.PrinterAccessRights.Printer_Access_Administer, true))
3.- The two printers status is online
4.- In the app.manifest is configured with higestAvailable
try
{
using (PrinterQueueWatch.PrinterInformation PrinterInfo = new PrinterQueueWatch.PrinterInformation("HP LaserJet P1006", PrinterQueueWatch.SpoolerApiConstantEnumerations.PrinterAccessRights.Printer_Access_Administer, true))
{
var job = PrinterInfo.PrintJobs.get_ItemByJobId(Id); //the value of job is not null.
if (job != null)
{
job.Transfer("Microsoft Print to PDF", false);
}
else
{
System.Diagnostics.Debug.WriteLine("Print job not found.");
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);
}