2017-02-08 16 views
8

मैं एक पीडीएफ फ़ाइल में आकर्षित करना चाहता हूं।पीडीएफ फ़ाइल में चित्रण

उदाहरण: पीडीएफ फ़ाइल खोलें और सर्कल, स्क्वायर, टेक्स्ट इत्यादि जैसे ड्राइंग टूल प्राप्त करें ... इन उपकरणों का उपयोग करके पीडीएफ फाइल पर आकार आ जाएगा।

मैंने Google पर खोज की और ऐसे विकल्प पाये जैसे pdf.js. लेकिन यह कोर PHP या सामान्य एमवीसी संरचना में लागू नहीं किया गया है। यह जेएस में लागू किया गया है।

किसी पीडीएफ फ़ाइल में आकार खींचने के लिए पीडीएफ.जेएस के लिए कोई वैकल्पिक?

मैं उदाहरण के लिए वीडियो linked here जैसा दिख रहा हूं।

+2

हमें पूछे जाने वाले प्रश्न ** पुस्तक, टूल, सॉफ़्टवेयर लाइब्रेरी, ट्यूटोरियल या अन्य ऑफ़-साइट संसाधन ** की सिफारिश या ढूंढने के लिए ** स्टैक ओवरफ़्लो के लिए * ऑफ-विषय * हैं क्योंकि वे राय वाले उत्तरों और स्पैम को आकर्षित करते हैं। इसके बजाए, [समस्या का वर्णन करें] (http://meta.stackoverflow.com/questions/254393/what-exactly-is-a-recommendation-question) और इसे हल करने के लिए अब तक क्या किया गया है। – Nytrix

+0

प्रश्न –

+0

को संपादित करने के लिए धन्यवाद है, आप निश्चित रूप से php में ऐसा नहीं कर सकते हैं, इन एनोटेशन को अपने पीडीएफ रीडर को सहेजने और लोड करने के अलावा। भी, पीडीएफ.जेएस सिर्फ एक पीडीएफ दर्शक है। यह पीडीएफ में बनाई गई एनोटेशन प्रदर्शित कर सकता है लेकिन यह एनोटेशन नहीं बना सकता है। – chitgoks

उत्तर

4

पिछले साल जब मैं एक ही समस्या मैं शोध पर और कुछ फेरबदल एवं समायोजन मैं यह काम कर करने में कामयाब होने के बाद आया था। तो यहां मेरी विधि को कैसे सेट अप और उपयोग करने के बारे में एक विस्तृत स्पष्टीकरण दिया गया है। (एफ ree पी ortable डी ocument एफ ormat) पीएचपी

साथ पीडीएफ फाइलों उत्पन्न करने के लिए अनुमति देता है जो:

  • FPDF:

    मैं एक दो पुस्तकालयों के संयोजन का उपयोग कर रहा हूँ

  • FPDI: (एफ री पी ortable डी ocument मैं mporter) जो मौजूदा पीडीएफ का उपयोग करता है और FPDF

पहले द्वारा प्रयोग किया जाता करने के लिए उन्हें टेम्पलेट्स में बदलता है, तो आपके पास दो पुस्तकालयों डाउनलोड करने के लिए की आवश्यकता होगी: FPDF में here पाया जाता है डाउनलोड अनुभाग और एफपीडीआई this page पर है। आपको दो फ़ोल्डर्स दिए जाएंगे। आगे बढ़ें और उन्हें अपनी परियोजना में जोड़ें।

enter image description here

के index.php में चलते हैं (या उस बात के लिए किसी भी अन्य फाइल) और एक पीडीएफ फाइल है कि हम sample.pdf नाम करेंगे संपादित:

यहाँ मेरी निर्देशिका संरचना है।मुझे official documentation से कुछ कोड मिला था लेकिन वास्तव में इसे सरल बनाने के लिए कुछ संशोधन किए गए थे। आप देखेंगे कि मैंने पृष्ठों के बीच नेविगेशन को आसान बनाने के लिए PDF कक्षा में nextPage() विधि जोड़ा है। एक फ्रेम में पीडीएफ फाइल आप बस उत्पादन कर सकते हैं या आप उपयोगकर्ता के कंप्यूटर से पीडीएफ फाइल के डाउनलोड के लिए मजबूर कर सकते हैं:

<?php 
require_once('FPDF/fpdf.php'); 
require_once('FPDI/fpdi.php'); 

// path of PDF file 
$fullPathToFile = "sample.pdf"; 


class PDF extends FPDI { 

    var $fileIndex; 
    var $currentPage = 1; 

    function Header() { 

     global $fullPathToFile; 

     if (is_null($this->fileIndex)) { 

      $this->numPages = $this->setSourceFile($fullPathToFile); 
      $this->fileIndex = $this->importPage(1); 

     } $this->useTemplate($this->fileIndex, 0, 0,200); 

    } 

    function nextPage() { 

     if($this->currentPage != 1) { 
      $this->fileIndex = $this->importPage($this->currentPage); 
     } 
     $this->addPage(); 

     return ++$this->currentPage; 
    } 

} 

// initiate PDF 
$pdf = new PDF(); 

// go to first page 
$pdf->nextPage(); 

// add content to current page 
$pdf->SetFont("helvetica", "", 20); 
$pdf->SetTextColor(220, 20, 60); 
$pdf->Text(50, 20, "I should not be here!"); 

// move to next page and add content 
$pdf->nextPage(); 

$pdf->SetFont("arial", "", 15); 
$pdf->SetTextColor(65, 105, 225); 
$pdf->Text(50, 20, "Me neither!!!"); 

//show the PDF in page 
$pdf->Output(); 

Output() विधि अलग तर्क प्राप्त कर सकते हैं। उस पर अधिक जानकारी के लिए Read here

डेमो!

FPDF के सामुदायिक कई स्क्रिप्ट जिनमें से एक अपनी दिलचस्पी लिखा है: यह geometric figures FPDF प्लगइन (आईडी script69.php) है। यह आपको लाइनों, आयतों, घटता, अंडाकार, मंडल, बहुभुज को दूसरों के बीच आकर्षित करने की अनुमति देता है।


यहाँ आप के लिए एक बोनस है:

draw.php नामक एक नई फ़ाइल बनाएँ और here पर उपलब्ध कराई गई स्रोत कोड डाल दिया। मैंने से नीचे स्रोत कोड प्रदान किया है (पहली तीन पंक्तियां इसे मूल स्रोत कोड से अलग करने के लिए अलग हैं)

<?php 
require_once('FPDF/fpdf.php'); 
require_once('FPDI/fpdi.php'); 

class PDF_Draw extends FPDI { 
    // Sets line style 
    // Parameters: 
    // - style: Line style. Array with keys among the following: 
    // . width: Width of the line in user units 
    // . cap: Type of cap to put on the line (butt, round, square). The difference between 'square' and 'butt' is that 'square' projects a flat end past the end of the line. 
    // . join: miter, round or bevel 
    // . dash: Dash pattern. Is 0 (without dash) or array with series of length values, which are the lengths of the on and off dashes. 
    //   For example: (2) represents 2 on, 2 off, 2 on , 2 off ... 
    //      (2,1) is 2 on, 1 off, 2 on, 1 off.. etc 
    // . phase: Modifier of the dash pattern which is used to shift the point at which the pattern starts 
    // . color: Draw color. Array with components (red, green, blue) 
    function SetLineStyle($style) { 
     extract($style); 
     if (isset($width)) { 
      $width_prev = $this->LineWidth; 
      $this->SetLineWidth($width); 
      $this->LineWidth = $width_prev; 
     } 
     if (isset($cap)) { 
      $ca = array('butt' => 0, 'round'=> 1, 'square' => 2); 
      if (isset($ca[$cap])) 
       $this->_out($ca[$cap] . ' J'); 
     } 
     if (isset($join)) { 
      $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2); 
      if (isset($ja[$join])) 
       $this->_out($ja[$join] . ' j'); 
     } 
     if (isset($dash)) { 
      $dash_string = ''; 
      if ($dash) { 
       $tab = explode(',', $dash); 
       $dash_string = ''; 
       foreach ($tab as $i => $v) { 
        if ($i > 0) 
         $dash_string .= ' '; 
        $dash_string .= sprintf('%.2F', $v); 
       } 
      } 
      if (!isset($phase) || !$dash) 
       $phase = 0; 
      $this->_out(sprintf('[%s] %.2F d', $dash_string, $phase)); 
     } 
     if (isset($color)) { 
      list($r, $g, $b) = $color; 
      $this->SetDrawColor($r, $g, $b); 
     } 
    } 

    // Draws a line 
    // Parameters: 
    // - x1, y1: Start point 
    // - x2, y2: End point 
    // - style: Line style. Array like for SetLineStyle 
    function Line($x1, $y1, $x2, $y2, $style = null) { 
     if ($style) 
      $this->SetLineStyle($style); 
     parent::Line($x1, $y1, $x2, $y2); 
    } 

    // Draws a rectangle 
    // Parameters: 
    // - x, y: Top left corner 
    // - w, h: Width and height 
    // - style: Style of rectangle (draw and/or fill: D, F, DF, FD) 
    // - border_style: Border style of rectangle. Array with some of this index 
    // . all: Line style of all borders. Array like for SetLineStyle 
    // . L: Line style of left border. null (no border) or array like for SetLineStyle 
    // . T: Line style of top border. null (no border) or array like for SetLineStyle 
    // . R: Line style of right border. null (no border) or array like for SetLineStyle 
    // . B: Line style of bottom border. null (no border) or array like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    function Rect($x, $y, $w, $h, $style = '', $border_style = null, $fill_color = null) { 
     if (!(false === strpos($style, 'F')) && $fill_color) { 
      list($r, $g, $b) = $fill_color; 
      $this->SetFillColor($r, $g, $b); 
     } 
     switch ($style) { 
      case 'F': 
       $border_style = null; 
       parent::Rect($x, $y, $w, $h, $style); 
       break; 
      case 'DF': case 'FD': 
       if (!$border_style || isset($border_style['all'])) { 
        if (isset($border_style['all'])) { 
         $this->SetLineStyle($border_style['all']); 
         $border_style = null; 
        } 
       } else 
        $style = 'F'; 
       parent::Rect($x, $y, $w, $h, $style); 
       break; 
      default: 
       if (!$border_style || isset($border_style['all'])) { 
        if (isset($border_style['all']) && $border_style['all']) { 
         $this->SetLineStyle($border_style['all']); 
         $border_style = null; 
        } 
        parent::Rect($x, $y, $w, $h, $style); 
       } 
       break; 
     } 
     if ($border_style) { 
      if (isset($border_style['L']) && $border_style['L']) 
       $this->Line($x, $y, $x, $y + $h, $border_style['L']); 
      if (isset($border_style['T']) && $border_style['T']) 
       $this->Line($x, $y, $x + $w, $y, $border_style['T']); 
      if (isset($border_style['R']) && $border_style['R']) 
       $this->Line($x + $w, $y, $x + $w, $y + $h, $border_style['R']); 
      if (isset($border_style['B']) && $border_style['B']) 
       $this->Line($x, $y + $h, $x + $w, $y + $h, $border_style['B']); 
     } 
    } 

    // Draws a Bézier curve (the Bézier curve is tangent to the line between the control points at either end of the curve) 
    // Parameters: 
    // - x0, y0: Start point 
    // - x1, y1: Control point 1 
    // - x2, y2: Control point 2 
    // - x3, y3: End point 
    // - style: Style of rectangule (draw and/or fill: D, F, DF, FD) 
    // - line_style: Line style for curve. Array like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style = '', $line_style = null, $fill_color = null) { 
     if (!(false === strpos($style, 'F')) && $fill_color) { 
      list($r, $g, $b) = $fill_color; 
      $this->SetFillColor($r, $g, $b); 
     } 
     switch ($style) { 
      case 'F': 
       $op = 'f'; 
       $line_style = null; 
       break; 
      case 'FD': case 'DF': 
       $op = 'B'; 
       break; 
      default: 
       $op = 'S'; 
       break; 
     } 
     if ($line_style) 
      $this->SetLineStyle($line_style); 

     $this->_Point($x0, $y0); 
     $this->_Curve($x1, $y1, $x2, $y2, $x3, $y3); 
     $this->_out($op); 
    } 

    // Draws an ellipse 
    // Parameters: 
    // - x0, y0: Center point 
    // - rx, ry: Horizontal and vertical radius (if ry = 0, draws a circle) 
    // - angle: Orientation angle (anti-clockwise) 
    // - astart: Start angle 
    // - afinish: Finish angle 
    // - style: Style of ellipse (draw and/or fill: D, F, DF, FD, C (D + close)) 
    // - line_style: Line style for ellipse. Array like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    // - nSeg: Ellipse is made up of nSeg Bézier curves 
    function Ellipse($x0, $y0, $rx, $ry = 0, $angle = 0, $astart = 0, $afinish = 360, $style = '', $line_style = null, $fill_color = null, $nSeg = 8) { 
     if ($rx) { 
      if (!(false === strpos($style, 'F')) && $fill_color) { 
       list($r, $g, $b) = $fill_color; 
       $this->SetFillColor($r, $g, $b); 
      } 
      switch ($style) { 
       case 'F': 
        $op = 'f'; 
        $line_style = null; 
        break; 
       case 'FD': case 'DF': 
        $op = 'B'; 
        break; 
       case 'C': 
        $op = 's'; // small 's' means closing the path as well 
        break; 
       default: 
        $op = 'S'; 
        break; 
      } 
      if ($line_style) 
       $this->SetLineStyle($line_style); 
      if (!$ry) 
       $ry = $rx; 
      $rx *= $this->k; 
      $ry *= $this->k; 
      if ($nSeg < 2) 
       $nSeg = 2; 

      $astart = deg2rad((float) $astart); 
      $afinish = deg2rad((float) $afinish); 
      $totalAngle = $afinish - $astart; 

      $dt = $totalAngle/$nSeg; 
      $dtm = $dt/3; 

      $x0 *= $this->k; 
      $y0 = ($this->h - $y0) * $this->k; 
      if ($angle != 0) { 
       $a = -deg2rad((float) $angle); 
       $this->_out(sprintf('q %.2F %.2F %.2F %.2F %.2F %.2F cm', cos($a), -1 * sin($a), sin($a), cos($a), $x0, $y0)); 
       $x0 = 0; 
       $y0 = 0; 
      } 

      $t1 = $astart; 
      $a0 = $x0 + ($rx * cos($t1)); 
      $b0 = $y0 + ($ry * sin($t1)); 
      $c0 = -$rx * sin($t1); 
      $d0 = $ry * cos($t1); 
      $this->_Point($a0/$this->k, $this->h - ($b0/$this->k)); 
      for ($i = 1; $i <= $nSeg; $i++) { 
       // Draw this bit of the total curve 
       $t1 = ($i * $dt) + $astart; 
       $a1 = $x0 + ($rx * cos($t1)); 
       $b1 = $y0 + ($ry * sin($t1)); 
       $c1 = -$rx * sin($t1); 
       $d1 = $ry * cos($t1); 
       $this->_Curve(($a0 + ($c0 * $dtm))/$this->k, 
          $this->h - (($b0 + ($d0 * $dtm))/$this->k), 
          ($a1 - ($c1 * $dtm))/$this->k, 
          $this->h - (($b1 - ($d1 * $dtm))/$this->k), 
          $a1/$this->k, 
          $this->h - ($b1/$this->k)); 
       $a0 = $a1; 
       $b0 = $b1; 
       $c0 = $c1; 
       $d0 = $d1; 
      } 
      $this->_out($op); 
      if ($angle !=0) 
       $this->_out('Q'); 
     } 
    } 

    // Draws a circle 
    // Parameters: 
    // - x0, y0: Center point 
    // - r: Radius 
    // - astart: Start angle 
    // - afinish: Finish angle 
    // - style: Style of circle (draw and/or fill) (D, F, DF, FD, C (D + close)) 
    // - line_style: Line style for circle. Array like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    // - nSeg: Ellipse is made up of nSeg Bézier curves 
    function Circle($x0, $y0, $r, $astart = 0, $afinish = 360, $style = '', $line_style = null, $fill_color = null, $nSeg = 8) { 
     $this->Ellipse($x0, $y0, $r, 0, 0, $astart, $afinish, $style, $line_style, $fill_color, $nSeg); 
    } 

    // Draws a polygon 
    // Parameters: 
    // - p: Points. Array with values x0, y0, x1, y1,..., x(np-1), y(np - 1) 
    // - style: Style of polygon (draw and/or fill) (D, F, DF, FD) 
    // - line_style: Line style. Array with one of this index 
    // . all: Line style of all lines. Array like for SetLineStyle 
    // . 0..np-1: Line style of each line. Item is 0 (not line) or like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    function Polygon($p, $style = '', $line_style = null, $fill_color = null) { 
     $np = count($p)/2; 
     if (!(false === strpos($style, 'F')) && $fill_color) { 
      list($r, $g, $b) = $fill_color; 
      $this->SetFillColor($r, $g, $b); 
     } 
     switch ($style) { 
      case 'F': 
       $line_style = null; 
       $op = 'f'; 
       break; 
      case 'FD': case 'DF': 
       $op = 'B'; 
       break; 
      default: 
       $op = 'S'; 
       break; 
     } 
     $draw = true; 
     if ($line_style) 
      if (isset($line_style['all'])) 
       $this->SetLineStyle($line_style['all']); 
      else { // 0 .. (np - 1), op = {B, S} 
       $draw = false; 
       if ('B' == $op) { 
        $op = 'f'; 
        $this->_Point($p[0], $p[1]); 
        for ($i = 2; $i < ($np * 2); $i = $i + 2) 
         $this->_Line($p[$i], $p[$i + 1]); 
        $this->_Line($p[0], $p[1]); 
        $this->_out($op); 
       } 
       $p[$np * 2] = $p[0]; 
       $p[($np * 2) + 1] = $p[1]; 
       for ($i = 0; $i < $np; $i++) 
        if (!empty($line_style[$i])) 
         $this->Line($p[$i * 2], $p[($i * 2) + 1], $p[($i * 2) + 2], $p[($i * 2) + 3], $line_style[$i]); 
      } 

     if ($draw) { 
      $this->_Point($p[0], $p[1]); 
      for ($i = 2; $i < ($np * 2); $i = $i + 2) 
       $this->_Line($p[$i], $p[$i + 1]); 
      $this->_Line($p[0], $p[1]); 
      $this->_out($op); 
     } 
    } 

    // Draws a regular polygon 
    // Parameters: 
    // - x0, y0: Center point 
    // - r: Radius of circumscribed circle 
    // - ns: Number of sides 
    // - angle: Orientation angle (anti-clockwise) 
    // - circle: Draw circumscribed circle or not 
    // - style: Style of polygon (draw and/or fill) (D, F, DF, FD) 
    // - line_style: Line style. Array with one of this index 
    // . all: Line style of all lines. Array like for SetLineStyle 
    // . 0..ns-1: Line style of each line. Item is 0 (not line) or like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    // - circle_style: Style of circumscribed circle (draw and/or fill) (D, F, DF, FD) (if draw) 
    // - circle_line_style: Line style for circumscribed circle. Array like for SetLineStyle (if draw) 
    // - circle_fill_color: Fill color for circumscribed circle. Array with components (red, green, blue) (if draw fill circle) 
    function RegularPolygon($x0, $y0, $r, $ns, $angle = 0, $circle = false, $style = '', $line_style = null, $fill_color = null, $circle_style = '', $circle_line_style = null, $circle_fill_color = null) { 
     if ($ns < 3) 
      $ns = 3; 
     if ($circle) 
      $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_line_style, $circle_fill_color); 
     $p = null; 
     for ($i = 0; $i < $ns; $i++) { 
      $a = $angle + ($i * 360/$ns); 
      $a_rad = deg2rad((float) $a); 
      $p[] = $x0 + ($r * sin($a_rad)); 
      $p[] = $y0 + ($r * cos($a_rad)); 
     } 
     $this->Polygon($p, $style, $line_style, $fill_color); 
    } 

    // Draws a star polygon 
    // Parameters: 
    // - x0, y0: Center point 
    // - r: Radius of circumscribed circle 
    // - nv: Number of vertices 
    // - ng: Number of gaps (ng % nv = 1 => regular polygon) 
    // - angle: Orientation angle (anti-clockwise) 
    // - circle: Draw circumscribed circle or not 
    // - style: Style of polygon (draw and/or fill) (D, F, DF, FD) 
    // - line_style: Line style. Array with one of this index 
    // . all: Line style of all lines. Array like for SetLineStyle 
    // . 0..n-1: Line style of each line. Item is 0 (not line) or like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    // - circle_style: Style of circumscribed circle (draw and/or fill) (D, F, DF, FD) (if draw) 
    // - circle_line_style: Line style for circumscribed circle. Array like for SetLineStyle (if draw) 
    // - circle_fill_color: Fill color for circumscribed circle. Array with components (red, green, blue) (if draw fill circle) 
    function StarPolygon($x0, $y0, $r, $nv, $ng, $angle = 0, $circle = false, $style = '', $line_style = null, $fill_color = null, $circle_style = '', $circle_line_style = null, $circle_fill_color = null) { 
     if ($nv < 2) 
      $nv = 2; 
     if ($circle) 
      $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_line_style, $circle_fill_color); 
     $p2 = null; 
     $visited = null; 
     for ($i = 0; $i < $nv; $i++) { 
      $a = $angle + ($i * 360/$nv); 
      $a_rad = deg2rad((float) $a); 
      $p2[] = $x0 + ($r * sin($a_rad)); 
      $p2[] = $y0 + ($r * cos($a_rad)); 
      $visited[] = false; 
     } 
     $p = null; 
     $i = 0; 
     do { 
      $p[] = $p2[$i * 2]; 
      $p[] = $p2[($i * 2) + 1]; 
      $visited[$i] = true; 
      $i += $ng; 
      $i %= $nv; 
     } while (!$visited[$i]); 
     $this->Polygon($p, $style, $line_style, $fill_color); 
    } 

    // Draws a rounded rectangle 
    // Parameters: 
    // - x, y: Top left corner 
    // - w, h: Width and height 
    // - r: Radius of the rounded corners 
    // - round_corner: Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top left, top right, bottom right and bottom left 
    // - style: Style of rectangle (draw and/or fill) (D, F, DF, FD) 
    // - border_style: Border style of rectangle. Array like for SetLineStyle 
    // - fill_color: Fill color. Array with components (red, green, blue) 
    function RoundedRect($x, $y, $w, $h, $r, $round_corner = '1111', $style = '', $border_style = null, $fill_color = null) { 
     if ('0000' == $round_corner) // Not rounded 
      $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color); 
     else { // Rounded 
      if (!(false === strpos($style, 'F')) && $fill_color) { 
       list($red, $g, $b) = $fill_color; 
       $this->SetFillColor($red, $g, $b); 
      } 
      switch ($style) { 
       case 'F': 
        $border_style = null; 
        $op = 'f'; 
        break; 
       case 'FD': case 'DF': 
        $op = 'B'; 
        break; 
       default: 
        $op = 'S'; 
        break; 
      } 
      if ($border_style) 
       $this->SetLineStyle($border_style); 

      $MyArc = 4/3 * (sqrt(2) - 1); 

      $this->_Point($x + $r, $y); 
      $xc = $x + $w - $r; 
      $yc = $y + $r; 
      $this->_Line($xc, $y); 
      if ($round_corner[0]) 
       $this->_Curve($xc + ($r * $MyArc), $yc - $r, $xc + $r, $yc - ($r * $MyArc), $xc + $r, $yc); 
      else 
       $this->_Line($x + $w, $y); 

      $xc = $x + $w - $r ; 
      $yc = $y + $h - $r; 
      $this->_Line($x + $w, $yc); 

      if ($round_corner[1]) 
       $this->_Curve($xc + $r, $yc + ($r * $MyArc), $xc + ($r * $MyArc), $yc + $r, $xc, $yc + $r); 
      else 
       $this->_Line($x + $w, $y + $h); 

      $xc = $x + $r; 
      $yc = $y + $h - $r; 
      $this->_Line($xc, $y + $h); 
      if ($round_corner[2]) 
       $this->_Curve($xc - ($r * $MyArc), $yc + $r, $xc - $r, $yc + ($r * $MyArc), $xc - $r, $yc); 
      else 
       $this->_Line($x, $y + $h); 

      $xc = $x + $r; 
      $yc = $y + $r; 
      $this->_Line($x, $yc); 
      if ($round_corner[3]) 
       $this->_Curve($xc - $r, $yc - ($r * $MyArc), $xc - ($r * $MyArc), $yc - $r, $xc, $yc - $r); 
      else { 
       $this->_Line($x, $y); 
       $this->_Line($x + $r, $y); 
      } 
      $this->_out($op); 
     } 
    } 

    /* PRIVATE METHODS */ 

    // Sets a draw point 
    // Parameters: 
    // - x, y: Point 
    function _Point($x, $y) { 
     $this->_out(sprintf('%.2F %.2F m', $x * $this->k, ($this->h - $y) * $this->k)); 
    } 

    // Draws a line from last draw point 
    // Parameters: 
    // - x, y: End point 
    function _Line($x, $y) { 
     $this->_out(sprintf('%.2F %.2F l', $x * $this->k, ($this->h - $y) * $this->k)); 
    } 

    // Draws a Bézier curve from last draw point 
    // Parameters: 
    // - x1, y1: Control point 1 
    // - x2, y2: Control point 2 
    // - x3, y3: End point 
    function _Curve($x1, $y1, $x2, $y2, $x3, $y3) { 
     $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k)); 
    } 

} 

?> 

मानते हुए कि आपके इस निर्देशिका संरचना है पेज के शीर्ष पर require_once('FPDF/fpdf.php'); और require_once('FPDI/fpdi.php'); जोड़ने के लिए मत भूलना: index.php में कोड के साथ फिर

enter image description here

बजाय वर्ग FPDI विस्तार हम सीधे PDF_Draw का विस्तार कर सकते हैं।

<?php 
require_once('draw.php'); 

// path of PDF file 
$fullPathToFile = "sample.pdf"; 

class PDF extends PDF_Draw { 

    . 
    . 
    . 

} 

// initiate PDF 
$pdf = new PDF(); 

// go to first page 
$pdf->nextPage(); 

// add content to current page 
$pdf->SetFont("helvetica", "", 20); 
$pdf->SetTextColor(220, 20, 60); 
$pdf->Text(50, 20, "I should not be here!"); 

// move to next page and add content 
$pdf->nextPage(); 

$pdf->SetFont("arial", "", 15); 

$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0)); 
$style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)); 
$style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0)); 
$style4 = array('L' => 0, 
       'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)), 
       'R' => array('width' => 0.50, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)), 
       'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10')); 
$style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)); 
$style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 255, 0)); 
$style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(200, 200, 0)); 

// Line 
$pdf->Text(5, 7, 'Line'); 
$pdf->Line(5, 10, 80, 30, $style); 

// Rect 
$pdf->Text(100, 7, 'Rectangle'); 
$pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200)); 

// Curve 
$pdf->Text(5, 37, 'Curve'); 
$pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6); 

// Circle and ellipse 
$pdf->Text(5, 82, 'Circle and ellipse'); 
$pdf->SetLineStyle($style5); 
$pdf->Circle(25,105,20); 

// Polygon 
$pdf->Text(5, 132, 'Polygon'); 
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); 
$pdf->Polygon(array(5,135,45,135,15,165)); 

// Regular polygon 
$pdf->Text(5, 172, 'Regular polygon'); 
$pdf->SetLineStyle($style5); 
$pdf->RegularPolygon(20, 190, 15, 6, 0, 1, 'F'); 

// Star polygon 
$pdf->Text(5, 212, 'Star polygon'); 
$pdf->SetLineStyle($style5); 
$pdf->StarPolygon(20, 230, 15, 20, 3, 0, 1, 'F'); 

// Rounded rectangle 
$pdf->Text(5, 252, 'Rounded rectangle'); 
$pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); 
$pdf->RoundedRect(5, 255, 40, 30, 3.50, '1111', 'DF'); 

$pdf->SetTextColor(65, 105, 225); 
$pdf->Text(50, 20, "Me neither!!!"); 

//show the PDF in page 
$pdf->Output(); 

डेमो: इस तरह कोड हम जोड़ने के पहले अभी भी काम, लेकिन अब हम Line() जैसे नए तरीकों का उपयोग कर सकते हैं, Curve(), Rect() आदि ...

यहाँ पूर्ण index.php कोड है!

और मैंने एसओ की 30k वर्ण सीमा को मारा। मैं आशा करता हूं कि इससे आपको मदद मिली होगी!

+0

मैंने PHP का उपयोग कर मौजूदा पीडीएफ में चित्र जोड़ने के लिए पूरी मार्गदर्शिका के साथ अपना जवाब अपडेट किया है – Ivan

4

TCPDF (tcpdf.org)PDF graphics methods को संभालने लगता है।

सीएफ। examples/example_012.php:

// create new PDF document 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

// Line 
$pdf->Text(5, 4, 'Line examples'); 
$pdf->Line(5, 10, 80, 30, $style); 
$pdf->Line(5, 10, 5, 30, $style2); 
$pdf->Line(5, 10, 80, 10, $style3); 
// Rect 
$pdf->Text(100, 4, 'Rectangle examples'); 
$pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200)); 
$pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3)); 

और इसकी GitHub project tecnickcom/tcpdf 100% पीएचपी किया जा रहा है का संकेत मिला।
हालांकि, this search दिखाता है कि यह एक नया पीडीएफ दस्तावेज़ बना और संशोधित कर सकता है। यह मौजूदा एक को खोलने और संशोधित करने में सक्षम नहीं हो सकता है।

1

http://www.fpdf.org आप x, y coordinates fpdf के साथ-साथ tcpdf का उपयोग कर आप के लिए उपयोगी हो सकता है आकर्षित करने के लिए चाहते हैं।

global $title; 
    // Calculate width 
    $w = $this->GetStringWidth($title)+6; 
    $this->SetX((210-$w)/2); 
    // Colors of frame, background and text 
    $this->SetDrawColor(0,80,180); 
    $this->SetFillColor(230,230,0); 
    $this->SetTextColor(220,50,50); 
    // Thickness of frame (1 mm) 
    $this->SetLineWidth(1); 
    // Title 
    $this->Cell($w,9,$title,1,1,'C',true); 
    // Line break 
    $this->Ln(10); 
} 
संबंधित मुद्दे