本文整理汇总了PHP中FPDI::useTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP FPDI::useTemplate方法的具体用法?PHP FPDI::useTemplate怎么用?PHP FPDI::useTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FPDI
的用法示例。
在下文中一共展示了FPDI::useTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: merge
/**
* Merge multiple documents.
*
* @return Dhl_Intraship_Helper_Pdf $this
* @throws Dhl_Intraship_Helper_Pdf_Exception
*/
public function merge()
{
// Include required fpdi library.
if (!class_exists('FPDF', false)) {
require_once Mage::getBaseDir('base') . DS . 'lib' . DS . 'fpdf' . DS . 'fpdf.php';
}
if (!class_exists('FPDI', false)) {
require_once Mage::getBaseDir('base') . DS . 'lib' . DS . 'fpdf' . DS . 'fpdi.php';
}
// Try to merge documents via FPDI.
try {
// Create new FPDI document
$this->_document = new FPDI('P', 'mm', $this->getConfig()->getFormat());
$this->_document->SetAutoPageBreak(false);
$page = 1;
foreach ($this->_collection as $document) {
$pages = $this->_document->setSourceFile($document->getFilePath());
for ($i = 1; $i <= $pages; $i++) {
$this->_document->addPage();
$this->_document->useTemplate($this->_document->importPage($i, '/MediaBox'));
$page++;
}
}
} catch (Exception $e) {
throw new Dhl_Intraship_Helper_Pdf_Exception('pdf merging failed. service temporary not available', $e->getCode());
}
return $this;
}
示例2: generate_philosophy_certificate
function generate_philosophy_certificate($confirmation, $form, $entry, $ajax)
{
// print_r( $entry ); die;
if ($entry['gquiz_is_pass']) {
$upload_dir = wp_upload_dir();
// initiate FPDI
$pdf = new FPDI();
// set the sourcefile
$pdf->setSourceFile(get_template_directory() . '/library/certificate.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// get the width and height of the template
$specs = $pdf->getTemplateSize($tplIdx);
// add a page
$pdf->AddPage("L", array($specs['w'], $specs['h']));
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
// now write some text above the imported page
$pdf->SetY(101);
$pdf->SetFont("dejavuserifbi", 'I', 35);
$pdf->SetTextColor(0, 54, 99);
$text = $entry['2.3'] . " " . $entry['2.6'];
$pdf->MultiCell(260, 40, $text, 0, 'C');
// now write some text above the imported page
$pdf->SetY(165);
$pdf->SetFont("dejavuserifbi", 'I', 22);
$pdf->SetTextColor(0, 54, 99);
$text = date('F j, Y');
$pdf->MultiCell(260, 22, $text, 0, 'C');
// save the pdf out to file
$pdf->Output($upload_dir['basedir'] . '/certificates/' . $entry['id'] . '.pdf', 'F');
}
return array('redirect' => '/philosophy-results/?id=' . $entry['id']);
}
示例3: createPDF
public function createPDF(FPDI $fpdi, $filename)
{
$fpdi->setSourceFile(__DIR__ . '/A.pdf');
$template = $fpdi->importPage(1);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
$template = $fpdi->importPage(1);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
file_put_contents($filename, $fpdi->Output('', 'S'));
}
示例4: testMerge
public function testMerge()
{
$fpdi = new FPDI();
$fpdi->setSourceFile(__DIR__ . '/A.pdf');
$template = $fpdi->importPage(1);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
$template = $fpdi->importPage(1);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
file_put_contents(__DIR__ . '/AA.pdf', $fpdi->Output('', 'S'));
}
示例5: runProcessStep
public function runProcessStep($dokument)
{
$file = $dokument->getLatestRevision()->getFile();
$extension = array_pop(explode(".", $file->getExportFilename()));
#$this->ziphandler->addFile($file->getAbsoluteFilename(), $file->getExportFilename());
// Print Metainfo for PDFs
if (strtolower($extension) == "pdf") {
try {
$fpdf = new FPDI();
$pagecount = $fpdf->setSourceFile($file->getAbsoluteFilename());
$fpdf->SetMargins(0, 0, 0);
$fpdf->SetFont('Courier', '', 8);
$fpdf->SetTextColor(0, 0, 0);
$documentSize = null;
for ($i = 0; $i < $pagecount; $i++) {
$string = $dokument->getLatestRevision()->getIdentifier() . " (Seite " . ($i + 1) . " von " . $pagecount . ", Revision " . $dokument->getLatestRevision()->getRevisionID() . ")";
$fpdf->AddPage();
$tpl = $fpdf->importPage($i + 1);
$size = $fpdf->getTemplateSize($tpl);
// First Page defines documentSize
if ($documentSize === null) {
$documentSize = $size;
}
// Center Template on Document
$fpdf->useTemplate($tpl, intval(($documentSize["w"] - $size["w"]) / 2), intval(($documentSize["h"] - $size["h"]) / 2), 0, 0, true);
$fpdf->Text(intval($documentSize["w"]) - 10 - $fpdf->GetStringWidth($string), 5, $string);
}
$this->ziphandler->addFromString($dokument->getLatestRevision()->getIdentifier() . "." . $extension, $fpdf->Output("", "S"));
} catch (Exception $e) {
$this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
}
} else {
$this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
}
}
示例6: generate_mitgliedsbescheinigung
function generate_mitgliedsbescheinigung($titleAndName, $strasse, $plz, $ort, $land, $jahr, $vorstand, $datum)
{
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile(HOME_DIRECTORY . 'alumpiHP_libraries/Mitgliedsbestaetigung_blank.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at position 0,0 with a width of 210 mm (full page)
$pdf->useTemplate($tplIdx, 0, 0, 210);
// add the font DejaVu
$pdf->AddFont('DejaVuSans', '', 'DejaVuSans.ttf', true);
$pdf->AddFont('DejaVuSans-Bold', '', 'DejaVuSans-Bold.ttf', true);
// text settings
$pdf->SetTextColor(0, 0, 0);
// add address of the member
$addressString = $titleAndName . "\n";
$addressString .= $strasse . "\n";
$addressString .= $plz . " " . $ort . "\n";
$addressString .= $land;
$pdf->SetFont('DejaVuSans');
$pdf->SetFontSize(12);
$pdf->SetXY(20, 23);
$pdf->Multicell(80, 6, $addressString);
//add heading
$headingString = "Mitgliedsbescheinigung " . $jahr;
$pdf->SetFont('DejaVuSans-Bold');
$pdf->SetFontSize(16);
$pdf->SetXY(20, 80);
$pdf->Multicell(170, 6, $headingString);
// add main text
$textString = "Hiermit wird bestätigt, dass " . $titleAndName . " im Kalenderjahr " . $jahr;
$textString .= " ordentliches Mitglied des Absolventen- und Förderverein MPI Uni Bayreuth e.V. (aluMPI) ist.\n";
$textString .= "\n";
$pdf->SetFont('DejaVuSans');
$pdf->SetFontSize(12);
$pdf->SetXY(20, 100);
$pdf->Multicell(170, 6, $textString);
// add signature text
$signatureString = "Absolventen- und Förderverein MPI Uni Bayreuth e.V.\n";
$signatureString .= "1. Vorstand: " . $vorstand . "\n";
$pdf->SetXY(20, 140);
$pdf->Multicell(170, 6, $signatureString);
// add signature
$pdf->Image(HOME_DIRECTORY . 'alumpiHP_libraries/unterschrift_krinninger.png', 20, 155, 50);
// add place and date
$dateString = "Bayreuth, " . $datum;
$pdf->SetXY(20, 180);
$pdf->Multicell(170, 6, $dateString);
ob_clean();
$pdf->Output();
}
示例7: listAction
public function listAction()
{
$receipt = new \FPDI();
// PDFの余白(上左右)を設定
$receipt->SetMargins(0, 0, 0);
// ヘッダーの出力を無効化
$receipt->setPrintHeader(false);
// フッターの出力を無効化
$receipt->setPrintFooter(false);
// フォントを登録
$fontPathRegular = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-regular.ttf';
// $regularFont = $receipt->addTTFfont($fontPathRegular, '', '', 32);
$font = new TCPDF_FONTS();
$regularFont = $font->addTTFfont($fontPathRegular);
$fontPathBold = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-bold.ttf';
// $boldFont = $receipt->addTTFfont($fontPathBold, '', '', 32);
$font = new TCPDF_FONTS();
$boldFont = $font->addTTFfont($fontPathBold);
// ページを追加
$receipt->AddPage();
// テンプレートを読み込み
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/receipt.pdf');
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/template.pdf');
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/w01_1.pdf');
$receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/senijiten.pdf');
// 読み込んだPDFの1ページ目のインデックスを取得
$tplIdx = $receipt->importPage(1);
// 読み込んだPDFの1ページ目をテンプレートとして使用
$receipt->useTemplate($tplIdx, null, null, null, null, true);
// 書き込む文字列のフォントを指定
$receipt->SetFont($regularFont, '', 11);
// 書き込む文字列の文字色を指定
$receipt->SetTextColor(0, 0, 255);
// X : 42mm / Y : 108mm の位置に
$receipt->SetXY(59, 248);
// 文字列を書き込む
$receipt->Write(0, isset($_POST['name']) ? $_POST['name'] . 'さん' : '名無しさん');
/* $response = new Response(
// Output関数の第一引数にはファイル名、第二引数には出力タイプを指定する
// 今回は文字列で返してほしいので、ファイル名はnull、出力タイプは S = String を選択する
$receipt->Output(null, 'S'),
200,
array('content-type' => 'application/pdf')
);
// レスポンスヘッダーにContent-Dispositionをセットし、ファイル名をreceipt.pdfに指定
$response->headers->set('Content-Disposition', 'attachment; filename="receipt.pdf"');
return $response;
*/
// $receipt->
$receipt->output('newpdf.pdf', 'I');
}
示例8: split_pdf
function split_pdf($filename, $end_directory = false, $num = 1)
{
require_once 'fpdf/fpdf.php';
require_once 'fpdi/fpdi.php';
$end_directory = $end_directory ? $end_directory . date("d-m-Y__H-i-s") . "/" : './';
$new_path = preg_replace('/[\\/]+/', '/', $end_directory . '/' . substr($filename, 0, strrpos($filename, '/')));
if (!is_dir($new_path)) {
// Will make directories under end directory that don't exist
// Provided that end directory exists and has the right permissions
mkdir($new_path, 0777, true);
}
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($filename);
// How many pages?
$j = 0;
// Split each page into a new PDF
$new_pdf = new FPDI();
for ($i = 1; $i <= $pagecount; $i++) {
$new_pdf->AddPage();
$new_pdf->setSourceFile($filename);
$new_pdf->useTemplate($new_pdf->importPage($i));
if ($i != 1 && $i % $num == 0 || $num == 1) {
try {
$new_filename = $end_directory . str_replace('.pdf', '', $filename) . '_' . $i . ".pdf";
$new_pdf->Output($new_filename, "F");
$url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/";
echo "File: <a href='" . $url . $new_filename . "'>" . $url . $new_filename . "</a><br />\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
unset($new_pdf);
$new_pdf = new FPDI();
$j = 0;
}
$j++;
}
if ($j != 0) {
try {
$new_filename = $end_directory . str_replace('.pdf', '', $filename) . '_' . ($i - 1) . ".pdf";
$new_pdf->Output($new_filename, "F");
$url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/";
echo "File: <a href='" . $url . $new_filename . "'>" . $url . $new_filename . "</a><br />\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
示例9: merge
/**
* Merges your provided PDFs and outputs to specified location.
* @param $outputmode
* @param $outputname
* @return PDF
*/
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
{
if (!isset($this->_files) || !is_array($this->_files)) {
throw new exception("No PDFs to merge.");
}
$fpdi = new FPDI();
//$fpdi->setPrintHeader(FALSE);
//$fpdi->setPrintFooter(FALSE);
//merger operations
foreach ($this->_files as $file) {
$filename = $file[0];
$filepages = $file[1];
$count = $fpdi->setSourceFile($filename);
//add the pages
if ($filepages == 'all') {
for ($i = 1; $i <= $count; $i++) {
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$orientation = $size['w'] <= $size['h'] ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
} else {
foreach ($filepages as $page) {
if (!($template = $fpdi->importPage($page))) {
throw new exception("Could not load page '{$page}' in PDF '{$filename}'. Check that the page exists.");
}
$size = $fpdi->getTemplateSize($template);
$orientation = $size['w'] <= $size['h'] ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
}
}
//output operations
$mode = $this->_switchmode($outputmode);
if ($mode == 'S') {
return $fpdi->Output($outputpath, 'S');
} else {
if ($fpdi->Output($outputpath, $mode) == '') {
return true;
} else {
throw new exception("Error outputting PDF to '{$outputmode}'.");
return false;
}
}
}
示例10: carl_merge_pdfs_fpdi
function carl_merge_pdfs_fpdi($pdffiles, $titles = array(), $metadata = array(), $metadata_encoding = 'UTF-8')
{
// FPDI throws some notices that break the PDF
$old_error = error_reporting(E_ERROR | E_WARNING | E_PARSE);
include_once INCLUDE_PATH . 'pdf/tcpdf/tcpdf.php';
include_once INCLUDE_PATH . 'pdf/fpdi/fpdi.php';
if (gettype($pdffiles) != 'array') {
trigger_error('$pdffiles must be an array');
return false;
}
if (!(class_exists('TCPDF') && class_exists('FPDI'))) {
trigger_error('You must have TCPDF/FPDI installed in order to run carl_merge_pdfs()');
return false;
}
if (empty($pdffiles)) {
return NULL;
}
$fpdi = new FPDI();
foreach ($pdffiles as $pdffile) {
if (file_exists($pdffile)) {
$count = $fpdi->setSourceFile($pdffile);
for ($i = 1; $i <= $count; $i++) {
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template, null, null, null, null, true);
if ($i == 1) {
if (isset($titles[$pdffile])) {
$bookmark = html_entity_decode($titles[$pdffile]);
} else {
$bookmark = $pdffile;
}
$fpdi->Bookmark($bookmark, 1, 0, '', '', array(0, 0, 0));
}
}
}
}
error_reporting($old_error);
return $fpdi->Output('ignored.pdf', 'S');
}
示例11: mkdir
function split_multi_pdf($arrayOfFiles)
{
$new_path = storage_path() . '/Macyspos';
if (!is_dir($new_path)) {
// Will make directories under end directory that don't exist
// Provided that end directory exists and has the right permissions
mkdir($new_path, 0777, true);
}
foreach ($arrayOfFiles as $file) {
$tempArrayOfPos = array();
$tempArrayOfPos = $this->getArrayOfPOs($file);
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($file);
// How many pages?
for ($i = 1; $i <= $pagecount; $i++) {
$singleItem = $tempArrayOfPos[$i - 1];
// dd($singleItem);
$tempPackingList = MacysPackingList::where('po', '=', $singleItem['PO'])->first();
if ($tempPackingList == null) {
$new_pdf = new FPDI();
$new_pdf->AddPage();
$new_pdf->setSourceFile($file);
$newPackingList = new MacysPackingList();
$newPackingList->po = trim($singleItem['PO']);
$newPackingList->shipterms = trim($singleItem['shipterms']);
$new_pdf->useTemplate($new_pdf->importPage($i));
try {
$new_filename = storage_path() . '/Macyspos/' . $singleItem['PO'] . '.pdf';
$newPackingList->pathToFile = $new_filename;
$new_pdf->Output($new_filename, "F");
$newPackingList->save();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
}
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$id = $input->getArgument('id');
$pdffile = $input->getArgument('pdf');
$em = $this->getContainer()->get('doctrine');
$tab = $this->csv($pdffile);
$template = $em->getRepository('PrintBundle:Template')->find($id);
$path = $this->getContainer()->get('kernel')->getRootDir() . '/../web/uploads/pdf/' . $template->getPdffile();
$width = $template->getWidth();
$height = $template->getHeight();
$orientation = $height > $width ? 'P' : 'L';
$custom_layout = array($width, $height);
$i = 1;
foreach ($tab as $key => $value) {
$pdf = new \FPDI($orientation, 'mm', $custom_layout, true, 'UTF-8', false);
$pdf->setPageOrientation($orientation);
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetAutoPageBreak(true, 40);
$pdf->setFontSubsetting(false);
// add a page
$pdf->AddPage($orientation);
$pdf->setSourceFile($path);
$_tplIdx = $pdf->importPage(1);
$size = $pdf->useTemplate($_tplIdx, 0, 0, $width, true);
foreach ($template->getChildactivity() as $opt) {
$pdf->SetXY($opt->getX(), $opt->getY());
$pdf->SetFont($opt->getFont(), '', $opt->getFontsize() * 2);
// echo $opt->getFontsize()."\n";
$pdf->Cell($opt->getWidth(), $opt->getHeight(), $value[$opt->getName()]);
}
//$pdf->Cell(0, $size['h'], 'TCPDF and FPDI');
// echo $template->getId();
$pdf->Output($this->getContainer()->get('kernel')->getRootDir() . '/../web/folder/pdf' . $template->getId() . "-{$i}.pdf", 'F');
$i++;
}
}
示例13: toStr
$pdf->Cell(20, 6, toStr(number_format($row["ANTICIPO_EXP"], 2, ",", ".")), 0, 0, 'R');
$total += $row["ANTICIPO_EXP"];
$pdf->Ln(6);
}
$pdf->Ln(6);
$pdf->Line(10, $pdf->GetY(), 200, $pdf->GetY());
$pdf->Ln(6);
$pdf->Cell(190, 6, 'Total Bs.: ' . number_format($total, 2, ",", "."), 0, 1, 'R');
$tmpFile = 'tmp' . time() . '.pdf';
$pdf->Output($tmpFile, 'F');
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile($tmpFile);
$box = '/MediaBox';
$tplIdx = $pdf->importPage(1, $box);
$pdf->useTemplate($tplIdx, 5, -55, 160);
$pdf->Output();
unlink($tmpFile);
break;
case "listapacmed":
$titulo = "Lista de pacientes por día";
$pdf = new PDF();
$pdf->SetCompression(true);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 10);
$smed = mssql_result(mssql_query("select nombre_prv from tbproveedores where codigo_prv='{$med}'"), 0, 0);
$sql = mssql_query("\n\t\tSET LANGUAGE Spanish\n\t\tselect \n\t\t\tCODIGO_CIT, \n\t\t\tTURNO_CIT,\n\t\t\tPACIENTE_CIT,\n\t\t\t(select nombre_pac from tbpacientes where codigo_pac = paciente_cit) as paciente \n\t\t\tfrom tbcitas where \n\t\t\tproveedor_cit = '{$med}' and baremo_cit='{$esp}' and \n\t\t\tconvert(char(10),fecha_cit,126)='{$dd}' order by turno_cit asc\n\t\t");
$pdf->Cell(100, 6, toStr("Fecha: " . date("d/m/Y", strtotime($dd))), 0, 1);
$pdf->Cell(100, 6, toStr("Médico: " . $smed), 0, 1);
$pdf->Cell(100, 6, toStr("Especialidad: " . $esp), 0, 1);
示例14: save_design
public function save_design()
{
if ($this->input->post('mode') == 'edit') {
$this->db->delete('designs', array('id' => $this->input->post('design_id')));
}
$faceMacket = str_replace('http://klever.media/', '', $this->input->post('faceMacket'));
$backMacket = str_replace('http://klever.media/', '', $this->input->post('backMacket'));
$face = $this->input->post('face');
$back = $this->input->post('back');
// get all fonts
$query = $this->db->get('fonts');
$fonts = array();
foreach ($query->result() as $font) {
$fonts[$font->family] = $font->source;
}
// generate pdf face template name and preview name
$face_pdf = 'uploads/redactor/face_' . md5(microtime(true)) . '.pdf';
$face_preview = 'uploads/redactor/face_' . md5(microtime(true)) . '.jpg';
// convert face image to pdf
$img = new Imagick($faceMacket);
$img->setresolution(300, 300);
$img->setcolorspace(Imagick::COLORSPACE_CMYK);
$img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
$img->setimageformat('pdf');
$img->writeimage($face_pdf);
// include TCPDF ana FPDI
include_once APPPATH . 'libraries/tcpdf/tcpdf.php';
include_once APPPATH . 'libraries/tcpdf/fpdi.php';
include_once APPPATH . 'libraries/tcpdf/include/tcpdf_fonts.php';
$fontMaker = new TCPDF_FONTS();
// создаём лист
$pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
$pdf->SetMargins(0, 0, 0, true);
$pdf->AddPage('L');
// загрузим ранее сохранённый шаблон
$pdf->setSourceFile($face_pdf);
$pdf->SetMargins(0, 0, 0, true);
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, null, null, 0, 0, true);
// установим опции для pdf
$pdf->setCellHeightRatio(1);
$pdf->setCellPaddings(0, 0, 0, 0);
$pdf->setCellMargins(0, 0, 0, 0);
$pdf->SetAutoPageBreak(false, 0);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
if (!empty($face)) {
// отрисуем сначала изображения лица
foreach ($face as $item) {
if ($item['type'] == 'image') {
$pdf->Image($_SERVER['DOCUMENT_ROOT'] . '/' . str_replace('http://klever.media/', '', $item['content']), $this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $this->px_to_mm($item['width']), '', '', '', '', false, 300);
}
}
// потом текст на лице
foreach ($face as $item) {
if ($item['type'] == 'text') {
$cmyk = $this->rgbToCmyk($item['color']);
$pdf->SetTextColor($cmyk['c'] * 100, $cmyk['m'] * 100, $cmyk['y'] * 100, $cmyk['k'] * 100);
// set font
$tcpdfFont = $fontMaker->addTTFfont(realpath('fonts/redactor/' . $fonts[$item['font']]));
$pdf->SetFont($tcpdfFont, '', $item['size'] / 2, '', 'false');
$pdf->Text($this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $item['content'], false, false, true, 0, 0, 'L', false, '', 0, false, 'T', 'L', false);
}
}
}
// сохраним пдф лица
$pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf, 'F');
// сделаем превью для пользователя
$im = new Imagick();
$im->setResolution(300, 300);
$im->readimage($face_pdf . '[0]');
$im->flattenimages();
$im->setImageFormat('jpg');
$im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
$im->writeImage($face_preview);
$im->clear();
$im->destroy();
//exec('$ convert ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf . ' ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_preview);
// есть ли оборот
if (!empty($backMacket)) {
// generate pdf back template name and preview name
$back_pdf = 'uploads/redactor/back_' . md5(microtime(true)) . '.pdf';
$back_preview = 'uploads/redactor/back_' . md5(microtime(true)) . '.jpg';
// convert back image to pdf
$img = new Imagick($backMacket);
$img->setresolution(300, 300);
$img->setcolorspace(Imagick::COLORSPACE_CMYK);
$img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
$img->setimageformat('pdf');
$img->writeimage($back_pdf);
// создаём лист
$pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
$pdf->AddPage('L');
// загрузим ранее сохранённый шаблон
$pdf->setSourceFile($_SERVER['DOCUMENT_ROOT'] . '/' . $back_pdf);
$pdf->SetMargins(0, 0, 0, true);
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, null, null, 0, 0, true);
// установим опции для pdf
$pdf->SetMargins(0, 0, 0, true);
//.........这里部分代码省略.........
示例15: view_sign_oc
public function view_sign_oc(){
require_once('./assets/fpdf17/fpdf.php');
require_once('./assets/fpdf17/fpdi.php');
$oc_id=$this->uri->segment(3,'');
// init pce data
$oc_dat=$this->m_oc->get_oc_by_id($oc_id);
$project=$this->m_project->get_project_by_id($oc_dat->project_id);
//init sign pic
$ae_sign_user_dat=$this->m_user->get_user_by_login_name($project->project_cs);
$ae_sign_filename="no";
if (isset($ae_sign_user_dat->sign_filename)) {
$ae_sign_filename=$ae_sign_user_dat->sign_filename;
}
$finance_sign_dat=$this->m_user->get_user_by_login_name($oc_dat->fc_sign);
$finance_sign_filename="no";
if (isset($finance_sign_dat->sign_filename)) {
$finance_sign_filename=$finance_sign_dat->sign_filename;
}
// initiate FPDI
$pdf = new FPDI();
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวธรรมดา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('angsana','','angsa.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('angsana','B','angsab.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('angsana','I','angsai.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา กำหนด ชื่อ เป็น angsana
$pdf->AddFont('angsana','BI','angsaz.php');
// get the page count
$pageCount = $pdf->setSourceFile("./media/real_pdf/".$oc_dat->filename);
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
}
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('angsana','B',14);
$pdf->SetXY(5, 5);
//$pdf->Write(8, 'A complete document imported with FPDI');
//// temporaly disable
if ($finance_sign_filename!="no"&&$finance_sign_filename!=""&&$finance_sign_filename!=null) {
//$pdf->Image("./media/sign_photo/".$finance_sign_filename,100,10,40,0);
}
if ($ae_sign_filename!="no"&&$ae_sign_filename!=""&&$ae_sign_filename!=null) {
//$pdf->Image("./media/sign_photo/".$ae_sign_filename,100,110,40,0);
}
//$pdf->Image("images/play.png",100,100,100,0);
}
$new_filename=$oc_dat->oc_no."_A.pdf";
// Output the new PDF
//@unlink("./media/real_pdf/".$new_filename);
$pdf->Output($new_filename,"I");
//redirect("media/real_pdf/".$new_filename);
}