Print a text file to a printer

You can simply make a “MoveFile” to the printer.

If you have your PrintJobSettings class filled, you can user this code:

private void printLabel()
{
    PrintJobSettings    printJobSettings;
    EmplTable           emplTable = EmplTable::find(EmplTable::userId2EmplId(curUserId()));
    InteropPermission   permission;
    ;

    permission = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();

    printJobSettings = new PrintJobSettings(emplTable.MyPrinterLabel);
    printJobSettings.fileName(fileName);
    WinAPI::moveFile(fileName, printJobSettings.printerServerName() + "\\" + printJobSettings.printerShareName());

    CodeAccessPermission::revertAssert();
}
Advertisements

Setup a printer on a table

Add on the table the EDT : PrintJobSettingsPacked.

In the form, add a new button which call this code (in clicked method) (this example is based on EmplTable)

void clicked()
{
    PrintJobSettings    printJobSettings;
    boolean             ok              = true;
    EmplTable           emplTableLoc    = EmplTable::find(EmplTable.EmplId, true);  
    ;

    super();

    printJobSettings            = new PrintJobSettings(emplTableLoc.MyPrinterLabel); 
    // open the form standard for printing
    ok                          = printJobSettings.printerSettings(formStr(SysPrintForm)); 

    if (ok) // if close ok
    {
        ttsBegin;
        // return the printjobsettings from the class
        emplTableLoc.MyPrinterLabel    = printJobSettings.packPrintJobSettings(); 
        emplTableLoc.update();
        ttsCommit;
    }

    // Refresh the form data;
    EmplTable_ds.reread();
    EmplTable_ds.refresh();
}

Print a report to PDF into a folder

From this Source

My personal code for generate a PDF from a standard report (SalesInvoice, …)

private void generatePDF()
{
    ReportRun           report;
    RecordSortedList    list        = new RecordSortedList(tableNum(MyTable));
    FileName            fileName    = "C:/test.pdf";
    PrintJobSettings    settings;
    ;

    list.ins(myTable);

    report = new ReportRun(new Args(ReportStr(MyReport)));

    report.args().caller(null);
    report.args().object(List);

    settings    = report.printJobSettings();
    settings.format(PrintFormat::PDF_EMBED_FONTS);
    settings.setTarget(PrintMedium::File);
    settings.viewerType(ReportOutputUserType::PDFEmbedFonts);
    settings.fileName(fileName);
    settings.lockDestinationProperties(true);

    report.run();
}