Langsung ke konten utama

Create PDF from SSRS Form

Hi, i want to share code to create and save from SSRS Report



I created a new Button, so after user selects data and clicks the button, system creates a PDF file and saves it to the destination folder.



public static void main(Args _args)
{
    PurchTable                      purchTable,purchTable2, row;
    PurchPurchaseOrderContract      purchPurchaseOrderContract;

    VendPurchOrderJour              vendPurchOrderJour;
    FormDataSource                  purchTable_ds;
    SRSPrintDestinationSettings     settings;
    SrsReportRunController          controller ;

    str                             folderPath;
    dialog                          d;

    DialogField                     dialogFilename;

    str                             PDFName, FilePath;
    int                             tot = 0;

    Args                            args;
    ReportName                      reportName = "PurchPurchaseOrder.Report";

    PurchTable                      _PurchTable;
    MultiSelectionHelper            _helper = MultiSelectionHelper::construct();
    ;


    d = new dialog();
    d.caption("select a folder");
    dialogFilename = d.addField(extendedTypeStr(FilePath));//add a field where you select your file in a specific path
    d.run();

    if(d.closedOk())
    {
        folderPath = dialogFileName.value();//return path file value

         if(folderPath == '')
        {
            folderPath = 'C:\\SharePdf';
        }


       if(_args.record().TableId == tableNum(PurchTable))
       {
            purchTable2 = _args.record();
            purchTable_ds = purchTable2.dataSource();
       }


    if (purchTable_ds.anyMarked())
    {
        row   = purchTable_ds.getFirst( 1, false );

        while(row)
        {
            tot++;

            args = new Args();

            select firstFast purchTable where purchTable.RecId == row.RecId ;

            select firstFast vendPurchOrderJour where vendPurchOrderJour.PurchId == purchTable.PurchId  ;

            PDFName = strFmt("%2\\%1.pdf",strReplace(purchTable.PurchId,'/','_'), folderPath);

           controller = new SrsReportRunController();
           purchPurchaseOrderContract = new PurchPurchaseOrderContract();

           controller.parmReportName(ReportName);
           controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
           controller.parmShowDialog(false);

           purchPurchaseOrderContract.parmRecordId(vendPurchOrderJour.RecId);

           args.record(row);

           controller.parmReportContract().parmRdpContract(purchPurchaseOrderContract);
           controller.parmArgs(args);

           settings = controller.parmReportContract().parmPrintSettings();
           settings.printMediumType(SRSPrintMediumType::File);
           settings.fileFormat(SRSReportFileFormat::PDF);
           settings.overwriteFile(true);
           settings.fileName(PDFName);

           controller.startOperation();

           row = purchTable_ds.getNext();
        }

    }

    info(strFmt("%1 Total",tot));

    }

}

Komentar