generate sales invoice report through code and save as pdf file in file system

Hi,

I have written the following code to generate a sales invoice report and save as a pdf file in the file system. But this code is not saving the report as pdf instead it is displaying the report on the screen. Please correct this code.

CustInvoiceJour InvJTbl;
SalesId Id;
ReportRun report;
SalesFormLetter_Invoice SalesFormLetter = new SalesFormLetter_Invoice(false);
RecordSortedList List = new RecordSortedList(62);

Id = “SO-0000123”;

Select InvJTbl Where InvJTbl.SalesId == Id;
List.ins(InvJTbl);
report = new ReportRun(new Args(ReportStr(SalesInvoice)));
report.args().caller(SalesFormLetter);
report.args().parmEnum(1);
report.args().parmEnumType(920);
report.args().object(List);
report.args().name(“KeepSettings”);
report.printJobSettings().setTarget(PrintMedium::File);
report.printJobSettings().format(PrintFormat::PDF);
report.printJobSettings().fileName(“C:\Temp\Test.pdf”);
report.prompt();
SalesFormLetter.updatePrinterSettingsFormLetter(report.packPrintJobSettings());
report.run();

Follow the following steps:

http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report_23.html