2010-04-06 4 views
0

다음 코드를 작성했습니다. 볼 수 있듯이 일부 값을 거쳐 생성 된 pdf에 표시하는 for 루프가 있습니다. 문제는 모든 값이 같은 위치에 쓰여지고 있다는 것입니다. 새 줄을 삽입하려고했지만 작동하지 않는 것 같습니다. 아무도 내가 그것을 할 수있는 방법을 제안 할 수 있습니까? 다른 y 위치의 값이되도록 중첩 for 루프를 작성해야합니까?값을 반복하고 PDF 파일로 표시

$pdf = pdf_new(); 

      // open a file 
      pdf_open_file($pdf, "C:/xampp/htdocs/final/6.pdf"); 
      pdf_set_info($pdf, "Author", ""); 
      pdf_set_info($pdf, "Title", ""); 
      pdf_set_info($pdf, "Creator", ""); 
      pdf_set_info($pdf, "Subject", ""); 
      // start a new page (A4) 
      $x = 595; 
      $y = 842; 
      pdf_begin_page($pdf, $x, $y); 
      pdf_set_parameter($pdf, 'FontOutline', 'Arial=c:\windows\fonts\arial.ttf'); 
      pdf_setcolor($pdf, "stroke", "rgb", 0, 0, 0, 1.0); 

      // get and use a font object 
      $font = pdf_findfont($pdf, "Arial", "host", 1); 

      pdf_setfont($pdf, $font, 10); 

      // print text 
      pdf_show_xy($pdf, "QUOTATION" , 250, $y - 60); 
      pdf_show_xy($pdf, "Customer Name: " . $this->customer_details['first_name'] . 
       " " . $this->customer_details['last_name'], 50, 770); 
      pdf_show_xy($pdf, "Date: " . date("F j, Y, g:i a"), 50, 750); 
      pdf_show_xy($pdf, "Number of items requested: " . $count_items_req, 50, 730); 
      pdf_show_xy($pdf, "Number of items found: " . $count_items_found, 50, 710); 


      // add an image under the text 
      $image = $image = PDF_load_image($pdf, "png", 
       "C:/xampp/htdocs/final/images/footer_logo.png", ""); 

      PDF_fit_image($pdf, $image, 50, 785, ""); 
      pdf_moveto($pdf, 20, 780); 
      pdf_lineto($pdf, 575, 780); 
      pdf_stroke($pdf); 

      // draw another line near the bottom of the page 
      pdf_moveto($pdf, 20, 50); 
      pdf_lineto($pdf, 575, 50); 
      pdf_stroke($pdf); 

      //Draw the lines 
      $offset = 184; 
      $i = 0; 
      pdf_moveto($pdf, 20, $y - 160); 
      pdf_lineto($pdf, $x - 20, $y - 160); 
      pdf_stroke($pdf); 

      pdf_moveto($pdf, $x - 400, $y - 160); 
      pdf_lineto($pdf, $x - 400, 80); 
      pdf_stroke($pdf); 

      pdf_moveto($pdf, $x - 200, $y - 160); 
      pdf_lineto($pdf, $x - 200, 80); 
      pdf_stroke($pdf); 

      pdf_moveto($pdf, $x - 100, $y - 160); 
      pdf_lineto($pdf, $x - 100, 80); 
      pdf_stroke($pdf); 

      pdf_continue_text($pdf, ''); 
      pdf_continue_text($pdf, ''); 

      pdf_show_xy($pdf, "Searched Item", 70, $y - 150); 
      pdf_show_xy($pdf, "Searched Item", 70, $y - 150); 


      pdf_show_xy($pdf, "Item name", 240, $y - 150); 
      pdf_show_xy($pdf, "Item name", 240, $y - 150); 
      pdf_show_xy($pdf, "Price", $x - 180, $y - 150); 
      pdf_show_xy($pdf, "Price", $x - 180, $y - 150); 
      pdf_show_xy($pdf, "Discounted Price", $x - 100, $y - 150); 
      pdf_show_xy($pdf, "Discounted Price", $x - 100, $y - 150); 
      for ($i = 0; $i < count($this->quotation_details); $i++) 
      { 

       pdf_show_xy($pdf, $this->quotation_details[$i]['name_searched'] , 70, $y - 500); 

      } 


      // and write some text under it 
      pdf_show_xy($pdf, "", 250, 35); 


      // end page 
      pdf_end_page($pdf); 

      // close and save file 
      pdf_close($pdf); 

답변

2

중첩 루프가 필요하지 않으므로 매번 $ y에서 빼는 값을 변경해야합니다. 당신은 너무처럼 작업을 수행 할 수 있습니다


$placeholder = 500; // initial value 
for ($i = 0; $i quotation_details); $i++) 
{ 
    pdf_show_xy($pdf, $this->quotation_details[$i]['name_searched'] , 70, $y - $placeholder); 
    $placeholder = $placeholder - 20; 
} 

당신은 주위보다 많거나 적은 20 재생에 의해 빼고 좋아 보인다 값을 발견 할 수 있습니다.

+0

고맙습니다. :) – chupinette

관련 문제