douluanji8752 2017-01-13 15:08
浏览 69

如何降低高度并使用FPDF下载pdf?

I have a function to generate pdf using Fpdf in laravel. My problems are:

  1. After all Cell I have some extra space. I need to remove that. Please find the image given below.
  2. How can I download this pdf file in to my system. Currently it's just showing in to browser. Code samples are given below.

Code

Controller: Controller.php

public function index()
    {
        $orders = Order::select('firstname', 'lastname', 'street', 'postal', 'country')->get();
        foreach ($orders as $order){
            Fpdf::SetMargins(5, 5, 5);
            Fpdf::AddPage('L', array(60,90), 'A4');
            Fpdf::SetAutoPageBreak(TRUE, 0);
            Fpdf::SetFont('helvetica', '', 7); //IF bold letter SetFont('Arial','B',14)
            Fpdf::SetTextColor(0, 0, 0);
            Fpdf::Cell(10,5,iconv('UTF-8', 'windows-1252', 'Falls unzustellbar, zurück an Absender'),0,"1","L");
            Fpdf::SetFont('','U');
            Fpdf::Cell(10,5,iconv('UTF-8', 'windows-1252', 'schrillALARM.jetzt c/o 365group • Grasgasse 2 • 93047 Regensburg'),0,"1","L");
            Fpdf::SetFont('helvetica', '', 11);
            Fpdf::Cell(10,5,$order->firstname,0,1,"L");
            Fpdf::Cell(10,5,$order->lastname,0,1,"L");
            Fpdf::Cell(10,5,$order->street,0,1,"L");
            Fpdf::Cell(10,5,$order->postal,0,1,"L");
            Fpdf::Cell(10,5,$order->country,0,1,"L");
        }
        Fpdf::Output();
        exit;
    }

Route: Route::get('/test', 'Controller@index');

enter image description here

  • 写回答

2条回答 默认 最新

  • duanpu1111 2017-01-13 15:17
    关注

    No experience with FDPF, but you can download this way:

    Route::get(
        'download/pdf/{pdf}',
        function ($pdf) {
            $file = // Get file
            return response()->download($file);
        }
    );
    

    Or just from your controller with

    return response()->download($pdf);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算