Catch the name of the temporary file

Hi, I am trying to generate a pdf report so I can send it later by email with automation, I am using the pdfreport from SC 9.6, the problem is that it is a “records per line” report, when I send it to a specific file it displays only one line of products in the detail.

the code I am using in the layout code, body section of the form is:

      /*------------------ Page 1 -----------------*/
        sc_pdf_print($cell_23);
        sc_pdf_print_mult($cell_24, 2.4694444444444);
        sc_pdf_print($cell_25);
		$at_path=$this->Ini->path_doc;
		$doc_name = $at_path."/OC-".[idocompra].".pdf";
		$pdf->Output($doc_name, 'F');
      /*-------------------------------------------*/

if I put this code on the header section of the code I get this message:

TCPDF ERROR: Wrong page number on setPage() function:

I hope I can get some help on this topic, thanks in advance