dompdf创建有缺陷的PDF

I want to create a pdf-file with dompdf pressing a button. Without the button all work fine, but as soon as I put the working php code in a if query to execute the dompdf-code the created pdf file is defective. I am using dompdf 0.6.2 and this is my code.

<form method="post" >
    <p><input type="submit" name="mein_button" value="PDF erstellen" /></p> 
</form>
<?php
if(isset($_POST['mein_button']))
{   
    require_once("pdf/dompdf/dompdf_config.inc.php");
    spl_autoload_register('DOMPDF_autoload');
    function pdf_create($html, $filename, $paper, $orientation, $stream=TRUE) 
    {
        $dompdf = new DOMPDF();
        $dompdf->set_paper($paper, $orientation);
        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream($filename.".pdf");
    } 
    $filename = 'file_name';
    $dompdf = new DOMPDF();
    $html = '<html><body>'.
            "<h1>PDF erstellen</h1>". 
            "<p>test test test</p>".
            '</body></html>';
    pdf_create($html, $filename, 'A4', 'portait');
}
?>

This code creates a a defective pdf-file. If I use only the code in the if query, the pdf file is ok.

I have not learned php, so I hope somebody can help me, because I can not find a solution.