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();
}