Example #1
0
<?php

$p = PDF_new();
PDF_open_file($p);
PDF_begin_page($p, 595, 842);
$im = pdf_open_jpeg($p, "php-big.jpg");
pdf_place_image($p, $im, 200, 700, 1.0);
PDF_save($p);
// Save current coordinate system settings
$nx = 50 / PDF_get_value($p, "imagewidth", $im);
$ny = 100 / PDF_get_value($p, "imageheight", $im);
PDF_scale($p, $nx, $ny);
pdf_place_image($p, $im, 200 / $nx, 600 / $ny, 1.0);
PDF_restore($p);
// Restore previous
pdf_close_image($p, $im);
PDF_end_page($p);
PDF_close($p);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
Header("Content-type:application/pdf");
Header("Content-Length:{$len}");
Header("Content-Disposition:inline; filename=coords.pdf");
echo $buf;
PDF_delete($p);
Example #2
0
 /**
  * Adiciona uma imagem no documento PDF escalonando-a até a largura desejada.
  *
  * @param   string     $tipo      Tipo de imagem a ser incorporada
  * @param   string     $image     Caminho para o arquivo da imagem
  * @param   int|float  $x         Posição x (eixo horizontal)
  * @param   int|float  $y         Posição y (eixo vertical)
  * @param   int|float  $maxWidth  Largura máxima da imagem (usado para o cálculo de redução proporcional)
  */
 public function insertImageScaled($tipo, $image, $x, $y, $maxWidth)
 {
     $image = realpath($image);
     if (!is_readable($image)) {
         throw new Exception('Caminho para arquivo de imagem inválido: "' . $image . '"');
     }
     $y = $this->altura - $y;
     $im = pdf_open_image_file($this->pdf, $tipo, $image, '', 0);
     /**
      * Reduz em dois pixels. Algum bug da função da PDFLib necessita essa
      * compensação no cálculo para redução proporcional.
      */
     $maxWidth -= 2;
     $scale = 1;
     $width = PDF_get_value($this->pdf, 'imagewidth', $im);
     if ($width > $maxWidth) {
         $scale = $maxWidth / $width;
     }
     PDF_place_image($this->pdf, $im, $x, $y, $scale);
     PDF_close_image($this->pdf, $im);
 }
 /**
  * Outputs the the via PDF_show_boxed()
  *
  * Outputs the text via PDF_show_boxed() at the
  * specified coordinates, alignment and leading.
  *
  * @param    float   $xpos        The left starting position
  * @param    float   $ypos        The top starting position
  * @param    string  $alignment   "left"/"right"/"center"
  * @param    float   $leading     The text leading
  *
  * @access   public
  */
 function puttext2($xpos, $ypos, $alignment, $leading)
 {
     if (!$this->layoutvalid) {
         $this->getrequiredlinenum();
     }
     $alignment = strtolower($alignment);
     if ($leading == 0) {
         $leading = $this->fontsize;
     }
     $linenum = sizeof($this->lines);
     $height = $linenum * $leading;
     $font = PDF_findfont($this->pdf, $this->fontface, 'host', 0);
     $descender = -PDF_get_value($this->pdf, "descender", $font) * $this->fontsize;
     //PDF_setcolor($this->pdf, "both", "rgb", 0, 0, 1, 0);
     // The passed x/y-coordinates specify the top left corner of the
     // text area whereas PDF_show_boxed() interpretes the coordinates
     // as the x/y-coordinates of the bottom left corner
     $ypos -= $linenum * $leading;
     // PDF_show_boxed() interpretes the coordinates as the text
     // baseline, but we use it for specifying the geometry of the
     // complete  textblock
     $ypos += $descender;
     // PDF_show_boxed() moves the first text line down by "leading"
     // pixels; we want the first line to really appear at the top of
     // the text block
     $ypos += $leading - $this->fontsize;
     // In order to allow output via PDF_show_boxed(),
     // lines consisting only of single word (i.e. lines
     // not containing a space), are supplemented by a LF
     // character
     for ($i = 0; $i < sizeof($this->lines); $i++) {
         $line =& $this->lines[$i];
         if (strpos($line, " ") === false) {
             $line .= "\n";
         }
     }
     $text = implode(" ", $this->lines);
     $text = ereg_replace("\n +", "\n", $text);
     PDF_setfont($this->pdf, $font, $this->fontsize);
     $this->setcolor($this->fontcolor);
     PDF_set_value($this->pdf, "leading", $leading);
     PDF_show_boxed($this->pdf, $text, $xpos, $ypos - 1, $this->width, (int) ($linenum * $leading) + 1, $alignment, "");
     $this->buffer = "";
 }
Example #4
0
 function getSize()
 {
     $this->openPage();
     $x = PDF_get_value($this->pdf, 'pagewidth', 0);
     $y = PDF_get_value($this->pdf, 'pageheight', 0);
     return array($x, $y);
 }