How to send attachment of Acumatica to printer

Hello,

recently I was asked on how to send attachment to printer via device hub.

For example some entity may have attached pdf files, and you may need to send them to printer. How to achieve that? Code below demonstrates:

public PXAction<APInvoice> PrintPDF;
 
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Print PDF")]
protected void printPDF()
{
    SMPrinter printer = PXSelect<SMPrinter,
        Where<SMPrinter.printerNameEqual<Required<SMPrinter.printerName>>>>.Select(Base, "P1");//here should be name of your printer, which is known to device hub
 
    SMPrintJobMaint printJobMaint = PXGraph.CreateInstance<SMPrintJobMaint>();
 
    foreach (var fileID in PXNoteAttribute.GetFileNotes(Base.CurrentDocument.Cache, Base.CurrentDocument.Current))
    {
        var printSettings = new PrintSettings
        {
            PrintWithDeviceHub = true,
            DefinePrinterManually = true,
            PrinterID = printer.PrinterID,
            NumberOfCopies = 1
        };
 
        printJobMaint.CreatePrintJob(printSettings,
            null,
            new Dictionary<stringstring> { { "FILEID"fileID.ToString() } },
            PXMessages.LocalizeFormatNoPrefix("Print PDF {0}"fileID.ToString()));
    }
}

 

 With provided code snippet you can print to device hub pdf files. And also not only pdf files.

Add comment

Loading