douhao9203 2016-08-23 07:35
浏览 19

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 MIT控制器能控制不稳定系统吗
    • ¥15 公司代码X对业务伙伴X无效,处理方法?
    • ¥15 微信内链接跳转到浏览器打开怎么实现
    • ¥15 三角波可以直接加施密特电路整形到矩形波吗实物
    • ¥15 html,php,在使用html请求php文件时发生了错误,无法请求到php文件读取数据库并用javascript进行数据显示,刷新
    • ¥15 touchsocket udp组播
    • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
    • ¥15 VS2012中查询语句无法填入解析,数值传不进去
    • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
    • ¥15 怎么让ai定时给我发信息 c#或者python