
Starting from April 2021 Cumulative Updates (CU), Microsoft Dynamics 365 Business Central 14.x and onward versions are now implementing server side an internal check to exclude the most common file printers such as Microsoft Print to PDF, XPS writer and Fax.
This is needed since typically these file printers do have a UI object that would request for path when called. This is not allowed server side.
Below the relevant TFS entry from e.g. version 14.x Knowledge Base article
|
387122 |
Background tasks from job queue entries run infinitely and remain in process when you print file outputs such as XPS or PDF. |
Why this could be important for your on-premises deployment?
Because if you have background sessions that perform some printing jobs these could wait forever waiting for a response from a printer that do have a file output (such as PDF or XPS ones).
Excluding these special printer server side from the server selection it will help in avoiding saturation of endless background session server side.
This issue, then, will never appear from April 2021 CU onwards.
This is not ended.
What about versions still in previous Cumulative Updates and other file printers that might be added server side?
From an application perspective, this was already uptake with Codeunit 9655 Init. Server Printer Table
Looking at the core procedure, behind the scenes, the application will populate a subset of server side printers with only the ones that do have maximumcopies > 1 and discarding all others
…
OnRun(VAR Rec : Record Printer)
InitTempPrinter(Rec);
InitTempPrinter(VAR Printer : Record Printer)
PrinterSettings := PrinterSettings.PrinterSettings;
PrinterSettingsCollection := PrinterSettings.InstalledPrinters;
FOR i := 0 TO PrinterSettingsCollection.Count - 1 DO BEGIN
PrinterName := PrinterSettingsCollection.Item(i);
PrinterSettings.PrinterName := PrinterName;
Printer.ID := COPYSTR(PrinterName,1,MAXSTRLEN(Printer.ID));
IF PrinterSettings.MaximumCopies > 1 THEN
Printer.INSERT;
END;
…
How can you see this codeunit in action?
Create or change a Job Queue Entry record to use Report and select the Printer Name dropdown. There you go! There is no Microsoft Print To PDF nor XPS nor Fax shown in there because of the aforementioned codeunit check.
For previous versions and CUs, then, you might think of subscribing to an event in the ReportManagement codeunit and check if the current client type is a background session and also not a processing only report to achieve a similar results that you have through platform since April 2021 CUs.
Below a simple code snippet to get you inspired
codeunit 50100 MyCodeunit
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterGetPrinterName', '', true, true)]
procedure OnAfterGetPrinterName(ReportID: Integer; var PrinterName: Text[250]; PrinterSelection: Record 78);
var
DotNetPrinterSettings : dotnet PrinterSettings;
DefaultPrinterName : Text;
InitServerPrinterTable : Codeunit "Init. Server Printer Table";
begin
//Check if printing through a background session and do have a layout to print
if (CurrentClientType = ClientType::Background) and
(Report.DefaultLayout(ReportID) <> DefaultLayout::None) then begin
//If PrinterName is not set, it means no PrinterSelection record hence default to server side default printer
if PrinterName <> '' then begin
DotNetPrinterSettings := DotNetPrinterSettings.PrinterSettings;
DefaultPrinterName := DotNetPrinterSettings.PrinterName;
end;
//Check if the printername is a valid printer name for server side printing otherwise it errors
InitServerPrinterTable.ValidatePrinterName(DefaultPrinterName);
end;
end;
}
dotnet
{
assembly("System.Drawing")
{
Version = '4.0.0.0';
Culture = 'neutral';
PublicKeyToken = 'b03f5f7f11d50a3a';
type("System.Drawing.Printing.PrinterSettings"; "PrinterSettings")
{
}
}
}