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(); }
function renderPDF($id,$mode) { $pdf = new FPDI(); $db_catalogue_pages = new catalogue_pages; $db_catalogue_pages->get_one_catalogue_pages($id); $db_catalogue_pages->load(); $template_id = $db_catalogue_pages->get_pag_template(); $template = new catalogue_templates; $template->getOne($template_id); $template->load(); $pdf->addPage("Landscape","Letter"); $db_catalogue_objects = new catalogue_objects; $db_catalogue_objects->get_all($id); $pdf->SetFont('Arial','',14); $pdf->Image("pdftemplates/".$template->get_tem_file().".jpg",0,0); while($db_catalogue_objects->load()) { $var = explode("_",$db_catalogue_objects->get_obj_var()); if($var[0] == "image") { if(file_exists($db_catalogue_objects->field->obj_image)) $pdf->Image($db_catalogue_objects->field->obj_image,($db_catalogue_objects->field->obj_posx*0.353),($db_catalogue_objects->field->obj_posy*0.353),"50","50"); } $pdf->SetXY($db_catalogue_objects->field->obj_posx*0.353,($db_catalogue_objects->field->obj_posy*0.35) + 60); $pdf->Write(5,$db_catalogue_objects->field->obj_text); } $db_catalogue_objects->close(); $db_catalogue_pages->close(); //if($mode=="I") $pdf->Output("page_".$id.".pdf", "I"); //else $pdf->Output("pages/page_".$id.".pdf", "F"); $pdf->Output("pages/page_".$id.".pdf", "F"); }
public function view_sign_pce(){ require_once('./assets/fpdf17/fpdf.php'); require_once('./assets/fpdf17/fpdi.php'); $pce_id=$this->uri->segment(3,''); // init pce data $pce_dat=$this->m_pce->get_pce_by_id($pce_id); $project=$this->m_project->get_project_by_id($pce_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; } $client_service_sign_dat=$this->m_user->get_user_by_login_name($pce_dat->csd_sign); $client_service_sign_filename="no"; if (isset($client_service_sign_dat->sign_filename)) { $client_service_sign_filename=$client_service_sign_dat->sign_filename; } $finance_sign_dat=$this->m_user->get_user_by_login_name($pce_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/".$pce_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'); $all_three_sign=0; if ($finance_sign_filename!="no"&&$finance_sign_filename!=""&&$finance_sign_filename!=null) { $pdf->Image("./media/sign_photo/".$finance_sign_filename,152,242,40,0); $c_time=$pce_dat->fc_sign_time; $pdf->SetXY(162,269); $pdf->Cell(30,5,iconv( 'UTF-8','cp874' , date("d",$c_time)." ".date("m",$c_time)." ".date("Y",$c_time)),0,0); $all_three_sign+=1; } if ($client_service_sign_filename!="no"&&$client_service_sign_filename!=""&&$client_service_sign_filename!=null) { $pdf->Image("./media/sign_photo/".$client_service_sign_filename,86,242,40,0); $c_time=$pce_dat->csd_sign_time; $pdf->SetXY(96,269.5); $pdf->Cell(30,5,iconv( 'UTF-8','cp874' , date("d",$c_time)." ".date("m",$c_time)." ".date("Y",$c_time)),0,0); $all_three_sign+=1; } if ($ae_sign_filename!="no"&&$ae_sign_filename!=""&&$ae_sign_filename!=null) { $pdf->Image("./media/sign_photo/".$ae_sign_filename,20,242,40,0); $c_time=$pce_dat->cs_sign_time; $pdf->SetXY(30,270); $pdf->Cell(30,5,iconv( 'UTF-8','cp874' , date("d",$c_time)." ".date("m",$c_time)." ".date("Y",$c_time)),0,0); $all_three_sign+=1; } //if ($all_three_sign==3) { $pdf->Image("./img/Client_Approval_Tag.png",110,204.2,35,0); //} //$pdf->Image("images/play.png",100,100,100,0); } $new_filename=$pce_dat->pce_no."_A.pdf"; // Output the new PDF //@unlink("./media/real_pdf/".$new_filename); $pdf->Output($new_filename,"I"); //redirect("media/real_pdf/".$new_filename); }
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); }
$pdf->Cell(0, 0, $row["NROFACTURA"]); $pdf->Ln(5.8); $pdf->Cell(80); $pdf->Cell(0, 0, $row["MONTOIMPONIBLE"]); $pdf->Ln(5.8); $pdf->Cell(80); $pdf->Cell(0, 0, $row["ALICUOTA"]); $pdf->Ln(5.2); $pdf->Cell(80); $pdf->Cell(0, 0, $row["RETENCION"]); $pdf->Ln(5.2); $pdf->Cell(80); $pdf->Cell(0, 0, $row["RETENCION"]); $pdf->SetFont("Arial", "", 10); $pdf->Ln(40); $pdf->Cell(150); $pdf->Cell(0, 0, $rowFirmante["FI_FIRMANTE"]); $pdf->Ln(5); $pdf->Cell(148.4); $pdf->Cell(0, 0, $rowFirmante["FI_CARACTER"]); $pdf->Image("http://extranet-desa.artprov.com.ar/modules/usuarios_registrados/agentes_comerciales/comisiones/images/firma.jpg", 156, 176, 34, 31); //336, 313 $pdf->Output(); ?>
public function createScreeningPdf($hash) { $screening_entry_model = ScreeningEntry::findOne(['hash' => $hash]); $screening_form_model = ScreeningForm::findOne(['id' => $screening_entry_model->screening_form_id]); $subject_model = Subject::findOne(['id' => $screening_entry_model->subject_id]); $count = 1; //$permissions = \SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT ; $this->_font = 'Helvetica'; //class_exists('TCPDF', true); // trigger Composers autoloader to load the TCPDF class $pdf = new \FPDI(); $pdf->SetAutoPageBreak(true); // add a page $pdf->SetTopMargin(30); $pdf->AddPage(); $pdf->setSourceFile(\yii::$app->basePath . "/../letterhead-mini-header.pdf"); $tplIdx = $pdf->importPage(1); // use the imported page and place it at point 10,10 with a width of 100 mm $pdf->useTemplate($tplIdx, 0, 0); $pdf->SetFont($this->_font, '', 9); $pdf->SetXY(10, 6); $pdf->Cell(0, 3, 'Confidential - Participant screening form'); $pdf->SetFont($this->_font, '', 12); $pdf->SetXY(10, 14); $pdf->MultiCell(150, 3, yii::$app->DateComponent->timestampToUkDate($screening_entry_model->created_at), 0, 'R'); $pdf->MultiCell(100, 3, $screening_entry_model->screening_form_title, 0, ''); $pdf->Ln(); $pdf->SetFont($this->_font, '', 9); $pdf->Cell(100, 4, sprintf('Participant: %s %s (dob %s)', $screening_entry_model->subject->first_name, $screening_entry_model->subject->last_name, yii::$app->DateComponent->isoToUkDate($screening_entry_model->subject->dob))); $pdf->Cell(50, 4, sprintf('Identifier: %s', $screening_entry_model->subject->cubric_id), 0, '', 'R'); $pdf->Ln(); $pdf->Cell(100, 4, sprintf('Researcher: %s %s (project %s)', $screening_entry_model->researcher->first_name, $screening_entry_model->researcher->last_name, $screening_entry_model->project->code)); $pdf->Cell(50, 4, sprintf('Resource: %s', $screening_entry_model->resource_title), 0, '', 'R'); $pdf->SetXY(10, 38); $pdf->SetFont($this->_font, '', 12); $pdf->Cell(150, 4, sprintf('Responses')); $pdf->SetFont($this->_font, '', 9); $pdf->Ln(); foreach (yii::$app->screeningresponse->getResponses($hash) as $response) { if (strlen($response['caption']) > 0) { $pdf->Ln(); $pdf->MultiCell(180, 4, sprintf('%s ', $response['caption']), 0, 'U'); $count = 1; } $pdf->MultiCell(180, 4, sprintf('%s. %s ', $count, $response['content'])); $pdf->SetFont($this->_font, 'B', 9); if ($response['response'] === null) { $response['response'] = 'Not specified / Unknown.'; } $pdf->MultiCell(180, 4, sprintf('%s ', $response['response'])); $pdf->SetFont($this->_font, '', 9); $count++; $pdf->Ln(); } $pdf->Ln(); $pdf->SetFont($this->_font, '', 12); $pdf->Cell(180, 4, sprintf('Signatures')); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont($this->_font, '', 9); $pdf->Cell(100, 4, 'Participant '); $pdf->Cell(100, 4, 'Researcher '); $pdf->Ln(); $pdf->Ln(); $currentX = $pdf->GetX(); $currentY = $pdf->GetY(); $pdf->Image(sprintf('/tmp/subject-%s.png', $hash), $currentX, $currentY); $currentX = $pdf->GetX(); $pdf->Image(sprintf('/tmp/researcher-%s.png', $hash), $currentX + 100, $currentY); // now write some text above the imported page // NOW SET ScreeningEntry::progress_id = PUBLISHED so it cannot be edited again. // $pdfData = $pdf->Output('S'); // create a writer // create a Http writer //$writer = new \SetaPDF_Core_Writer_Http("fpdf-sign-demo.pdf", true); // load document by filename //$document = new \SetaPDF_Core_Document::loadByString($pdfData, $writer); //$document = new \SetaPDF_Core_Reader_File($pdf->Output(), $writer); $writer = new \SetaPDF_Core_Writer_File("/Users/Spiro/tmp/myPDF.pdf"); $document = \SetaPDF_Core_Document::loadByString($pdf->Output("S"), $writer); // let's prepare the temporary file writer: \SetaPDF_Core_Writer_TempFile::setTempDir("/tmp/"); // create a signer instance for the document $signer = new \SetaPDF_Signer($document); // add a field with the name "Signature" to the top left of page 1 $signer->addSignatureField(\SetaPDF_Signer_SignatureField::DEFAULT_FIELD_NAME, 1, \SetaPDF_Signer_SignatureField::POSITION_LEFT_BOTTOM, array('x' => 10, 'y' => 10), 180, 50); // set some signature properties $signer->setReason('Integrity'); $signer->setLocation('CUBRIC'); $signer->setContactInfo('+44 2920 703859'); // ccreate an OpenSSL module instance $module = new \SetaPDF_Signer_Signature_Module_OpenSsl(); // set the sign certificate $module->setCertificate(file_get_contents("/Users/spiro/Sites/projects/certs/certificate.pem")); // set the private key for the sign certificate $module->setPrivateKey(array(file_get_contents("/Users/spiro/Sites/projects/certs/key.pem"), "")); // create a Signature appearance $visibleAppearance = new \SetaPDF_Signer_Signature_Appearance_Dynamic($module); // choose a document to get the background from and convert the art box to an xObject $backgroundDocument = \SetaPDF_Core_Document::loadByFilename(Yii::getAlias('@frontend/web/img/cubric-logo.pdf')); $backgroundXObject = $backgroundDocument->getCatalog()->getPages()->getPage(1)->toXObject($document); // format the date $visibleAppearance->setShowFormat(\SetaPDF_Signer_Signature_Appearance_Dynamic::CONFIG_DATE, 'd-m-Y H:i:s'); // disable the distinguished name $visibleAppearance->setShow(\SetaPDF_Signer_Signature_Appearance_Dynamic::CONFIG_DISTINGUISHED_NAME, false); // set the background with 50% opacity $visibleAppearance->setGraphic($backgroundXObject, 0.5); //$visibleAppearance->setBackgroundLogo($backgroundXObject, .5); // sign/certify the document // define the appearance $signer->setAppearance($visibleAppearance); $signer->sign($module); if (file_exists(sprintf('/tmp/subject-%s.png', $hash))) { } // unlink(sprintf('/tmp/subject-%s.png' , $hash)); if (file_exists(sprintf('/tmp/researcher-%s.png', $hash))) { } // unlink(sprintf('/tmp/researcher-%s.png' , $hash)); return true; }
$contrat_PDF->CellFit( 70 , $hauteur_ligne , To::pdf('Exemplaire à conserver') , 1 /*bordure*/ , 2 /*br*/ , 'C' /*alignement*/ , TRUE /*remplissage*/ ); } // référence du connecteur $contrat_PDF->SetXY(40,116); $contrat_PDF->CellFit( 100 , $hauteur_ligne , To::pdf($connecteur_ref) , 0 /*bordure*/ , 2 /*br*/ , 'L' /*alignement*/ , FALSE /*remplissage*/ ); // connecteur $contrat_PDF->SetXY(93,142); $contrat_PDF->CellFit( 100 , $hauteur_ligne , To::pdf('"'.$DB_ROW['connexion_nom'].'"') , 0 /*bordure*/ , 2 /*br*/ , 'L' /*alignement*/ , FALSE /*remplissage*/ ); // date fin $contrat_PDF->SetXY(90,216.5); $contrat_PDF->CellFit( 100 , $hauteur_ligne , To::pdf(convert_date_mysql_to_french($DB_ROW['convention_date_fin']).'.') , 0 /*bordure*/ , 2 /*br*/ , 'L' /*alignement*/ , FALSE /*remplissage*/ ); // date création $contrat_PDF->SetXY(121,237.5); $contrat_PDF->CellFit( 80 , $hauteur_ligne , To::pdf(convert_date_mysql_to_french($DB_ROW['convention_creation']).'.') , 0 /*bordure*/ , 2 /*br*/ , 'L' /*alignement*/ , FALSE /*remplissage*/ ); // signature $contrat_PDF->Image( CHEMIN_DOSSIER_WEBSERVICES.'sesamath_ent_conventions_sacoche_etablissement_signature.png' , 30 /*x*/ , 254 /*y*/ , 254*0.2 /*largeur*/ , 158*0.2 /*hauteur*/ , 'PNG' ); // ajouter une page ; y importer la page 2 ; l'utiliser comme support $contrat_PDF->AddPage(); $tplIdx = $contrat_PDF->importPage(2); $contrat_PDF->useTemplate($tplIdx); } // On enregistre la sortie PDF $contrat_fichier_nom = 'convention_contrat_'.fabriquer_fin_nom_fichier__date_et_alea().'.pdf'; FileSystem::ecrire_sortie_PDF( CHEMIN_DOSSIER_EXPORT.$contrat_fichier_nom , $contrat_PDF ); // // Imprimer la facture. // $facture_PDF = new FPDI( NULL /*make_officiel*/ , 'portrait' /*orientation*/ , 15 /*marge_gauche*/ , 15 /*marge_droite*/ , 10 /*marge_haut*/ , 15 /*marge_bas*/ , 'oui' /*couleur*/ , 'non' /*legende*/ , NULL /*filigrane*/ ); $facture_PDF->setSourceFile(CHEMIN_DOSSIER_WEBSERVICES.'sesamath_ent_convention_sacoche_etablissement_facture.pdf'); // ajouter une page ; y importer la page 1 ; l'utiliser comme support $facture_PDF->AddPage();
$logo = $dir_fax_temp . '/' . $remote_filename; } else { unset($logo); } } else { $logo = $dir_fax_temp . '/' . $remote_filename; } } else { unset($logo); } } $display_logo = true; } } if ($display_logo) { $pdf->Image($logo, 0.5, 0.4, 2.5, 0.9, null, null, 'N', true, 300, null, false, false, 0, true); } else { //set position for header text, if enabled $pdf->SetXY($x + 0.5, $y + 0.4); } //header if ($fax_header != '') { $pdf->SetLeftMargin(0.5); $pdf->SetFont($pdf_font, "", 10); $pdf->Write(0.3, $fax_header); } //fax, cover sheet $pdf->SetTextColor(0, 0, 0); $pdf->SetFont($pdf_font, "B", 55); $pdf->SetXY($x + 4.55, $y + 0.25); $pdf->Cell($x + 3.5, $y + 0.4, $text['label-fax-fax'], 0, 0, 'R', false, null, 0, false, 'T', 'T');
$contrat_PDF->CellFit(70, $hauteur_ligne, To::pdf('Exemplaire à conserver'), 1, 2, 'C', TRUE); } // référence du connecteur $contrat_PDF->SetXY(40, 116); $contrat_PDF->CellFit(100, $hauteur_ligne, To::pdf($connecteur_ref), 0, 2, 'L', FALSE); // connecteur $contrat_PDF->SetXY(93, 142); $contrat_PDF->CellFit(100, $hauteur_ligne, To::pdf('"' . $DB_ROW['connexion_nom'] . '"'), 0, 2, 'L', FALSE); // date fin $contrat_PDF->SetXY(90, 216.5); $contrat_PDF->CellFit(100, $hauteur_ligne, To::pdf(convert_date_mysql_to_french($DB_ROW['convention_date_fin']) . '.'), 0, 2, 'L', FALSE); // date création $contrat_PDF->SetXY(121, 237.5); $contrat_PDF->CellFit(80, $hauteur_ligne, To::pdf(convert_date_mysql_to_french($DB_ROW['convention_creation']) . '.'), 0, 2, 'L', FALSE); // signature $contrat_PDF->Image(CHEMIN_DOSSIER_WEBSERVICES . 'sesamath_ent_conventions_sacoche_etablissement_signature.png', 30, 254, 254 * 0.2, 158 * 0.2, 'PNG'); // ajouter une page ; y importer la page 2 ; l'utiliser comme support $contrat_PDF->AddPage(); $tplIdx = $contrat_PDF->importPage(2); $contrat_PDF->useTemplate($tplIdx); } // On enregistre la sortie PDF $contrat_fichier_nom = 'convention_contrat_' . fabriquer_fin_nom_fichier__date_et_alea() . '.pdf'; FileSystem::ecrire_sortie_PDF(CHEMIN_DOSSIER_EXPORT . $contrat_fichier_nom, $contrat_PDF); // // Imprimer la facture. // $facture_PDF = new FPDI(NULL, 'portrait', 15, 15, 10, 15, 'oui', 'non', NULL); $facture_PDF->setSourceFile(CHEMIN_DOSSIER_WEBSERVICES . 'sesamath_ent_convention_sacoche_etablissement_facture.pdf'); // ajouter une page ; y importer la page 1 ; l'utiliser comme support $facture_PDF->AddPage();
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 generatepdfAction(command $commande) { $request = $this->get('request'); $tools = $this->get('tools.utils'); $session = $request->getSession(); if ($session->has('tpl')) { $tpl = $commande->getToprint(); $pdffile = ""; foreach ($tpl as $key => $elemnt) { foreach ($elemnt as $val) { $prod = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($val['id']); $template = $prod->getTpl(); $tplpdf = str_replace("../", "", $template->getPdf()); $pdffile = $this->get('kernel')->getRootDir() . '/../web/' . $tplpdf; } } $custom_layout = array(85, 55); $orientation = 'L'; $pdf = new \FPDI($orientation, 'mm', $custom_layout, true, 'UTF-8', false); $pdf->setPageOrientation($orientation); $pdf->SetMargins(0, 0, 0); $pdf->SetAutoPageBreak(true, 0); $pdf->setFontSubsetting(false); $pdf->AddPage($orientation); // echo "<pre>";print_r($pdf->getMargins());exit; $pdf->setSourceFile($pdffile); $_tplIdx = $pdf->importPage(1); $size = $pdf->useTemplate($_tplIdx, 0, 0, 85, 55, true); $idd = ""; $i = 0; $oldx = 0; $oldy = 0; foreach ($elemnt as $value) { //if($i==0) if ($idd != $value['id'] && $value['value'] != "") { $pdf->SetPageMark(); if (substr($value['value'], 0, 4) != "/tmp") { //$tools->dump($value); $align = strtoupper(substr($value['align'], 0, 1)); $color = $this->hex2rgb($value['color']); $pdf->SetTextColor($color[0], $color[1], $color[2]); $param = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($value['id']); $y2 = $param->getX1() / 5; $x1 = $param->getY1() / 5; //$x1 = 10;$y2 = 8; $w = $param->getX2() / 5; $h = $param->getY2() / 5; $oldx = $x1; $oldy = $y2; $pdf->SetX($x1, false); $pdf->SetY($y2, false); //$pdf->SetXY($x1, $y2,true); $pdf->SetFont(null, '', $param->getSize() * 0.6); //$param->getPolice() // echo $opt->getFontsize()."\n"; $pdf->Cell($w, $h, $value["value"], 0, 0, $align); } else { $param = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($value['id']); $img = $this->getParameter('base_url') . $value['value']; $pdf->Image($img, $param->getX1() / 4.5, $param->getY1() / 4.55, $param->getX2() / 4.55, $param->getY2() / 4.5, '', '', '', true); } } $idd = $value['id']; $i++; } //$pdf->Cell(0, $size['h'], 'TCPDF and FPDI'); // echo $template->getId(); $pdf->Output($this->get('kernel')->getRootDir() . '/../web/pdf.pdf'); } return new Response(""); }
function generatePDF($id_invoice, $introduction_letter = false, $target = 'file', $docs = false) { if (!is_numeric($id_invoice)) { error_log('$id_invoice not defined'); exit(1); } if (!defined('EURO')) { define('EURO', chr(128)); } $facture = Facture::getInfos($id_invoice); foreach (array(LC_MESSAGES, LC_TIME, LC_MONETARY, LC_CTYPE) as $locale) { setlocale($locale, $facture->language . ".UTF-8") or die("locale {$locale} language failed {$facture->language}"); } bindtextdomain('webfinance', dirname(__FILE__) . '/../../lang') or die("Set gettext bindtextdomain language failed\n"); textdomain('webfinance') or die("Set gettext textdomain language failed\n"); $type_doc = $facture->type_doc; if ($facture->language == 'en_US' and $facture->type_doc == 'facture') { $type_doc = 'invoice'; } if ($facture->language == 'en_US' and $facture->type_doc == 'devis') { $type_doc = 'quote'; } // Generate PDF filename $filename = sys_get_temp_dir() . '/' . ucfirst($type_doc) . ' ' . preg_replace('/[^a-z0-9éàçùî\\._-]/i', ' ', $facture->num_facture . ' ' . $facture->nom_client) . '.pdf'; foreach ($facture as $n => $v) { if (!is_array($v)) { $facture->{$n} = preg_replace("/€/", "EUROSYMBOL", $facture->{$n}); // FPDF ne support pas l'UTF-8 $facture->{$n} = utf8_decode($facture->{$n}); $facture->{$n} = preg_replace("/EUROSYMBOL/", chr(128), $facture->{$n}); $facture->{$n} = preg_replace("/\\\\EUR\\{([0-9.,]+)\\}/", "\\1 " . chr(128), $facture->{$n}); } } $pdf = new FPDI('P', 'mm', 'A4'); // Address $address = "{$facture->nom_client}\n"; for ($i = 0; $i < 3; $i++) { $n = sprintf("addr%d", $i + 1); if ($facture->{$n} != "") { $address .= $facture->{$n} . "\n"; } } $address .= "{$facture->cp} {$facture->ville}\n{$facture->pays}"; //Get docs, if needed if ($docs !== false) { $pagecount = $pdf->SetSourceFile(dirname(__FILE__) . '/../admin/invoice_docs/docs_' . $facture->language . '.pdf'); for ($n = 1; $n <= $pagecount; $n++) { $tplidx = $pdf->ImportPage($n, '/MediaBox'); $pdf->AddPage(); $pdf->UseTemplate($tplidx); } } $pdf->SetMargins(10, 10, 10); $pdf->SetDisplayMode('fullwidth'); $pdf->AddPage(); $prefs = new WebfinancePreferences(); // UTF8 to ISO $prefs->prefs['societe']->invoice_top_line1 = preg_replace("/€/", "EUROSYMBOL", $prefs->prefs['societe']->invoice_top_line1); // FPDF ne support pas l'UTF-8 $prefs->prefs['societe']->invoice_top_line1 = utf8_decode($prefs->prefs['societe']->invoice_top_line1); $prefs->prefs['societe']->invoice_top_line1 = preg_replace("/EUROSYMBOL/", chr(128), $prefs->prefs['societe']->invoice_top_line1); // Save the logo to a temp file since fpdf cannot read from a var $tempfile_logo = tempnam(sys_get_temp_dir(), 'logo') . '.png'; $logo_tmp = fopen($tempfile_logo, "w"); fwrite($logo_tmp, $prefs->prefs['logo']); fclose($logo_tmp); // Logo $pdf->Image($tempfile_logo, 90, 5, 25, 0, 'PNG'); // Display text headers $pdf->SetFont('Arial', '', 5); $logo_size = getimagesize($tempfile_logo); $logo_height = $logo_size[1] * 25 / $logo_size[0]; $pdf->SetXY(10, $logo_height + 5); $pdf->Cell(190, 5, $prefs->prefs['societe']->invoice_top_line1, 0, 0, "C"); $pdf->SetLineWidth(0.3); $pdf->SetXY(10, $logo_height + 8); $pdf->Cell(190, 5, utf8_decode($prefs->prefs['societe']->invoice_top_line2), "B", 0, "C"); // Address $pdf->SetFont('Arial', 'B', 11); $pdf->SetXY(115, 50); $pdf->Cell(80, 5, $facture->nom_client, 0, 0); $pdf->SetFont('Arial', '', 11); $y = 54; for ($i = 0; $i < 3; $i++) { $n = sprintf("addr%d", $i + 1); if ($facture->{$n} != "") { $pdf->SetXY(115, $y); $pdf->Cell(80, 5, $facture->{$n}, 0, 0); $y += 5; } } $pdf->SetXY(115, $y); $pdf->Cell(80, 4, $facture->cp . " " . $facture->ville, 0, 0); $pdf->SetXY(115, $y + 5); $pdf->Cell(80, 4, $facture->pays, 0, 0); // Donnees factures $pdf->SetXY(10, 19 + $logo_height); $pdf->SetFont('Arial', 'B', 14); $pdf->Cell(60, 4, ucfirst($type_doc) . utf8_decode(_(' #')) . $facture->num_facture); $pdf->SetFont('Arial', '', 9); $pdf->SetXY(10, 27 + $logo_height); $pdf->Cell(60, 4, $societe->ville . " " . utf8_decode(_("on")) . " " . strftime("%d/%m/%Y", $facture->timestamp_date_facture)); $pdf->SetXY(10, 32 + $logo_height); if (!empty($societe->tva_intracommunautaire)) { $pdf->Cell(60, 4, utf8_decode(_("VAT code")) . " " . $societe->raison_sociale . " : {$societe->tva_intracommunautaire}\n"); } if (!empty($facture->vat_number)) { $pdf->Write(5, utf8_decode(_("Your VAT code")) . " : {$facture->vat_number}\n"); } $pdf->Write(5, $facture->ref_contrat . "\n"); $pdf->Write(5, wordwrap($facture->extra_top, 70)); // Lignes de facturation $pdf->SetLineWidth(0.1); $pdf->SetXY(10, 80); $pdf->SetFont('Arial', 'B', '10'); $pdf->Cell(110, 6, utf8_decode(_("Designation")), 1); $pdf->Cell(20, 6, utf8_decode(_("Quantity")), 1, 0, "C"); $pdf->Cell(30, 6, utf8_decode(_("VAT excl.")), 1, 0, "C"); $pdf->Cell(30, 6, utf8_decode(_("Total")), 1, 0, "C"); $pdf->Ln(); $total_ht = 0; foreach ($facture->lignes as $ligne) { foreach ($ligne as $n => $v) { $ligne->{$n} = preg_replace("/€/", "EUROSYMBOL", $ligne->{$n}); $ligne->{$n} = utf8_decode($ligne->{$n}); $ligne->{$n} = preg_replace("/EUROSYMBOL/", chr(128), $ligne->{$n}); } setlocale(LC_TIME, "fr_FR.UTF8"); // Replace dates like YYYY-MM-DD with nice expanded date $ligne->description = preg_replace_callback('/\\d{4}-\\d{2}-\\d{2}/', create_function('$matches', 'return utf8_decode(strftime("%e %B %Y", strtotime($matches[0])));'), $ligne->description); $y_start = $pdf->getY(); $pdf->SetFont('Arial', '', '10'); $pdf->MultiCell(110, 6, $ligne->description, "LR", 'L'); $x = $pdf->getX(); $y = $pdf->getY(); $pdf->setXY(120, $y_start); $pdf->Cell(20, 6, $ligne->qtt, "LR", 0, "C"); $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $ligne->prix_ht)), "LR", 0, "R"); $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $ligne->prix_ht * $ligne->qtt)), "LR", 0, "R"); $pdf->setXY(120, $y_start); $pdf->Cell(20, $y - $y_start, '', "LR", 0, "C"); $pdf->Cell(30, $y - $y_start, '', "LR", 0, "R"); $pdf->Cell(30, $y - $y_start, '', "LR", 0, "R"); $total_ht += $ligne->prix_ht * $ligne->qtt; $pdf->Ln(); $pdf->Cell(110, 2, "", "LR"); $pdf->Cell(20, 2, "", "LR"); $pdf->Cell(30, 2, "", "LR"); $pdf->Cell(30, 2, "", "LR"); $pdf->Ln(); } $y_fin = $pdf->getY(); if ($y < 190) { $pdf->Cell(110, 190 - $y, "", "LRB", 0, "C"); $pdf->Cell(20, 190 - $y, "", "LRB", 0, "C"); $pdf->Cell(30, 190 - $y, "", "LRB", 0, "C"); $pdf->Cell(30, 190 - $y, "", "LRB", 0, "C"); $pdf->Ln(); } // Total HT $txt_type_paiement = $facture->type_paiement; if (preg_match('/eption de cette facture/', $txt_type_paiement) and $facture->language != 'fr_FR') { $txt_type_paiement = _('upon receipt of invoice'); } $pdf->SetFont('Arial', '', '11'); $pdf->Cell(130, 6, utf8_decode(_("Payment")) . " : " . $txt_type_paiement); $pdf->Cell(30, 6, utf8_decode(_("Subtotal")), "", 0, "R"); $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $total_ht)), "", 0, "R"); $pdf->Ln(); // TVA $pdf->Cell(130, 6, ""); $pdf->Cell(30, 6, utf8_decode(_("VAT")) . " " . str_replace('.', ',', $facture->taxe) . "%", "", 0, "R"); $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $facture->taxe / 100 * $total_ht)), "", 0, "R"); $pdf->Ln(); // Solde à régler $pdf->SetFont('Arial', 'B', '11'); $pdf->Cell(130, 6, ""); $pdf->Cell(30, 6, utf8_decode(_('Total')), "", 0, "R"); $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, (1 + $facture->taxe / 100) * $total_ht - $facture->accompte)), "", 0, "R"); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont('Arial', '', '8'); $pdf->MultiCell(190, 4, utf8_decode(_('Discount not practiced by the company. In case of default in the invoice due date, the client agrees to pay a penalty pursuant to the provisions of Article 1226 of the Civil Code, an increase of 15% in addition to the main total without any notice of default being required.'))); // Extra data $pdf->SetFont('Arial', '', '10'); if (!empty($facture->extra_bottom)) { $pdf->Ln(10); $pdf->MultiCell(120, 6, $facture->extra_bottom, 0); } // RIB $result = mysql_query('SELECT value ' . 'FROM webfinance_pref ' . 'WHERE id_pref=' . $facture->id_compte) or die(mysql_error()); list($cpt) = mysql_fetch_array($result); mysql_free_result($result); $cpt = unserialize(base64_decode($cpt)); if (!is_object($cpt)) { echo "compte Impossible de generer la facture. <a " . "href='../admin/societe'>Vous devez saisir au moins un compte " . "bancaire dans les options pour emettre des factures</a>"; exit(1); } foreach ($cpt as $n => $v) { $cpt->{$n} = utf8_decode($cpt->{$n}); } $pdf->SetFont('Arial', 'B', '10'); $pdf->Ln(); $pdf->Cell(160, 6, utf8_decode(_("Bank references")) . " ", "LTR", 0, "C"); $pdf->Ln(); $pdf->SetFont('Arial', '', '8'); $pdf->Cell(35, 6, utf8_decode(_("Bank")) . " : ", "L"); $pdf->Cell(125, 6, $cpt->banque, "R"); $pdf->Ln(); $pdf->Cell(35, 6, "IBAN : ", "L"); $pdf->Cell(125, 6, $cpt->iban, "R"); $pdf->Ln(); $pdf->Cell(35, 6, "SWIFT/BIC : ", "LB"); $pdf->Cell(125, 6, $cpt->swift, "BR"); $pdf->Ln(); $pdf->SetAuthor($societe->raison_sociale); $pdf->SetCreator('Webfinance $Id: gen_facture.php 532 2012-11-10 10:32:19Z pierre $ Using FPDF'); $pdf->SetSubject(ucfirst($facture->type_doc) . utf8_decode(_(' #')) . " " . $facture->num_facture . " " . utf8_decode(_("for")) . " " . $facture->nom_client); $pdf->SetTitle(ucfirst($facture->type_doc) . utf8_decode(_(' #')) . " " . $facture->num_facture); if ($target == 'file') { $pdf->Output($filename, 'F'); } else { $pdf->Output(basename($filename), 'I'); } $pdf->Close(); // Delete temporary logo file unlink($tempfile_logo); global $language; foreach (array(LC_MESSAGES, LC_TIME, LC_MONETARY, LC_CTYPE) as $locale) { setlocale($locale, $language . ".UTF-8") or die("locale {$locale} language failed {$language}"); } bindtextdomain('webfinance', dirname(__FILE__) . '/../../lang') or die("Set gettext bindtextdomain language failed\n"); textdomain('webfinance') or die("Set gettext textdomain language failed\n"); return $filename; }
public function test() { // $rgb_arr = sscanf('rgb(243, 243, 243)', "rgb(%d, %d, %d)"); // print_r($this->rgbToCmyk($rgb_arr[0], $rgb_arr[1], $rgb_arr[2])); // exit(); // $img = new Imagick('test.jpg'); $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1); $img->setresolution(300, 300); $img->setimageformat('pdf'); $img->writeimage('test.pdf'); include_once APPPATH . 'libraries/tcpdf/tcpdf.php'; include_once APPPATH . 'libraries/tcpdf/fpdi.php'; // создаём лист $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false); $pdf->AddPage('L'); // загрузим ранее сохранённый шаблон $pdf->setSourceFile('test.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); $pdf->setCellHeightRatio(1); $pdf->setCellPaddings(0, 0, 0, 0); $pdf->setCellMargins(1, 1, 1, 1); $pdf->SetAutoPageBreak(false); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); $pdf->Image('qwe.png', 30, 30, 20, '', '', '', '', false, 300); $pdf->SetTextColor(0, 0, 0, 100); $pdf->SetFont('helvetica', 'BI', 10, '', 'false'); $pdf->Text(12, 9, 'Black CMYK'); $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/uploads/fynal.pdf', 'F'); $im = new Imagick(); $im->setResolution(300, 300); $im->readimage('uploads/fynal.pdf[0]'); $im->setImageFormat('jpeg'); $im->resizeimage(538, 360, Imagick::FILTER_LANCZOS, 1); $im->writeImage('uploads/fynal.jpg'); $im->clear(); $im->destroy(); // include_once APPPATH . 'libraries/drawer.php'; // // $drawer = new Drawer(); // $drawer->init(); // $drawer->setLayout(); // $drawer->setBackground('test.jpg'); // $drawer->drawImage('test.jpg', 10, 10, 30); // $drawer->drawText('Maxim', 10, 10, 'TimesNewRoman', 20, 'rgb(77, 77, 77)'); // $drawer->savePdf($_SERVER['DOCUMENT_ROOT'] . '/1.pdf'); // $drawer->makePreview($_SERVER['DOCUMENT_ROOT'] . '/1.pdf', $_SERVER['DOCUMENT_ROOT'] . '/1.jpg'); }
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); }
/** * Creates a personalized exam file. * * @param unknown $examid * @return NULL */ function emarking_download_exam($examid, $multiplepdfs = false, $groupid = null, $pbar = null, $sendprintorder = false, $printername = null) { global $DB, $CFG, $USER, $OUTPUT; // Se obtiene el examen if (!($downloadexam = $DB->get_record('emarking_exams', array('id' => $examid)))) { return null; } // Contexto del curso para verificar permisos $context = context_course::instance($downloadexam->course); if (!has_capability('mod/emarking:downloadexam', $context)) { return null; } // Verify that remote printing is enable, otherwise disable a printing order if ($sendprintorder && (!$CFG->emarking_enableprinting || $printername == null)) { return null; } $course = $DB->get_record('course', array('id' => $downloadexam->course)); $coursecat = $DB->get_record('course_categories', array('id' => $course->category)); if ($downloadexam->printrandom == 1) { $enrolincludes = 'manual,self,meta'; } else { $enrolincludes = 'manual,self'; } if ($CFG->emarking_enrolincludes && strlen($CFG->emarking_enrolincludes) > 1) { $enrolincludes = $CFG->emarking_enrolincludes; } if (isset($downloadexam->enrolments) && strlen($downloadexam->enrolments) > 1) { $enrolincludes = $downloadexam->enrolments; } $enrolincludes = explode(",", $enrolincludes); // Get all the files uploaded as forms for this exam $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_emarking', 'exams', $examid); // We filter only the PDFs $pdffileshash = array(); foreach ($files as $filepdf) { if ($filepdf->get_mimetype() === 'application/pdf') { $pdffileshash[] = array('hash' => $filepdf->get_pathnamehash(), 'filename' => $filepdf->get_filename()); } } // Verify that at least we have a PDF if (count($pdffileshash) < 1) { return null; } if ($downloadexam->headerqr == 1) { if ($groupid != null) { $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}" . "/group_" . $groupid; } else { $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}"; } $fileimg = $CFG->dataroot . "/temp/emarking/{$context->id}/qr"; $userimgdir = $CFG->dataroot . "/temp/emarking/{$context->id}/u"; emarking_initialize_directory($filedir, true); emarking_initialize_directory($fileimg, true); emarking_initialize_directory($userimgdir, true); if ($groupid != null) { // Se toman los resultados del query dentro de una variable. $students = emarking_get_students_of_groups($downloadexam->course, $groupid); } else { // Se toman los resultados del query dentro de una variable. $students = emarking_get_students_for_printing($downloadexam->course); } $nombre = array(); $current = 0; // Los resultados del query se recorren mediante un foreach loop. foreach ($students as $student) { if (array_search($student->enrol, $enrolincludes) === false) { continue; } $nombre[] = substr("{$student->lastname}, {$student->firstname}", 0, 65); $rut[] = $student->idnumber; $moodleid[] = $student->id; // Get the image file for student $imgfound = false; if ($CFG->emarking_pathuserpicture && is_dir($CFG->emarking_pathuserpicture)) { $idstring = "" . $student->idnumber; $revid = strrev($idstring); $idpath = $CFG->emarking_pathuserpicture; $idpath .= "/" . substr($revid, 0, 1); $idpath .= "/" . substr($revid, 1, 1); if (file_exists($idpath . "/user{$idstring}.png")) { $userimg[] = $idpath . "/user{$idstring}.png"; $imgfound = true; } } if (!$imgfound) { $usercontext = context_user::instance($student->id); $imgfile = $DB->get_record('files', array('contextid' => $usercontext->id, 'component' => 'user', 'filearea' => 'icon', 'filename' => 'f1.png')); if ($imgfile) { $userimg[] = emarking_get_path_from_hash($userimgdir, $imgfile->pathnamehash, "u" . $student->id, true); } else { $userimg[] = $CFG->dirroot . "/pix/u/f1.png"; } } } $numberstudents = count($nombre); for ($i = $numberstudents; $i < $numberstudents + $downloadexam->extraexams; $i++) { $nombre[$i] = '..............................................................................'; $rut[$i] = '0'; $moodleid[$i] = '0'; $userimg[$i] = $CFG->dirroot . "/pix/u/f1.png"; } $newfile = emarking_get_path_from_hash($filedir, $pdffileshash[$current]['hash']); $path = $filedir . "/" . str_replace(' ', '-', $pdffileshash[$current]['filename']); $hash = hash_file('md5', $path); $logoisconfigured = false; if ($logofile = emarking_get_logo_file()) { $logofilepath = emarking_get_path_from_hash($filedir, $logofile->get_pathnamehash()); $logoisconfigured = true; } $file1 = $filedir . "/" . emarking_clean_filename($course->shortname, true) . "_" . emarking_clean_filename($downloadexam->name, true) . ".pdf"; $pdf = new FPDI(); $cp = $pdf->setSourceFile($path); if ($cp > 99) { print_error(get_string('page', 'mod_emarking')); } if ($multiplepdfs || $groupid != null) { $zip = new ZipArchive(); if ($groupid != null) { $file1 = $filedir . "/" . emarking_clean_filename($course->shortname, true) . "_" . "GRUPO_" . $groupid . "_" . emarking_clean_filename($downloadexam->name, true) . ".zip"; } else { $file1 = $filedir . "/" . emarking_clean_filename($course->shortname, true) . "_" . emarking_clean_filename($downloadexam->name, true) . ".zip"; } if ($zip->open($file1, ZipArchive::CREATE) !== true) { return null; } } if ($sendprintorder) { if ($pbar != null) { $pbar->update(0, count($nombre), ''); } } $jobs[] = array(); if ($downloadexam->printlist == 1) { $flag = 0; // lista de alumnos if ($flag == 0) { $pdf->SetAutoPageBreak(false); $pdf->AddPage(); $left = 85; $top = 8; $pdf->SetFont('Helvetica', 'B', 12); $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper("LISTA DE ALUMNOS")); $left = 15; $top = 16; $pdf->SetFont('Helvetica', '', 8); $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper("Asignatura: " . $course->fullname)); $left = 15; $top = 22; $pdf->SetFont('Helvetica', '', 8); $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper("N° Inscritos: " . count($nombre))); // $year = date("Y"); // $month= date("F"); // $day= date("m"); setlocale(LC_ALL, "es_ES"); $left = 15; $top = 28; $pdf->SetFont('Helvetica', '', 8); $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper("Fecha: " . strftime("%A %d de %B del %Y"))); $left = 15; $top = 36; $pdf->SetXY($left, $top); $pdf->Cell(10, 10, "N°", 1, 0, 'L'); $pdf->Cell(120, 10, "Nombres", 1, 0, 'L'); $pdf->Cell(50, 10, "Firmas", 1, 0, 'L'); $t = 0; $t2 = 46; for ($a = 0; $a <= count($nombre) - 1; $a++) { if ($n == 24 || $n == 48 || $n == 72 || $n == 96 || $n == 120) { $pdf->AddPage(); $t = 0; $t2 = 8; } $top = $t2 + $t; $n = $a + 1; $pdf->SetFont('Helvetica', '', 8); $pdf->SetXY($left, $top); $pdf->Cell(10, 10, $n . ")", 1, 0, 'L'); $pdf->Cell(120, 10, core_text::strtoupper($nombre[$a]), 1, 0, 'L'); $pdf->Cell(50, 10, "", 1, 0, 'L'); // $pdf->Write ( 1, core_text::strtoupper ( $nombre [$a] ) ); $t = $t + 10; } $flag = 1; if ($multiplepdfs || $groupid != null) { if ($groupid != null) { $pdffile = $filedir . "/Lista_de_alumnos_" . "GRUPO_" . $groupid . ".pdf"; $pdf->Output($pdffile, "F"); // se genera el nuevo pdf $zip->addFile($pdffile, "GRUPO_" . $groupid . ".pdf"); } else { $pdffile = $filedir . "/Lista_de_alumnos_" . emarking_clean_filename($course->shortname, true) . ".pdf"; $pdf->Output($pdffile, "F"); // se genera el nuevo pdf $zip->addFile($pdffile, "Lista_de_alumnos_" . emarking_clean_filename($course->shortname, true) . ".pdf"); } } $printername = explode(',', $CFG->emarking_printername); if ($sendprintorder) { if ($printername[$_POST["printername"]] != "Edificio-C-mesonSecretaria") { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=UpperLeft -o fit-to-page -o media=Letter " . $pdffile; } else { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=SinglePortrait -o PageSize=Letter -o Duplex=none " . $pdffile; } $printresult = exec($command); if ($CFG->debug) { echo "{$command} <br>"; echo "{$printresult} <hr>"; } } } } // Here we produce a PDF file for each student for ($k = 0; $k <= count($nombre) - 1; $k++) { // If there are multiplepdfs we have to produce one per student if ($multiplepdfs || $sendprintorder || $groupid != null) { $pdf = new FPDI(); } if ($multiplepdfs || $sendprintorder || $groupid != null || count($pdffileshash) > 1) { $current++; if ($current > count($pdffileshash) - 1) { $current = 0; } $newfile = emarking_get_path_from_hash($filedir, $pdffileshash[$current]['hash']); $path = $filedir . "/" . str_replace(' ', '-', $pdffileshash[$current]['filename']); $cp = $pdf->setSourceFile($path); } $pdf->SetAutoPageBreak(false); for ($i = 1; $i <= $cp + $downloadexam->extrasheets; $i = $i + 1) { $h = rand(1, 999999); $img = $fileimg . "/qr" . $h . "_" . $rut[$k] . "_" . $i . "_" . $hash . ".png"; $imgrotated = $fileimg . "/qr" . $h . "_" . $rut[$k] . "_" . $i . "_" . $hash . "r.png"; // Se genera QR con id, curso y número de página $qrstring = "{$moodleid[$k]} - {$downloadexam->course} - {$i}"; QRcode::png($qrstring, $img); // se inserta QR QRcode::png($qrstring . " - R", $imgrotated); // se inserta QR $gdimg = imagecreatefrompng($imgrotated); $rotated = imagerotate($gdimg, 180, 0); imagepng($rotated, $imgrotated); $pdf->AddPage(); // Agrega una nueva página if ($i <= $cp) { $tplIdx = $pdf->importPage($i); // Se importan las páginas del documento pdf. $pdf->useTemplate($tplIdx, 0, 0, 0, 0, $adjustPageSize = true); // se inserta como template el archivo pdf subido } /* * Ahora se escribe texto sobre las páginas ya importadas. Se fija la fuente, el tipo y el tamaño de la letra. Se señala el título. Se da el nombre, apellido y rut del alumno al cual pertenece la prueba. Se indica el curso correspondiente a la evaluación. Se introduce una imagen. Esta corresponde al QR que se genera con los datos */ if ($CFG->emarking_includelogo && $logoisconfigured) { $pdf->Image($logofilepath, 2, 8, 30); } $left = 58; $top = 8; $pdf->SetFont('Helvetica', '', 12); $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper($downloadexam->name)); $pdf->SetFont('Helvetica', '', 9); $top += 5; $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper(get_string('name') . ": " . $nombre[$k])); $top += 4; if ($rut[$k] && strlen($rut[$k]) > 0) { $pdf->SetXY($left, $top); $pdf->Write(1, get_string('idnumber', 'mod_emarking') . ": " . $rut[$k]); $top += 4; } $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper(get_string('course') . ": " . $course->fullname)); $top += 4; if (file_exists($userimg[$k])) { $pdf->Image($userimg[$k], 35, 8, 15, 15, "PNG", null, "T", true); } $totals = new stdClass(); $totals->identified = $i; $totals->total = $cp + $downloadexam->extrasheets; $pdf->SetXY($left, $top); $pdf->Write(1, core_text::strtoupper(get_string('page') . ": " . get_string('aofb', 'mod_emarking', $totals))); $pdf->Image($img, 176, 3, 34); // y antes era -2 $pdf->Image($imgrotated, 0, $pdf->getPageHeight() - 35, 34); unlink($img); unlink($imgrotated); } if ($multiplepdfs || $sendprintorder || $groupid != null) { $pdffile = $filedir . "/" . emarking_clean_filename($qrstring) . ".pdf"; if (file_exists($pdffile)) { $pdffile = $filedir . "/" . emarking_clean_filename($qrstring) . "_" . $k . ".pdf"; $pdf->Output($pdffile, "F"); // se genera el nuevo pdf $zip->addFile($pdffile, emarking_clean_filename($qrstring) . "_" . $k . ".pdf"); } else { $pdffile = $filedir . "/" . emarking_clean_filename($qrstring) . ".pdf"; $pdf->Output($pdffile, "F"); // se genera el nuevo pdf $zip->addFile($pdffile, emarking_clean_filename($qrstring) . ".pdf"); } $jobs[$k]["param_1_pbar"] = $k + 1; $jobs[$k]["param_2_pbar"] = count($nombre); $jobs[$k]["param_3_pbar"] = 'Imprimiendo pruebas de ' . core_text::strtoupper($nombre[$k]); $jobs[$k]["name_job"] = $pdffile; } } $printername = explode(',', $CFG->emarking_printername); if ($sendprintorder) { foreach ($jobs as &$valor) { if (!empty($valor)) { if ($pbar != null) { $pbar->update($valor["param_1_pbar"], $valor["param_2_pbar"], $valor["param_3_pbar"]); } if ($printername[$_POST["printername"]] != "Edificio-C-mesonSecretaria") { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=UpperLeft -o fit-to-page -o media=Letter " . $valor["name_job"]; } else { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=SinglePortrait -o PageSize=Letter -o Duplex=none " . $valor["name_job"]; } $printresult = exec($command); if ($CFG->debug) { echo "{$command} <br>"; echo "{$printresult} <hr>"; } } } } if ($multiplepdfs || $groupid != null) { // Generate Bat File $printerarray = array(); foreach (explode(',', $CFG->emarking_printername) as $printer) { $printerarray[] = $printer; } $contenido = "@echo off\r\n"; $contenido .= "TITLE Sistema de impresion\r\n"; $contenido .= "color ff\r\n"; $contenido .= "cls\r\n"; $contenido .= ":MENUPPL\r\n"; $contenido .= "cls\r\n"; $contenido .= "echo #######################################################################\r\n"; $contenido .= "echo # Sistema de impresion #\r\n"; $contenido .= "echo # #\r\n"; $contenido .= "echo # @copyright 2014 Eduardo Miranda #\r\n"; $contenido .= "echo # Fecha Modificacion 23-04-2014 #\r\n"; $contenido .= "echo # #\r\n"; $contenido .= "echo # Para realizar la impresion debe seleccionar una de las impresoras #\r\n"; $contenido .= "echo # configuradas. #\r\n"; $contenido .= "echo # #\r\n"; $contenido .= "echo # #\r\n"; $contenido .= "echo #######################################################################\r\n"; $contenido .= "echo # Seleccione una impresora: #\r\n"; $i = 0; while ($i < count($printerarray)) { $contenido .= "echo # " . $i . " - " . $printerarray[$i] . " #\r\n"; $i++; } $contenido .= "echo # " . $i++ . " - Cancelar #\r\n"; $contenido .= "echo # #\r\n"; $contenido .= "echo #######################################################################\r\n"; $contenido .= "set /p preg01= Que desea hacer? ["; $i = 0; while ($i <= count($printerarray)) { if ($i == count($printerarray)) { $contenido .= $i; } else { $contenido .= $i . ","; } $i++; } $contenido .= "]\r\n"; $i = 0; while ($i < count($printerarray)) { $contenido .= "if %preg01%==" . $i . " goto MENU" . $i . "\r\n"; $i++; } $contenido .= "if %preg01%==" . $i++ . " goto SALIR\r\n"; $contenido .= "goto MENU\r\n"; $contenido .= "pause\r\n"; $i = 0; while ($i < count($printerarray)) { $contenido .= ":MENU" . $i . "\r\n"; $contenido .= "cls\r\n"; $contenido .= "set N=%Random%%random%\r\n"; $contenido .= "plink central.apuntes mkdir -m 0777 ~/pruebas/%N%\r\n"; $contenido .= "pscp *.pdf central.apuntes:pruebas/%N%\r\n"; $contenido .= "plink central.apuntes cp ~/pruebas/script_pruebas.sh ~/pruebas/%N%\r\n"; $contenido .= "plink central.apuntes cd pruebas/%N%;./script_pruebas.sh " . $printerarray[$i] . "\r\n"; $contenido .= "plink central.apuntes rm -dfr ~/pruebas/%N%\r\n"; $contenido .= "EXIT\r\n"; $i++; } $contenido .= ":SALIR\r\n"; $contenido .= "CLS\r\n"; $contenido .= "ECHO Cancelando...\r\n"; $contenido .= "EXIT\r\n"; $random = rand(); mkdir($CFG->dataroot . '/temp/emarking/' . $random . '_bat/', 0777); // chmod($random."_bat/", 0777); $fp = fopen($CFG->dataroot . "/temp/emarking/" . $random . "_bat/imprimir.bat", "x"); fwrite($fp, $contenido); fclose($fp); // Generate zip file $zip->addFile($CFG->dataroot . "/temp/emarking/" . $random . "_bat/imprimir.bat", "imprimir.bat"); $zip->close(); unlink($CFG->dataroot . "/temp/emarking/" . $random . "_bat/imprimir.bat"); rmdir($CFG->dataroot . "/temp/emarking/" . $random . "_bat"); } else { if (!$sendprintorder) { $pdf->Output($file1, "F"); // se genera el nuevo pdf } } $downloadexam->status = EMARKING_EXAM_SENT_TO_PRINT; $downloadexam->printdate = time(); $DB->update_record('emarking_exams', $downloadexam); if ($sendprintorder) { $pbar->update_full(100, 'Impresión completada exitosamente'); return $filedir; } if ($groupid != null) { unlink($file1); return $filedir; } else { ob_start(); // modificación: ingreso de esta linea, ya que anterior revisión mostraba error en el archivo header('Content-Description: File Transfer'); header('Content-Type: application/x-download'); header('Content-Disposition: attachment; filename=' . basename($file1)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); ob_clean(); flush(); readfile($file1); unlink($file1); // borra archivo temporal en moodledata exit; } return false; } else { $students = emarking_get_students_for_printing($downloadexam->course); $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}"; emarking_initialize_directory($filedir, true); $printername = explode(',', $CFG->emarking_printername); $totalAlumn = 0; $pdffiles = array(); for ($current = 0; $current < count($pdffileshash); $current++) { $newfile = emarking_get_path_from_hash($filedir, $pdffileshash[$current]['hash']); $path = $filedir . "/" . str_replace(' ', '-', $pdffileshash[$current]['filename']); $pdf = new FPDI(); $cp = $pdf->setSourceFile($path); if ($cp > 99) { print_error(get_string('page', 'mod_emarking')); } $pdf->SetAutoPageBreak(false); $s = 1; while ($s <= $cp + $downloadexam->extrasheets) { $pdf->AddPage(); if ($s <= $cp) { $tplIdx = $pdf->importPage($s); // Se importan las páginas del documento pdf. $pdf->useTemplate($tplIdx, 0, 0, 0, 0, $adjustPageSize = true); // se inserta como template el archivo pdf subido } $s++; } $pdffile = $filedir . "/" . $current . emarking_clean_filename($file->filename); $pdf->Output($pdffile, "F"); $pdffiles[] = $pdffile; } $totalAlumn = count($students); if ($pbar != null) { $pbar->update(0, $totalAlumn, ''); } for ($k = 0; $k <= $totalAlumn + $downloadexam->extraexams - 1; $k++) { $pdffile = $pdffiles[$k % count($pdffileshash)]; if ($printername[$_POST["printername"]] != "Edificio-C-mesonSecretaria") { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=UpperLeft -o fit-to-page -o media=Letter " . $pdffile; } else { $command = "lp -d " . $printername[$_POST["printername"]] . " -o StapleLocation=SinglePortrait -o PageSize=Letter -o Duplex=none " . $pdffile; } // $printresult = exec ( $command ); if ($CFG->debug) { echo "{$command} <br>"; echo "{$printresult} <hr>"; } if ($pbar != null) { $pbar->update($k, $totalAlumn, ''); } } $pbar->update_full(100, 'Impresión completada exitosamente'); return true; /* * $downloadexam->status = EMARKING_EXAM_SENT_TO_PRINT; $downloadexam->printdate = time (); $DB->update_record ( 'emarking_exams', $downloadexam ); $downloadURL = $CFG->wwwroot . '/pluginfile.php/' . $file->contextid . '/mod_emarking/' . $file->filearea . '/' . $file->itemid . '/' . $file->filename; $startdownload = true; echo '<meta http-equiv="refresh" content="2;url=' . $downloadURL . '">'; return true; */ } }
file_put_contents('img.png', $unencodedData); //Show the image //echo '<img src="'.$_POST['img_val'].'" />'; $pdf = new FPDI(); $pdf->setSourceFile('TemplateReporte.pdf'); // seteamos la fuente, el estilo y el tamano $pdf->SetFont('Times', 'B', 10); // seteamos la posicion inicial $pdf->SetXY(25, 80); date_default_timezone_set('America/Bogota'); setlocale(LC_ALL, "es_ES"); $dias = array("Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sábado"); $meses = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); //agregamos una pagina $pdf->AddPage(); $pdf->SetFont('Arial'); // seleccionamos la primera pagina del docuemnto importado $tplIdx = $pdf->importPage(1); // usamos la pagina importado como template $pdf->useTemplate($tplIdx); //seteamos la posicion X $pdf->SetX(25); //salto de linea $pdf->Ln(55.2); $pdf->SetFontSize(9); $pdf->Write(0, utf8_decode(" " . $dias[date('w')] . " " . date('d') . " de " . $meses[date('n') - 1] . " del " . date('Y'))); $pdf->Image('img.png', 50, 110, 200); unlink('img.png'); $pdf->Ln(155); $pdf->Write(0, utf8_decode(" Relación de costos anuales sobre proyectos ejecutados con éxito.")); $pdf->Output();
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); $pdf->setCellHeightRatio(1); $pdf->setCellPaddings(0, 0, 0, 0); $pdf->setCellMargins(1, 1, 1, 1); $pdf->SetAutoPageBreak(false); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); if (!empty($back)) { // отрисуем сначала изображения оборота foreach ($back 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 ($back 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($_SERVER['DOCUMENT_ROOT'] . '/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'] . '/' . $back_pdf, 'F'); // сделаем превью для пользователя $im = new Imagick(); $im->setResolution(300, 300); $im->readimage($back_pdf . '[0]'); $im->setImageFormat('jpg'); $im->flattenimages(); $im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1); $im->writeImage($back_preview); $im->clear(); $im->destroy(); } $this->db->insert('products', array('name' => 'cards_pvc', 'tiraj' => 100, 'weight' => 0.5, 'price' => 0.49, 'cost' => 49, 'macket' => 'my_macket')); $product_id = $this->db->insert_id(); $this->db->insert('designs', array('product_id' => $product_id, 'theme_id' => $this->input->post('theme'), 'face_background' => $faceMacket, 'back_background' => empty($backMacket) ? NULL : $backMacket, 'face' => $face_preview, 'back' => empty($back_preview) ? '' : $back_preview, 'type' => 'system')); $design_id = $this->db->insert_id(); $options = array(); if (!empty($face)) { foreach ($face as $item) { if ($item['type'] == 'text') { $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']); } else { $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL); } } } if (!empty($back)) { foreach ($back as $item) { if ($item['type'] == 'text') { $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']); } else { $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL); } } } if (count($options) > 0) { $this->db->insert_batch('design_options', $options); } echo 'OK'; }
public function executeBatchPrintBadge(sfWebRequest $request) { $ids = $request->getParameter('ids'); // initiate FPDI $pdf = new FPDI('P', 'pt'); // set the sourcefile $pdf->setSourceFile(sfConfig::get('sf_upload_dir') . '/badges/ID_new.pdf'); foreach ($ids as $id) { $this->employee = EmployeePeer::retrieveByPk($id); // import page 1 $tplIdx = $pdf->importPage(1); // add a new page based on size of the badge $s = $pdf->getTemplatesize($tplIdx); $pdf->AddPage('P', array($s['w'], $s['h'])); $pdf->useTemplate($tplIdx); $pdf->setMargins(0, 0, 0, 0); $pdf->SetAutoPageBreak(false); if ($this->employee->getPicture()) { $pdf->Image(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir') . '/' . $this->employee->getPicture(), 29.5, 25.5, 60.3, 74.3); } else { $pdf->Image(sfConfig::get('sf_upload_dir') . '/badges/picture_missing.jpg', 29.5, 25.5, 60.3, 74.3); } // now write some text above the imported page $pdf->SetFont('freesans', 'B', 12); $pdf->SetTextColor(82, 78, 134); $pdf->SetXY(22, 110); $pdf->Cell(0, 12, $this->employee->getFullName()); $pdf->Ln(); $pdf->SetX(22); $pdf->SetFont('freesans', 'BI', 10); $pdf->Cell(0, 14, $this->employee->getJob()); $pdf->SetDisplayMode('real'); } return $pdf->Output('newpdf.pdf', 'D'); }
$pdf->Ln(8.4); $pdf->Cell(100); $pdf->Cell(40, 0, $row["DIFMENSUAL"], 0, 0, "R"); $pdf->Ln(5.6); $pdf->Cell(100); $pdf->Cell(40, 0, $row["DIFANUALAHORRO"], 0, 0, "R"); $pdf->SetTextColor(255, 255, 255); $pdf->Ln(5.6); $pdf->Cell(100); $pdf->Cell(40, 0, $row["DIFPORCENTUAL"], 0, 0, "R"); $pdf->SetTextColor(0, 0, 0); $pdf->Image(GRAFICO_CARTA_COTIZACION.$_REQUEST["archivo"], 50, 156, 120, 77); // 400, 256 } } $pdf->setSourceFile($_SERVER["DOCUMENT_ROOT"]."/modules/solicitud_cotizacion/plantillas/carta_cotizacion.pdf"); $pdf->SetDrawColor(255, 255, 255); $pdf->SetFillColor(255, 255, 255); $pdf->AddPage(); $tplIdx = $pdf->importPage(1); $pdf->useTemplate($tplIdx); $pdf->SetFont("Arial", "B", 10); $pdf->Ln(4); $pdf->Cell(12); $pdf->Cell(0, 0, $row["FECHA"]);
<?php if (isset($_GET['file'])) { require_once 'pdf/fpdf.php'; require_once 'pdf/fpdi.php'; require_once '../model/cardModel.php'; $name = $_GET['file']; $pdf = new FPDI(); $pdf->AddPage("Landscape", array(85.59999999999999, 53.98)); //Set the source PDF file if ($_GET['statut'] == 'junior') { $pagecount = $pdf->setSourceFile("YDCard/Junior.pdf"); } elseif ($_GET['statut'] == 'senior') { $pagecount = $pdf->setSourceFile("YDCard/Senior.pdf"); } elseif ($_GET['statut'] == 'sponsor') { $pagecount = $pdf->setSourceFile("YDCard/Sponsor.pdf"); } //Import the first page of the file $tppl = $pdf->importPage(1); $pdf->useTemplate($tppl); //Use this page as template // use the imported page and place it at point 20,30 with a width of 170 mm $pdf->Image($_GET['file_path'], 5, 40, 10, 10, 'png'); $path = 'userCard/' . $name . '.pdf'; $pdf->Output($path, "F"); header('location:../view/index.php'); $cardModel = new cardModel(); $cardModel->activateCard($path, $name); } else { header('location:../view/index.php'); }
public function generateCoupon($coupon_image_url, $user_id, $email_id) { require_once $_SERVER['DOCUMENT_ROOT'] . '/application/libraries/fpdf/fpdf.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/application/libraries/fpdf/fpdi.php'; $pdf = new FPDI(); $pageCount = $pdf->setSourceFile($_SERVER['DOCUMENT_ROOT'] . "/application/libraries/coupon.pdf"); $tplIdx = $pdf->importPage(1, '/MediaBox'); $count = 0; $y = 145.5; $i = 1; $amt = 0; $pdf->addPage(); $pdf->useTemplate($tplIdx, 3, 3, 210, 300); $pdf->SetFont('Arial', '', '9'); $pdf->SetTextColor(0, 0, 0); $pdf->Text(50, 80, 'User ID :'); $pdf->Text(100, 80, $user_id); $pdf->Text(50, 90, 'Email ID :'); $pdf->Text(100, 90, $email_id); $pdf->Image($coupon_image_url, 50, 100); $save_status = 1; if (!$save_status) { $pdf->Output(); } else { $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/images/coupons/' . 'coupon_' . $user_id . '.pdf', 'F'); } }