2017-01-13 39 views
0

我有一個函數可以在laravel中使用Fpdf生成pdf。 我的問題是:如何使用FPDF降低高度並下載pdf?

  1. 畢竟我有一些額外的空間。我需要刪除它。請找到下面的圖片。
  2. 如何將此pdf文件下載到我的系統中。目前它只是顯示在瀏覽器中。代碼示例如下。

代碼

控制器: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; 
    } 

路線:路線::得到( '/測試', '控制器@索引');

enter image description here

回答

0

沒有與FDPF經驗,但你可以下載這個辦法:

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

還是剛剛從你的控制器

return response()->download($pdf); 
0

保存,只需指定輸出路徑和文件名在您的輸出呼叫字符串中

Fpdf::Output([string dest [, string name [, boolean isUTF8]]]) 

儘管如此,當您構建PDF文檔時,您可以使用以下其中一種的默認大小:A3,A4,A5,Letter,Legal,A4爲默認大小。但是,您也可以聲明自定義大小。這很可能是您要查找的內容,因爲您需要使用大小來獲得您需要的空白空間。 FPDF首先放出畫布然後填充它,所以你的白色空間來自太大的畫布。這可以在構造函數或AddPage中完成,就像你所做的那樣。

通過構造:

//(L)andscape or (P)ortrait, unit type (mm millimeters), array size in mm 
$pdf = new FPDF('L','mm',array(100,150)); 

VIA AddPage(必須有可能你在找什麼): 目前您有:

Fpdf::AddPage('L', array(60,90), 'A4'); 

然而,則params應該是橫向/縱向,預定義或自定義大小的數組,然後旋轉。所以,試試這個:

Fpdf::AddPage('L', array(60,90)); 

現在,您需要與那些玩數字遊戲,更可能在90,縮短多達擺脫空白的自己。