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']); }
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); } }
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')); }
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')); }
/** * 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; } } }
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'); }
/** * Simple helper function which actually merges a given array of document-paths * @param $paths * @return string The created document's url */ private function mergeDocuments($paths) { include_once 'engine/Library/Fpdf/fpdf.php'; include_once 'engine/Library/Fpdf/fpdi.php'; $pdf = new FPDI(); foreach ($paths as $path) { $numPages = $pdf->setSourceFile($path); for ($i = 1; $i <= $numPages; $i++) { $template = $pdf->importPage($i); $size = $pdf->getTemplateSize($template); $pdf->AddPage('P', array($size['w'], $size['h'])); $pdf->useTemplate($template); } } $hash = md5(uniqid(rand())); $pdf->Output($hash . '.pdf', "D"); }
$n = 1; foreach ($envelopes as $letter) { $pagecount = $pdf->setSourceFile("/tmp/{$sid}-{$n}letters.pdf"); $tplidx = $pdf->importPage($pagecount, '/MediaBox'); $pdf->addPage('L'); $pdf->useTemplate($tplidx, 0, 0); if ($letter['files']) { foreach ($letter['files'] as $file_id) { $cfile = new CFile($file_id); if (preg_match("/\\.pdf\$/", $cfile->name)) { $tmp_name = '/tmp/' . uniqid() . '.pdf'; file_put_contents($tmp_name, file_get_contents(WDCPREFIX . '/' . $cfile->path . $cfile->name)); $pagecount = $pdf->setSourceFile($tmp_name); for ($i = 1; $i <= $pagecount; ++$i) { $tplidx = $pdf->importPage($i); $specs = $pdf->getTemplateSize($tplidx); $pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L'); $pdf->useTemplate($tplidx); } } } } ++$n; } $pdf->Output("/tmp/{$sid}letters.pdf", 'F'); $zip->addFile("/tmp/{$sid}letters.pdf", '/letters.pdf'); } if ($table_post) { $zip->addFile("/tmp/{$sid}post.xls", '/post.xls'); } if ($table_post_our) {
public static function concatFiles($files_path_array) { require_once(Yii::app()->basePath.'/extensions/Fpdf/fpdf.php'); require_once(Yii::app()->basePath.'/extensions/Fpdi/fpdi.php'); $pdf = new FPDI(); foreach ($files_path_array AS $file) { // get the page count $pageCount = $pdf->setSourceFile($file); // 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); } } // Output the new PDF. Here we need to overwrite existing file so first array element is used. $pdf->Output($files_path_array[0],'F'); return $files_path_array[0]; }
function FlyerRendering($config, $inputFile, $outputPath, $outputPostfix, $anschnitt = 0.0) { // Breite der einzelnen Seiten $wRechts = 99.0; //mm $wMitte = 98.0; //mm $wLinks = 97.0; //mm // Community Name $communityNamePositionX = $wLinks + $wMitte + $config['communityNamePositionOffsetX']; //mm $communityNamePositionY = 12.2 + $config['communityNamePositionOffsetY']; //mm // Kontakt Titel $kontaktTitelPositionX = $wLinks + 3.975; //mm $kontaktTitelPositionY = 10.425; //mm $kontaktTitelFontSize = 15.0; //pt // Kontakt Info $kontaktInfoTextPositionX = $kontaktTitelPositionX + 25.0; //mm $kontaktInfoPositionY = $kontaktTitelPositionY + 7.0; //mm $kontaktInfoZeilenOffsetY = 4.7; //mm $kontaktInfoFontSize = 10.9; //pt // Kontakt Logo $kontaktLogoPositionX = $wLinks + $wMitte / 2 - $config['kontaktLogoWidth'] / 2; // Kontakt Footer $kontaktFooterPositionX = $wLinks; //mm $kontaktFooterPositionY = 95.40000000000001; //mm $kontaktFooterWidth = $wMitte; //mm $kontaktFooterFontSize = 10.9; //pt // Output-Dasteiname zusammenbauen $outputFile = $outputPath . DIRECTORY_SEPARATOR . $outputPostfix . '_' . basename($inputFile); // initiate FPDI $pdf = new FPDI(); echo 'Input: ' . basename($inputFile) . PHP_EOL; $pageCount = $pdf->setSourceFile($inputFile); // Importiere Vorder- und Rueckseite $Vorderseite = $pdf->ImportPage(1); $Rueckseite = $pdf->ImportPage(2); // Seitenabmessungen holen $size = $pdf->getTemplateSize($Vorderseite); $dokumentBreite = round($size['w'], 2); $dokumentHoehe = round($size['h'], 2); echo 'Dokumenten Breite: ' . $dokumentBreite . 'mm' . PHP_EOL; echo 'Dokumenten Hoehe: ' . $dokumentHoehe . 'mm' . PHP_EOL; echo 'Anschnitt: ' . $anschnitt . 'mm' . PHP_EOL; // Vorderseite uebernehmen // Anfang eines bloeden Hacks wegen des FooterZeilen-Textes. // Der Footertext laesst sich nur einfügen, wenn die Seite eine A4 Seite ist. // Keine Ahnung warum! $pdf->AddPage('L'); $tplVorderseite = $pdf->importPage(1); $pdf->useTemplate($tplVorderseite); //Margin ist wegen der Rand-Platzierung des Community Names wichtig. $pdf->SetMargins(0, 0, 0); // erstmal alle Fonts laden echo 'Lade Fonts...' . PHP_EOL; $pdf->AddFont('lato-bold'); $pdf->AddFont('lato-regular'); $pdf->AddFont('alternategothic'); // Rendern Titel Text echo 'Verarbeite Titel Text...' . PHP_EOL; $pdf->SetFont('lato-bold'); $pdf->SetFontSize($kontaktTitelFontSize); $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktTitelPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $config['kontaktTitelText'])); // Rendern Info Text echo 'Verarbeite Info Text...' . PHP_EOL; $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetFontSize($kontaktInfoFontSize); foreach ($config['kontaktInfoTexte'] as $a) { $pdf->SetFont('lato-bold'); $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[0])); $pdf->SetFont('lato-regular'); $pdf->SetXY($kontaktInfoTextPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[1])); $kontaktInfoPositionY = $kontaktInfoPositionY + $kontaktInfoZeilenOffsetY; } // Rendern Community Logo echo 'Verarbeite Logo...' . PHP_EOL; $pdf->Image($config['kontaktLogoDateiName'], $kontaktLogoPositionX + $anschnitt, $config['kontaktLogoPositionY'] + $anschnitt, $config['kontaktLogoWidth'], 0); // Rendern Fusszeilen Text echo 'Verarbeite Fusszeile...' . PHP_EOL; $pdf->SetFont('lato-regular'); $pdf->SetFontSize($kontaktFooterFontSize); $pdf->SetTextColor(255, 255, 255); //weiss $pdf->SetXY($kontaktFooterPositionX + $anschnitt, $kontaktFooterPositionY + $anschnitt); $pdf->Cell($kontaktFooterWidth, 0, iconv('UTF-8', 'windows-1252', $config['kontaktFusszeileText']), 0, 0, 'C'); // Rendern Community Name echo 'Verarbeite Community Name...' . PHP_EOL; $pdf->SetFont('alternategothic'); $pdf->SetFontSize($config['communityNameFontSize']); $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetXY($communityNamePositionX + $anschnitt, $communityNamePositionY + $anschnitt); $pdf->MultiCell($wRechts, 10, iconv('UTF-8', 'windows-1252', $config['communityNameText']), 0, 'C'); // Das war's mit dem Editieren // Original PDF Rueckseit uebernehmen $pdf->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplRueckseite = $pdf->importPage(2); $pdf->useTemplate($tplRueckseite); // und erstmal abspeichern echo 'Zwischenspeichern...' . PHP_EOL; $pdf->Output($outputFile); // Hier geht jetzt der Hack wegen der Footerzeile weiter // Die gerade abgespeicherte Datei wird erneut eingelesen // um dann im Seiten-Format der Ursprungsdatei erneut abgespeichert zu werden. // Is' doof, muss aber sein $pdf_2 = new FPDI(); echo 'Erneut laden...' . PHP_EOL; $pageCount = $pdf_2->setSourceFile($outputFile); echo 'Feinschliff...' . PHP_EOL; $Vorderseite_2 = $pdf_2->ImportPage(1); $Rueckseite_2 = $pdf_2->ImportPage(2); $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplVorderseite = $pdf_2->importPage(1); $pdf_2->useTemplate($tplVorderseite); $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplRueckseite = $pdf_2->importPage(2); $pdf_2->useTemplate($tplRueckseite); echo 'Output: ' . basename($outputFile) . PHP_EOL; $pdf_2->Output($outputFile); unset($pdf); unset($pdf_2); }
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); }
define('FPDF_FONTPATH', __DIR__ . '/fpdf/font/'); include_once __DIR__ . '/fpdf/fpdf.php'; include_once __DIR__ . '/fpdi/fpdi.php'; ob_clean(); $file = __DIR__ . '/cupon_001.pdf'; if (!file_exists($file)) { die("File does not exist"); } else { $fullName = $_REQUEST['suname'] . ' ' . $_REQUEST['name'] . ' ' . $_REQUEST['midlname']; $currentDate = currentDate(); $cuponNum = generateCuponNumber(); sendEmail($cuponNum, $currentDate, $fullName); $pdf = new FPDI(); $pdf->setSourceFile($file); $tpl = $pdf->importPage(1); $size = $pdf->getTemplateSize($tpl); $orientation = $size['h'] > $size['w'] ? 'P' : 'L'; $pdf->AddPage($orientation); $pdf->useTemplate($tpl, null, null, $size['w'], $size['h'], true); $pdf->AddFont('AgencyFBCyrillic', '', 'agenfbcyr.php'); $pdf->AddFont('GoodVibesPro', '', 'good_vibes_pro_regular.php'); $pdf->SetXY(41.628, 91.017); $pdf->SetFont('GoodVibesPro', '', 40); $pdf->SetTextColor(184, 153, 106); $pdf->Cell(212.019, 20.814, iconv('UTF-8', 'CP1251', $fullName), 0, 2, 'C'); $pdf->SetXY(56.797, 160.396); $pdf->SetFont('AgencyFBCyrillic', '', 21); $pdf->SetTextColor(32, 22, 0); $pdf->Cell(44.097, 7.173, iconv('UTF-8', 'CP1251', $currentDate), 0, 2, 'C'); $pdf->SetXY(194.263, 160.396); $pdf->SetFont('AgencyFBCyrillic', '', 21);
if (!array_key_exists($id, $app['files'])) { $app->abort(404, 'The PDF file could not be found'); } $file = $app['files'][$id]; $parser = new \Smalot\PdfParser\Parser(); $filepath = dirname(__FILE__) . '/../uploads/' . $file; $document = $parser->parseFile($filepath); $details = $document->getDetails(); $dir = dirname(__FILE__) . '/../uploads/pages/' . $id; if (!file_exists($dir)) { $dirCreate = mkdir($dir); for ($i = 1; $i <= $details['Pages']; $i++) { $fpdi = new FPDI(); $fpdi->setSourceFile($filepath); $tpl = $fpdi->importPage($i); $size = $fpdi->getTemplateSize($tpl); $orientation = $size['h'] > $size['w'] ? 'P' : 'L'; $fpdi->AddPage($orientation); $fpdi->useTemplate($tpl, null, null, $size['w'], $size['h'], true); try { $filename = dirname(__FILE__) . '/../uploads/pages/' . $id . '/' . $i; $fpdi->Output($filename . '.pdf', "F"); $imagick = new Imagick(); $imagick->readimage($filename . '.pdf'); $imagick->setImageFormat('jpeg'); $imagick->setCompressionQuality(20); $imagick->writeImage($filename . '.jpg'); $imagick->clear(); $imagick->destroy(); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n";
function FlyerRendering($inputFile, $outputPostfix, $anschnitt) { /*------------------------------------------------------------------------------------ * Bitte tragt hier eure lokalen Freifunk Daten ein. *------------------------------------------------------------------------------------ * * Hinweiss Community-Logo: * Moegliche Format sind GIF, JPG und PNG. * * Laenge des Community Namen: * Falls der Community-Name zu lang ist und es zu einem Zeilenumbruch kommt, * dann sollte $communityNameFontSize verkleiner werden * -------------------------------------------------------------------------------------*/ // Community Name fuer Hauptseite $communityNameText = "Freifunk Duckburg"; $communityNameFontSize = 48.0; //in pt $communityNamePositionOffsetX = 0.0; // +/- in mm $communityNamePositionOffsetY = 0.0; // +/- in mm // Logo auf Kontaktseite $kontaktLogoDateiName = "logo-template.png"; $kontaktLogoWidth = 66.25; //in mm // Muss kleiner 98.0 mm sein! Hier bitte die gewuenschte Breite des Logos auf dem Flyer eintragen. $kontaktLogoPositionY = 47.0; //in mm // Die Hoeheneinstellung ist etwas frickelig. Es klappt aber :-) // Texte fuer Seite mit Kontaktdaten $kontaktTitelText = "Kontakt"; $kontaktInfoTexte = [["Webseite", "http://ffdb.freifunk.net"], ["Mail", "*****@*****.**"], ["Mailingliste", "*****@*****.**"], ["Twitter", "@FreiFunkDB"], ["Treffen", "Jeden zweiten Montag"], ["", "Und wo? Siehe unsere Webseite"], ["", ""], ["", ""]]; // Text Fusszeile $kontaktFusszeileText = "Freifunk Duckburg e.V."; /*----------------------------------------------------------------------------------- * * Ab hier sollte nichts mehr geander werden! * ------------------------------------------------------------------------------------*/ // Breite der einzelnen Seiten $wRechts = 99.0; //mm $wMitte = 98.0; //mm $wLinks = 97.0; //mm // Community Name $communityNamePositionX = $wLinks + $wMitte + $communityNamePositionOffsetX; //mm $communityNamePositionY = 12.2 + $communityNamePositionOffsetY; //mm // Kontakt Titel $kontaktTitelPositionX = $wLinks + 3.975; //mm $kontaktTitelPositionY = 10.425; //mm $kontaktTitelFontSize = 15.0; //pt // Kontakt Info $kontaktInfoTextPositionX = $kontaktTitelPositionX + 25.0; //mm $kontaktInfoPositionY = $kontaktTitelPositionY + 7.0; //mm $kontaktInfoZeilenOffsetY = 4.7; //mm $kontaktInfoFontSize = 10.9; //pt // Kontakt Logo $kontaktLogoPositionX = $wLinks + $wMitte / 2 - $kontaktLogoWidth / 2; // Kontakt Footer $kontaktFooterPositionX = $wLinks; //mm $kontaktFooterPositionY = 95.40000000000001; //mm $kontaktFooterWidth = $wMitte; //mm $kontaktFooterFontSize = 10.9; //pt echo "\n"; // Output-Dasteiname zusammenbauen $outputFile = $outputPostfix . "-" . $inputFile; // initiate FPDI $pdf = new FPDI(); echo "Input: {$inputFile}\n"; $pageCount = $pdf->setSourceFile($inputFile); // Importiere Vorder- und Rueckseite $Vorderseite = $pdf->ImportPage(1); $Rueckseite = $pdf->ImportPage(2); // Seitenabmessungen holen $size = $pdf->getTemplateSize($Vorderseite); $dokumentBreite = round($size['w'], 2); $dokumentHoehe = round($size['h'], 2); echo "Dokumenten Breite: {$dokumentBreite} mm\n"; echo "Dokumenten Hoehe: {$dokumentHoehe} mm\n"; echo "Anschnitt: {$anschnitt} mm\n"; // Vorderseite uebernehmen // Anfang eines bloeden Hacks wegen des FooterZeilen-Textes. // Der Footertext laesst sich nur einfügen, wenn die Seite eine A4 Seite ist. // Keine Ahnung warum! $pdf->AddPage('L'); $tplVorderseite = $pdf->importPage(1); $pdf->useTemplate($tplVorderseite); //Margin ist wegen der Rand-Platzierung des Community Names wichtig. $pdf->SetMargins(0, 0, 0); // erstmal alle Fonts laden echo "Lade Fonts...\n"; $pdf->AddFont('lato-bold'); $pdf->AddFont('lato-regular'); $pdf->AddFont('alternategothic'); // Rendern Titel Text echo "Verarbeite Titel Text...\n"; $pdf->SetFont('lato-bold'); $pdf->SetFontSize($kontaktTitelFontSize); $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktTitelPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $kontaktTitelText)); // Rendern Info Text echo "Verarbeite Info Text...\n"; $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetFontSize($kontaktInfoFontSize); foreach ($kontaktInfoTexte as $a) { $pdf->SetFont('lato-bold'); $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[0])); $pdf->SetFont('lato-regular'); $pdf->SetXY($kontaktInfoTextPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt); $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[1])); $kontaktInfoPositionY = $kontaktInfoPositionY + $kontaktInfoZeilenOffsetY; } // Rendern Community Logo echo "Verarbeite Logo...\n"; $pdf->Image($kontaktLogoDateiName, $kontaktLogoPositionX + $anschnitt, $kontaktLogoPositionY + $anschnitt, $kontaktLogoWidth, 0); // Rendern Fusszeilen Text echo "Verarbeite Fusszeile...\n"; $pdf->SetFont('lato-regular'); $pdf->SetFontSize($kontaktFooterFontSize); $pdf->SetTextColor(255, 255, 255); //weiss $pdf->SetXY($kontaktFooterPositionX + $anschnitt, $kontaktFooterPositionY + $anschnitt); $pdf->Cell($kontaktFooterWidth, 0, iconv('UTF-8', 'windows-1252', $kontaktFusszeileText), 0, 0, 'C'); // Rendern Community Name echo "Verarbeite Community Name...\n"; $pdf->SetFont('alternategothic'); $pdf->SetFontSize($communityNameFontSize); $pdf->SetTextColor(0, 0, 0); //schwarz $pdf->SetXY($communityNamePositionX + $anschnitt, $communityNamePositionY + $anschnitt); $pdf->MultiCell($wRechts, 10, iconv('UTF-8', 'windows-1252', $communityNameText), 0, 'C'); // Das war's mit dem Editieren // Original PDF Rueckseit uebernehmen $pdf->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplRueckseite = $pdf->importPage(2); $pdf->useTemplate($tplRueckseite); // und erstmal abspeichern echo "Zwischenspeichern...\n"; $pdf->Output($outputFile); // Hier geht jetzt der Hack wegen der Footerzeile weiter // Die gerade abgespeicherte Datei wird erneut eingelesen // um dann im Seiten-Format der Ursprungsdatei erneut abgespeichert zu werden. // Is' doof, muss aber sein $pdf_2 = new FPDI(); echo "Erneut laden...\n"; $pageCount = $pdf_2->setSourceFile($outputFile); echo "Feinschliff...\n"; $Vorderseite_2 = $pdf_2->ImportPage(1); $Rueckseite_2 = $pdf_2->ImportPage(2); $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplForderseite = $pdf_2->importPage(1); $pdf_2->useTemplate($tplForderseite); $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe)); $tplRueckseite = $pdf_2->importPage(2); $pdf_2->useTemplate($tplRueckseite); echo "Output: {$outputFile}\n"; $pdf_2->Output($outputFile); unset($pdf); unset($pdf_2); }
public function pdfImg($file) { require_once $_SERVER['DOCUMENT_ROOT'] . 'tyj_oa/Public/fpdf/fpdf.php'; require_once $_SERVER['DOCUMENT_ROOT'] . 'tyj_oa/Public/fpdi/fpdi.php'; $pdf = new FPDI(); $pageCount = $pdf->setSourceFile($file); for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { $templateId = $pdf->importPage($pageNo); $size = $pdf->getTemplateSize($templateId); if ($size['w'] > $size['h']) { $pdf->AddPage('L', array($size['w'], $size['h'])); } else { $pdf->AddPage('P', array($size['w'], $size['h'])); } if ($pageNo == $pageCount) { $img = $_SERVER['DOCUMENT_ROOT'] . get_save_url() . D('user')->where('id = ' . get_user_id())->getField('pic_yin'); $pdf->Image($img, 150, 250, 0, 20); } $pdf->useTemplate($templateId); $pdf->SetFont('Helvetica'); $pdf->SetXY(5, 5); } $pdf->Output($file); }
/** * Render a certificate * * @param object $user User * @param string $path Path to store rendered file to * @return boolean True on success, false on error */ public function render($user = null, $path = null) { if (!$user) { $user = \User::getRoot(); } if (!class_exists('\\Components\\Courses\\Models\\Course')) { require_once __DIR__ . DS . 'course.php'; } $course = Course::getInstance($this->get('course_id')); require_once PATH_CORE . DS . 'libraries' . DS . 'fpdf16' . DS . 'fpdf.php'; require_once PATH_CORE . DS . 'libraries' . DS . 'fpdi' . DS . 'fpdi.php'; // Get the pdf and draw on top of it $pdf = new \FPDI(); $pageCount = $pdf->setSourceFile($this->path('system') . DS . 'certificate.pdf'); $tplIdx = $pdf->importPage(1); $size = $pdf->getTemplateSize($tplIdx); $pdf->AddPage('L', array($size['h'], $size['w'])); $pdf->useTemplate($tplIdx, 0, 0, 0, 0, true); $pdf->SetFillColor(0, 0, 0); foreach ($this->properties()->elements as $element) { // Convert pixel values to percents $element->x = $element->x / $this->properties()->width; $element->y = $element->y / $this->properties()->height; $element->w = $element->w / $this->properties()->width; $element->h = $element->h / $this->properties()->height; $val = ''; switch ($element->id) { case 'name': case 'email': case 'username': $val = $user->get($element->id); break; case 'course': $val = $course->get('title'); break; case 'offering': $val = $course->offering()->get('title'); break; case 'section': $val = $course->offering()->section()->get('title'); break; case 'date': $val = \Date::of('now')->format(Lang::txt('d M Y')); break; } $pdf->SetFont('Arial', '', 30); //($element->h * $size['h'])); $pdf->setXY($element->x * $size['w'], $element->y * $size['h']); // - ($element->h * $size['h']) $pdf->Cell($element->w * $size['w'], $element->h * $size['h'], $val, '', 1, 'C'); } if (!$path) { $pdf->Output(); die; } $pdf->Output($path, 'F'); return true; }
function watermark_and_sent(stdClass $issuedcert) { global $CFG, $USER, $COURSE, $DB, $PAGE; if ($issuedcert->haschange) { //This issue have a haschange flag, try to reissue if (empty($issuedcert->timedeleted)) { require_once $CFG->dirroot . '/mod/simplecertificate/locallib.php'; try { // Try to get cm $cm = get_coursemodule_from_instance('simplecertificate', $issuedcert->certificateid, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); //Must set a page context to issue .... $PAGE->set_context($context); $simplecertificate = new simplecertificate($context, null, null); $file = $simplecertificate->get_issue_file($issuedcert); } catch (moodle_exception $e) { // Only debug, no errors debugging($e->getMessage(), DEBUG_DEVELOPER, $e->getTrace()); } } else { //Have haschange and timedeleted, somehting wrong, it will be impossible to reissue //add wraning debugging("issued certificate [{$issuedcert->id}], have haschange and timedeleted"); } $issuedcert->haschange = 0; $DB->update_record('simplecertificate_issues', $issuedcert); } if (empty($file)) { $fs = get_file_storage(); if (!$fs->file_exists_by_hash($issuedcert->pathnamehash)) { print_error(get_string('filenotfound', 'simplecertificate', '')); } $file = $fs->get_file_by_hash($issuedcert->pathnamehash); } $canmanage = false; if (!empty($COURSE)) { $canmanage = has_capability('mod/simplecertificate:manage', context_course::instance($COURSE->id)); } if ($canmanage || !empty($USER) && $USER->id == $issuedcert->userid) { send_stored_file($file, 0, 0, true); } else { require_once $CFG->libdir . '/pdflib.php'; require_once $CFG->dirroot . '/mod/simplecertificate/lib/fpdi/fpdi.php'; // copy to a tmp file $tmpfile = $file->copy_content_to_temp(); // TCPF doesn't import files yet, so i must use FPDI $pdf = new FPDI(); $pageCount = $pdf->setSourceFile($tmpfile); 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'])); // Font size 1/3 Height if it landscape $fontsize = $size['h'] / 3; } else { $pdf->AddPage('P', array($size['w'], $size['h'])); // Font size 1/3 Width if it portrait $fontsize = $size['w'] / 3; } // use the imported page $pdf->useTemplate($templateId); // Calculating the rotation angle $rotAngle = atan($size['h'] / $size['w']) * 180 / pi(); // Find the middle of the page to use as a pivot at rotation. $mX = $size['w'] / 2; $mY = $size['h'] / 2; // Set the transparency of the text to really light $pdf->SetAlpha(0.25); $pdf->StartTransform(); $pdf->Rotate($rotAngle, $mX, $mY); $pdf->SetFont("freesans", "B", $fontsize); $pdf->SetXY(0, $mY); $boder_style = array('LTRB' => array('width' => 2, 'dash' => $fontsize / 5, 'cap' => 'round', 'join' => 'round', 'phase' => $fontsize / $mX)); $pdf->Cell($size['w'], $fontsize, get_string('certificatecopy', 'simplecertificate'), $boder_style, 0, 'C', false, '', 4, true, 'C', 'C'); $pdf->StopTransform(); // Reset the transparency to default $pdf->SetAlpha(1); } // Set protection seems not work, so comment // $pdf->SetProtection(array('print', 'modify', 'print-high'),null, random_string(), '1',null); // For DEGUG // $pdf->Output($file->get_filename(), 'I'); // Save and send tmpfiles $pdf->Output($tmpfile, 'F'); send_temp_file($tmpfile, $file->get_filename()); } }
/** * 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."); endif; $fpdi = new FPDI; //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); $fpdi->AddPage('P', 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."); endif; $size = $fpdi->getTemplateSize($template); $fpdi->AddPage('P', 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)!==false) { return true; } else { throw new exception("Error outputting PDF to '$outputmode'."); return false; } } }
/** * Append a PDF to this PDF * * @access public * @param \Skeleton\File\Pdf\Pdf $pdf */ public function append(\Skeleton\File\Pdf\Pdf $pdf) { $result_pdf = new \FPDI(); if (!file_exists($this->get_path())) { throw new \Exception('Cannot append file. Filename "' . $this->get_path() . '" not found'); } $page_count = $result_pdf->setSourceFile($this->get_path()); /** * Add the pages from this PDF */ for ($i = 1; $i <= $page_count; $i++) { $templateId = $result_pdf->importPage($i); $size = $result_pdf->getTemplateSize($templateId); // create a page (landscape or portrait depending on the imported page size) if ($size['w'] > $size['h']) { $result_pdf->AddPage('L', [$size['w'], $size['h']]); } else { $result_pdf->AddPage('P', [$size['w'], $size['h']]); } // use the imported page $result_pdf->useTemplate($templateId); } /** * Add the pages from the incoming PDF */ $page_count = $result_pdf->setSourceFile($pdf->get_path()); for ($i = 1; $i <= $page_count; $i++) { $templateId = $result_pdf->importPage($i); $size = $result_pdf->getTemplateSize($templateId); // create a page (landscape or portrait depending on the imported page size) if ($size['w'] > $size['h']) { $result_pdf->AddPage('L', [$size['w'], $size['h']]); } else { $result_pdf->AddPage('P', [$size['w'], $size['h']]); } // use the imported page $result_pdf->useTemplate($templateId); } $content = $result_pdf->Output('ignored', 'S'); file_put_contents($this->get_path(), $content); }
print "<meta http-equiv=\"Refresh\" content=\"0;URL=MainPage.php\">"; exit; } } if ($_SESSION['status'] == "admin") { $query = "SELECT * FROM `abiturients` WHERE `ab_id` = '" . $id . "'"; $sql = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($sql) == 1) { $row = mysql_fetch_assoc($sql); } } $pdf = new FPDI(); $pageCount = $pdf->setSourceFile("img/ugoda2014.pdf"); $pageNo = 1; $templateId = $pdf->importPage($pageNo); $size = $pdf->getTemplateSize($templateId); $pdf->AddPage('P', array($size['w'], $size['h'])); $pdf->useTemplate($templateId); $pdf->AddFont('Times', '', 'times.php'); $pdf->SetFont('Times', '', 10); $pdf->SetTextColor(0, 0, 0); $pdf->SetFontSize(11); $pdf->SetXY(35, 61); $pdf->Write(5, $row['lastname'] . " " . $row['firstname'] . " " . $row['patronymic']); $pdf->SetXY(55, 70); if ($row['type'] == "mag") { $pdf->Write(5, "6-й курс, " . $row['faculty']); } if ($row['type'] == "spc") { $pdf->Write(5, "5-й курс " . $row['faculty']); }
public function leerarchivopdf(Request $request, $id) { /*$pureba=fopen($patharchivo, "rb") or die ("Error al leer"); while (!feof($prueba)) { $linea=fgets($prueba); $salto_de_linea=nl2br($linea); echo $salto_de_linea; } fclose($prueba);*/ # incluimos la libreria fdpf # http://www.fpdf.org/ require_once 'fpdf17/fpdf.php'; # incluimos la libreria fpdi # http://www.setasign.com/products/fpdi/about/ require_once 'FPDI-1.5.2/fpdi.php'; # inicializamos el objeto $pdf = new FPDI(); # definimos el archivo pdf a leer. Nos devuel el numero de paginas $paginas = $pdf->setSourceFile('linux.pdf'); $pagina = 2; # importamos cada una de las paginas $templateId = $pdf->importPage($pagina); # obtenemos el temaño de cada hoja $size = $pdf->getTemplateSize($templateId); // create a page definiendo el formato y tamaños if ($size['w'] > $size['h']) { $pdf->AddPage('L', array($size['w'], $size['h'])); } else { $pdf->AddPage('P', array($size['w'], $size['h'])); } $pdf->useTemplate($templateId); # devolvemos el documento $pdf->Output(); }