2017-12-20 1 views
2

PDF 작성을 좀 더 명확하게하기 위해 다음과 같이 미리 정의 된 기능 세트 인 Factory/Abstract 클래스를 작성해야합니다.

class AbstractPDF{ 

    protected $pdf; 
    protected $searchpath; 

    public function __construct(){ 

     $this->pdf = PDF_new(); 
     $this->searchpath = "fonts/"; 

     pdf_set_option($this->pdf,"errorpolicy=return"); 

     pdf_set_option($this->pdf,"searchpath={" . $this->searchpath . "}"); 

     pdf_set_option($this->pdf,"stringformat=utf8"); 

    } 

    protected function startAFourPage(){ 

     pdf_begin_page_ext($this->pdf, 0, 0, "width=a4.width height=a4.height"); 
       } 



    /* When setting up any of the PDF content types, one should */ 
    /* remember that in PDFLib, x=>y axis start with 0(zero) at */ 
    /* lower left corner.          */ 
    /* The text line is set up in space by setting up the  */ 
    /* coordinates of the lower left corner and then providing */ 
    /* height and width of the object as separate values  */ 



protected function setupTextLine($xcoordinate, $ycoordinate, $width, $height, 
         $fontName, $fontEncoding, $fontSize, $text, $textPosition = "left"){ 

     //adding text directly through the PDFLib documentation 
     $font = PDF_load_font($this->pdf, $fontName, $fontEncoding, ""); 
     PDF_setfont($this->pdf, $font, $fontSize); 
     //PDF_set_text_pos($this->pdf, 25, 650); 
     //PDF_show($this->pdf, $text); 
     PDF_fit_textline ($this->pdf, $text, 111, 744, "boxsize {".$width." ".$height."} position=left"); 

    } 


    /* When setting up any of the PDF content types, one should */ 
    /* remember that in PDFLib, x=>y axis start with 0(zero) at */ 
    /* lower left corner.          */ 
    /* The text flow is set up by providing the coordinate for */ 
    /* lower left corner and upper right, as a rule.   */ 
    /* But overall PDFLib will placed it by coordinates for  */ 
    /* two corners diagonal to each other.      */ 
    /* For this class we will identify these corners as   */ 
    /* lowLeft and upperRight         */ 


protected function setupMultilineTextflow($lowLeftX, $lowLeftY, $upperRightX, $upperRightY, 
         $fontName, $fontEncoding, $fontSize, $text){ 

     $orderDetails = 'Datum: 
     Auftrags-NR: 
     Auftragsname: 
     Kunden-Nr:'; 

     $textFlow = PDF_create_textflow($this->pdf, $text, 
        "fontname=".$fontName." 
        fontsize=".$fontSize." 
        encoding=".$fontEncoding); 
     PDF_fit_textflow($this->pdf, $textFlow3, $lowLeftX, $lowLeftY, $upperRightX, $upperRightY,""); 

    } 

    protected function setupTable($headers=array('test'=>''), array $field){   
       } 

} 
?> 

이 클래스는 다음

class PDF extends AbstractPDF{ 

    public function __construct(){ 

     parent::__construct(); 

     parent::startAFourPage(); 

    } 

    public function generateContent(){ 

     return ""; 

    } 


} 
내가 너무 많은 코드를 가진 사과

에서 호출하지만 전체 그림을 그려 싶어한다.

2017/12/19 18:47:58 [error] 465#465: *252 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDFlibException: Function must not be called in 'object' scope in/var/www/dev-vm-stretch.de/htdocs/AbstractPDF.php:30

Stack trace:

#0 /var/www/dev-vm-stretch.de/htdocs/AbstractPDF.php(30): pdf_begin_page_ext(Resource id #1, 0, 0, 'width=a4.width ...')

#1 /var/www/dev-vm-stretch.de/htdocs/PDF.php(10): AbstractPDF->startAFourPage()

#2 /var/www/dev-vm-stretch.de/htdocs/index.php(18): PDF->__construct()

#3 {main}

thrown in /var/www/dev-vm-stretch.de/htdocs/AbstractPDF.php on line 30" while reading response header from upstream, client: 192.168.34.51, server: dev-vm-stretch.de, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "dev-vm-stretch.de"

나는 기능에 PDFLib 관련 코드를 분리 때문이라고 생각하지만은 100 % 확실하지 않다 :

문제는 내가이 다음과 같은 오류가 이러한 클래스를 호출 할 때이다 내 PDFLib 경험 5 일 후 약간 더 제한되며이 오류가 환영 고정 할 수있는 방법에

어떤 아이디어 :-(문제 이런 종류의 처리하는 어떤 PDFLib 자습서를 발견하지 않았습니다.

답변

0

문제는 간단합니다. 출력 문서가있을 때 페이지. begin_document($file, $options);으로 새 출력 문서를 만들 수 있습니다. __construct도 마찬가지입니다.

PDFlib 9.1.1 API 참조, 1.2 장 "기능 범위"를 확인할 수 있습니다. 또한 모든 PDFlib PHP 샘플 (PDFlib PHP 패키지 포함)은 올바른 사용법을 보여줍니다.

+0

필자는 실제로 테스트를 위해 그리고 테스트를 위해 다양한 파일을 가져 오는 테스트 파일에서 그 라인을 가지고있었습니다 ... 그리고 나는 절대적으로 그것을 놓쳤습니다 :-( –

관련 문제