2014-11-26 2 views
0

fpdf를 사용하여 pdf에 텍스트를 추가합니다. 텍스트를 추가 할 수 있지만 pdf 페이지의 크기는 항상 A4입니다. 업로드 된 pdf 방향이 가로 방향 인 경우 세로로 표시됩니다. pdf에 writting하기위한 업로드 된 pdf의 widht와 height 및 orientation을 사용하고 싶습니다.fpdf 설정 높이와 방향을 자동으로

$fullPathToFile = $target_path; 

    class custom_PDF extends FPDI { 

    var $_tplIdx; 
    var $file; 

    function Header() { 
     if (is_null($this->_tplIdx)) { 
     // THIS IS WHERE YOU GET THE NUMBER OF PAGES 
     $this->numPages = $this->setSourceFile($this->file); 
     $this->_tplIdx = $this->importPage(1); 
     } 
     $this->useTemplate($this->_tplIdx, 0, 0, 200); 
    } 

    function Footer() { 

    } 

    function setFile($param) { 
     $this->file = $param; 
    } 

    } 
    $pdf234 = new custom_PDF(); 
    $pdf234->setFile($fullPathToFile); 
    $pdf234->AddPage(); 
    $pdf234->SetAutoPageBreak(TRUE, 0); 
    $pdf234->SetY(280); 
    $pdf234->SetFont("helvetica", "B", 8); 
    $pdf234->SetTextColor(0, 0, 0); 


    $utf8text = $current_user->user_login . "(" . str_ireplace('_', ' ', $current_user->roles[0]) . ")," . get_bloginfo('name') . "," . get_bloginfo('url') . "" . date("d M Y,h:i:s a"); 
    $pdf234->Write(5, $utf8text, get_bloginfo('url')); 
    if ($pdf234->numPages > 1) { 
    for ($i = 2; $i <= $pdf234->numPages; $i++) { 
     //$pdf->endPage(); 
     $pdf234->_tplIdx = $pdf234->importPage($i); 
     $pdf234->AddPage(); 
      $pdf234->SetAutoPageBreak(TRUE, 0); 
     $pdf234->SetY(280); 

     $pdf234->Write(5, $utf8text, get_bloginfo('url')); 
    } 
    } 
    $pdf234->Output($line['name'], 'D'); 
    die(); 

다음 코드도 시도 : 이제 가로 모드하지만 내용의 전체 page.content을 점유하지 않는에서

$specs = $pdf234->getTemplateSize($pdf234->_tplIdx); 
$pdf234->AddPage('L',$specs); 

내 PDF가 왼쪽 상단에 정렬됩니다.

답변

0

업로드 된 pdf dimension을 감지하는 방법을 찾았습니다. getTemplateSize() 함수를 사용하여 레이아웃을 만드는 데 너비와 높이를 가져 왔습니다. 다음은 내 코드입니다 :

$fullPathToFile = $target_path; 

    class custom_PDF extends AlphaPDF { 

    var $_tplIdx; 
    var $file; 

    function Header() { 
     if (is_null($this->_tplIdx)) { 
     // THIS IS WHERE YOU GET THE NUMBER OF PAGES 
     $this->numPages = $this->setSourceFile($this->file); 
     $this->_tplIdx = $this->importPage(1); 
     } 
     $this->useTemplate($this->_tplIdx, 0, 0); 
    } 

    function Footer() { 

    } 

    function setFile($param) { 
     $this->file = $param; 
    } 

    function RotatedText($x, $y, $txt, $angle) { 
     //Text rotated around its origin 
     $this->Rotate($angle, $x, $y); 
     $this->Text($x, $y, $txt); 
     $this->Rotate(0); 
    } 

    } 

    $pdf234 = new custom_PDF(); 
    $pdf2345 = new custom_PDF(); //detect size of uploaded pdf 
    $pdf234->setFile($fullPathToFile); 
    $pdf2345->setFile($fullPathToFile); 
    $pdf2345->AddPage(); 
    $specs = $pdf2345->getTemplateSize($pdf2345->_tplIdx); 
    if ($specs['w'] > $specs['h']) { 
    $pdf234->AddPage('L', array($specs['w'], $specs['h'])); 
    } else { 
    $pdf234->AddPage(); 
    } 
    $pdf234->SetAutoPageBreak(TRUE, 0); 
    $pdf234->SetAlpha(0.7); 
    $pdf234->SetFont('courier', '', 10); 
    $pdf234->SetTextColor(0, 0, 0); 
    $pdf234->SetDisplayMode('fullpage'); 
    $utf8text1 = $current_user->user_login . "(" . str_ireplace('_', ' ', $current_user->roles[0]) . ")," . get_bloginfo('name') . "," . get_bloginfo('url'); 
    $utf8text2 = date("d M Y,h:i:s a") . "," . $current_user->data->user_email; 
    $pdf234->SetFont('helvetica', '', 13); 
    $pdf234->SetTextColor(128, 128, 128); 
    if ($specs['w'] > $specs['h']) { 

    $pdf234->RotatedText(($specs['w']/2) - 50, ($specs['h']/2) + 45, $utf8text1, 40); 
    $pdf234->RotatedText(($specs['w']/2) - 40, ($specs['h']/2) + 45, $utf8text2, 40); 
    } else { 
    $pdf234->RotatedText(45, 180, $utf8text1, 40); 
    $pdf234->RotatedText(55, 180, $utf8text2, 40); 
    } 
    if ($pdf234->numPages > 1) { 
    for ($i = 2; $i <= $pdf234->numPages; $i++) { 
     //$pdf->endPage(); 
     $pdf234->_tplIdx = $pdf234->importPage($i); 
     $pdf234->AddPage(); 
     $pdf234->SetAutoPageBreak(TRUE, 0); 
     $pdf234->SetY(280); 
     $pdf234->SetAlpha(0.7); 
     $pdf234->SetFont('helvetica', '', 13); 
     $pdf234->SetTextColor(128, 128, 128); 
     $pdf234->RotatedText(45, 180, $utf8text1, 40); 
     $pdf234->RotatedText(55, 180, $utf8text2, 40); 
    } 
    } 
    $pdf234->Output($line['name'], 'D'); 
    die(); 
0

당신은 생성자에서 크기를 설정할 수 있습니다

FPDF([string orientation [, string unit [, mixed size]]]) 

:

$pagesize = array(107, 199); 
$pdf234 = new FPDF('P', 'mm', $pagesize); 

이나와 :

AddPage([string orientation [, mixed size]]); 

예 :

$pdf234->AddPage('P','A5'); 

설명

문서에 새 페이지를 추가합니다.

매개 변수

방향을

페이지 방향입니다. 기본값은 생성자에 전달 된 하나입니다

  • P 또는 세로
  • L 또는 가로

: 가능한 값 (대소 문자 구분)입니다.

크기

페이지 크기. 그것은 (대소 문자 구분) 다음 값 중 하나가 될 수

  • A4를

    • A3
    • A5
    • 문자
    • 법적

    또는 폭을 포함하는 배열 및 높이 (사용자 단위로 표시)

    기본값은 생성자에 전달되는 값입니다.

  • +0

    '$ 사양 = $ pdf234-> getTemplateSize ($의 pdf234 -> _ tplIdx); $ pdf234-> AddPage ('L', $ specs); ' 내 PDF는 가로 모드로 표시되지만 콘텐츠는 전체 페이지를 차지하지 않습니다. 콘텐츠가 왼쪽 상단에 정렬됩니다. – Kavita

    관련 문제