PDF in Binary DOMPDF Standard

Asked

Viewed 170 times

2

I have a problem in the Windows when mounting a PDF. It gives the output all in binary. I am https://github.com/barryvdh/laravel-dompdf

Look at the code:

      public function relatorio($id)
      {
        $pedidos_id = Pedidos::find($id);

        $pedidos['pedidos'] = Pedidos::select(
        'pedidos_id',
        'cliente_id',
        'pedidos.observacao',
        'pedidos.especificacoes',
        'pedidos.frete',
        'pedidos.data',
        'pedidos.numero_pedido',
        'pedidos.preco_ipi',
        'clientes.nome as nome_cliente',
        'clientes.endereco as endereco_cliente',
        'clientes.telefone as telefone_cliente',
        'clientes.email as email_cliente',
        'clientes.uf as estado_cliente',
        'fornecedores.nome as nome_fornecedor',
        'pedidos.total_m2',
        'pedidos.total_m3',
        'pedidos.total'
        )
        ->join('clientes','clientes_id', '=', 'cliente_id')
        ->join('fornecedores','fornecedores_id', '=', 'fornecedor_id')
        ->orderBy('pedidos.data')
        ->where('pedidos_id',$pedidos_id)->get();
        // dados do pedido
        if(!$pedidos)
        {
        return response()->json([
        'message'   => 'Nenhum pedido encontrado',
      ], 404);
    }

  $pdf = PDF::loadView('pedidos', $pedidos);
  return $pdf->download('relatorio.pdf');
  }

EXIT

inserir a descrição da imagem aqui

  • Actually this is the pdf even if you open it in the notepad for example, but have tried using the $pdf->stream(); to see what comes out instead of the download? Your view requests exists and is correct?

  • Is it not the route that is wrong? It looks like this: Route::get('return_report/{pedidos_id}','Pedidoscontroller@report');

  • It shouldn’t, if it was on the route the page wouldn’t load, but try to leave the route like this and use the stream to test, what you can also try is to post instead of get. The pdf load is being done, it’s just not downloading (this may be because of get, but I’m not sure, I would have to test)

  • Where exactly is this route called? the problem is before!

  • @Virgilionovic did the report but it comes out php programming. see image above

  • So it has extra code (not required) $pedidos_id = Pedidos::find($id); this line for example draws off no need, can already bring the data only with the bottom if return blz if there are no problems somewhere, your route has the variable pedidos_id, then the method formula follows the same name relatorio($pedidos_id), try these changes

Show 1 more comment

1 answer

0

Exchange $pdf->download(); for $pdf->stream(); while the error occurs so you don’t need to download the file each time this occurs.

Make sure that the $requests variable you are passing to the view is coming in correctly, as the view is not understanding the data you passed, possibly the error is when you pass $controller requests to the view.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.