Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel软件包html到pdf_Php_Html_Laravel_Pdf_Type Conversion - Fatal编程技术网

Php Laravel软件包html到pdf

Php Laravel软件包html到pdf,php,html,laravel,pdf,type-conversion,Php,Html,Laravel,Pdf,Type Conversion,我使用以下软件包将html转换为pdf: 但是当我用这个的时候,它一点都不好看。这是我的原始html pdf: 当我转换它时,它看起来像这样: 我做错什么了吗 编辑: 这个laravel软件包似乎使用了DOMPDF,这很好 考虑到我看不到您的代码,我将与您分享为我工作的PHP代码: // This should be your normal HTML page $url = 'http://www.website.com/invoice'; $html = file_get_content

我使用以下软件包将html转换为pdf:

但是当我用这个的时候,它一点都不好看。这是我的原始html pdf:

当我转换它时,它看起来像这样:

我做错什么了吗

编辑:


这个laravel软件包似乎使用了DOMPDF,这很好

考虑到我看不到您的代码,我将与您分享为我工作的PHP代码:

// This should be your normal HTML page
$url = 'http://www.website.com/invoice';
$html = file_get_contents($url);

// First. Convert all relative image paths to file system paths.
// Test that the generated path is where your images files are located
$html = str_replace("/images", public_path()."/images", $html);

// Generate PDF file
$dompdf = new DOMPDF();
$dompdf->set_paper("A4", "portrait");
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream('your_invoice_file.pdf');
如果还希望将Laravel视图直接渲染为PDF,请将前两行代码替换为这一行

// Just render the view normally
$html = View::make('path/view');
根据您添加的代码选择其他选项

$html = view('administration.invoice')->render();
$html = str_replace("/images", public_path()."/images", $html);
return $this->pdf->load($html)->download();

记得将images文件夹设置为您拥有的文件夹。

hmm您可以发布控制器代码吗?代码很好,只需添加一行代码,将您的相对图像路径转换为我在回答中给出的文件系统路径。您应该在视图呈现之后插入它。您已经让它工作了,但是DOMPDF找不到用于呈现HTML的文件。因此,图像和CSS文件必须转换为本地系统路径。如何将其与view.blade结合?那么,不是在laravel中使用视图来使用url?
$html = view('administration.invoice')->render();
$html = str_replace("/images", public_path()."/images", $html);
return $this->pdf->load($html)->download();