PDF_set_parameter($p, "SearchPath", $searchpath); /* open new PDF file; insert a file name to create the PDF on disk */ if (PDF_open_file($p, "") == 0) { die("Error: " . PDF_get_errmsg($p)); } /* This line is required to avoid problems on Japanese systems */ PDF_set_parameter($p, "hypertextencoding", "winansi"); PDF_set_info($p, "Creator", "image.php"); PDF_set_info($p, "Author", "Rainer Schaaf"); PDF_set_info($p, "Title", "image sample (PHP)"); $imagefile = "nesrin.jpg"; $image = PDF_load_image($p, "auto", $imagefile, ""); if (!$image) { die("Error: " . PDF_get_errmsg($p)); } /* dummy page size, will be adjusted by PDF_fit_image() */ PDF_begin_page($p, 10, 10); PDF_fit_image($p, $image, 0, 0, "adjustpage"); PDF_close_image($p, $image); PDF_end_page($p); /* close page */ PDF_close($p); /* close PDF document */ $buf = PDF_get_buffer($p); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: {$len}"); header("Content-Disposition: inline; filename=image.pdf"); print $buf; PDF_delete($p); /* delete the PDFlib object */
PDF_show_xy($pdf, $line, 20, $y - 300); PDF_show_xy($pdf, $total, 250, $y - 320); PDF_show_xy($pdf, $doubleline, 250, $y - 330); PDF_show_xy($pdf, $descript, 30, $y - 400); //PRINT AMOUNT ---------------------------------------------------------- $amt_x = 470; $amt_y = 655; PDF_show_xy($pdf, '$ ' . $debit_card, $amt_x, $amt_y - 30); PDF_show_xy($pdf, '$ ' . $amex_card, $amt_x, $amt_y - 60); PDF_show_xy($pdf, '$ ' . $visa_card, $amt_x, $amt_y - 90); PDF_show_xy($pdf, '$ ' . $total_staff_salary, $amt_x, $amt_y - 120); PDF_show_xy($pdf, '$ ' . $phone_bill, $amt_x, $amt_y - 150); PDF_show_xy($pdf, '$ ' . $rent_bill, $amt_x, $amt_y - 180); PDF_show_xy($pdf, '$ ' . $electricity_bill, $amt_x, $amt_y - 210); PDF_show_xy($pdf, '$ ' . $director_fee, $amt_x, $amt_y - 240); PDF_show_xy($pdf, '$ ' . $consignment_payment, $amt_x, $amt_y - 270); PDF_show_xy($pdf, '$ ' . $total_amount, $amt_x, $amt_y - 320); PDF_show_xy($pdf, strtoupper($desc), 150, $amt_y - 400); PDF_close_image($pdf, $images); //test /*end page*/ PDF_end_page($pdf); /*close and save file*/ PDF_close($pdf); $buf = PDF_get_buffer($pdf); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: {$len}"); header("Content-Disposition: inline; filename=gen01.pdf"); print $buf; PDF_save($pdf);
/** * 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); }