What you try to use the result it's an octet stream which sends the PDF file to your Browser to download the file. In this case you can't have an output before. Create a single file and output that PDF file without writing anything before. Then you can download the file.
That is what the error message tells you. Don't output anything before the output of the PDF file.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…