pageextension 50101 "ProdOrderExt" extends "Released Production Order"
{
    actions
    {
        addlast(Processing)
        {
            action(PrintJobCard)
            {
                Caption = 'Print Job Card';
                Image = Print;
                trigger OnAction()
                var
                    ProdOrderRec: Record "Production Order";
                    JobCardReport: Report "Prod. Order - Job Card";
                    OutputFile: File;
                    OutputFilePath: Text;
                    TempBlob: Codeunit "Temp Blob";
                    OutStream: OutStream;
                begin
                    // Call original behavior
                    CurrPage.Update(); // Simulate Refresh action or use page action if needed
 
                    // Get the current Production Order
                    Rec.TestField("No.");
                    ProdOrderRec.Get(Rec."No.");
 
                    // Prepare to save report to PDF
                    TempBlob.CreateOutStream(OutStream);
                    // Use a filter string as the second argument
                    Report.SaveAs(Report::"Prod. Order - Job Card", 'No.=' + Rec."No.", ReportFormat::Pdf, OutStream);
 
                    // Save to file system or stream to download — for now, simulate download
                    OutputFilePath := 'JobCard_' + Rec."No." + '.pdf';
 
                    // Create an InStream from the TempBlob and download the file
                    TempBlob.CreateInStream(InStr);
                    DownloadFromStream(InStr, 'Job Card', 'PDF Files|*.pdf', '', OutputFilePath);
                end;
            }
        }
    }
    var
        InStr: InStream;
}