/** * tests getContent(). */ public function testGetContent() { $this->_parFormat->setIndentLeft(5); $this->_parFormat->setIndentRight(5); $this->_parFormat->setSpaceBefore(5); $this->_parFormat->setSpaceAfter(5); $this->_parFormat->setIndentFirstLine(3); $this->_parFormat->setSpaceBetweenLines(1.2); $this->_parFormat->setShading(50); $this->assertEquals('\\ql \\fi1701 \\li2835 \\ri2835 \\sb100 \\sa100 \\sl288 \\shading5000 ', $this->_parFormat->getContent()); }
function Generate_Content() { PHPRtfLite::registerAutoloader(); $largerFont = new PHPRtfLite_Font(16, 'Courier New'); $largerFont->setBold(); $smallerFont = new PHPRtfLite_Font(12, 'Times New Roman'); $tableFont = new PHPRtfLite_Font(10, 'Courier New'); //Izveido pašu dokumentu $rtf = new PHPRtfLite(); $parHead = new PHPRtfLite_ParFormat(); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parBody = new PHPRtfLite_ParFormat(); $parBody->setSpaceBefore(1); //Izveido pirmo sekciju $sect =& $rtf->addSection(); $sect->writeText("Atzīmju izraksts", $largerFont, $parHead); $sect->writeText("Skolnieks: " . $this->studentName, $smallerFont, $parHead); for ($i = 0; $i < count($this->grades); $i++) { $grade = $this->grades[$i]; $sect->writeText(sprintf("%s %s %s", $grade["date"], $grade["lesson"], $grade["grade"]), $tableFont, $parBody); } $this->fileContents = $rtf; }
$rtf->setPaperFormat(PHPRtfLite::PAPER_LETTER); // Добавить футер $footer = $rtf->addFooter(); $fontFooter = new PHPRtfLite_Font(8, 'Arial', '#000000'); $alignFooter = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $footer->writeText('Used cars for sale - <pagenum>', $fontFooter, $alignFooter); // Определить шрифты $fontH1 = new PHPRtfLite_Font(16, 'Arial', '#4E9C93'); $fontH2 = new PHPRtfLite_Font(14, 'Arial', '#4E9C93'); $fontP = new PHPRtfLite_Font(12, 'Helvetica', '#000000'); // Вертикальное форматирование текста $formatH1 = new PHPRtfLite_ParFormat(); $formatH1->setSpaceAfter(8); $formatH2 = new PHPRtfLite_ParFormat(); $formatH2->setSpaceAfter(6); $formatP = new PHPRtfLite_ParFormat(); $formatP->setSpaceAfter(3); // Содержание страницы $section = $rtf->addSection(); $section->writeText('Used Cars for Sale', $fontH1, $formatH1); while ($row = getRow($result)) { $section->writeText($row['make'], $fontH2, $formatH2); $section->setNoBreak(); $section->writeText('<bullet> Price: $' . number_format($row['price'], 2), $fontP, $formatP); $section->writeText('<bullet> Mileage: ' . number_format($row['mileage']), $fontP, $formatP); $section->writeText('<bullet> Transmission: ' . $row['transmission'], $fontP, $formatP); $section->writeText($row['description'] . '<hr>', $fontP, $formatP); } // Выходной файл $rtf->sendRtf('cars.rtf'); } catch (Exception $e) {
/** * renders footnote/endnote * * @return string */ public function getContent() { $content = '\\chftn ' . '{\\footnote' . ($this->isFootnote() ? '' : '\\ftnalt') . '\\pard\\plain \\lin283\\fi-283 '; if ($this->_parFormat) { $content .= $this->_parFormat->getContent($this->_rtf); } $content .= $this->_font->getContent($this->_rtf); $content .= '{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} '; return $content; }
<?php $dir = dirname(__FILE__); require_once $dir . '/../lib/PHPRtfLite.php'; // register PHPRtfLite class loader PHPRtfLite::registerAutoloader(); // rtf document $rtf = new PHPRtfLite(); //paragraph formats $parFormat = new PHPRtfLite_ParFormat(); $parGreyLeft = new PHPRtfLite_ParFormat(); $parGreyLeft->setShading(10); $parGreyCenter = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $parGreyCenter->setShading(10); // header $header = $rtf->addHeader('first'); $header->addImage($dir . '/sources/rtf_thumb.jpg', $parFormat); $header->writeText('Image in header.', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect = $rtf->addSection(); $sect->writeText('Images with PHPRtfLite.', new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center')); $sect->writeText('<br>Here is .jpg image. <tab>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect->addImage($dir . '/sources/rtf_thumb.jpg', null); $sect->writeText('<br>Here is .png image. <tab>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect->addImage($dir . '/sources/html.png', null); $sect->writeText('<br><br><b>Formating sizes of images:</b>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $table = $sect->addTable(); $table->addRows(3, 4.5); $table->addRow(6); $table->addColumnsList(array(7.5, 6.5)); $table->writeToCell(1, 1, '<br> Original size.', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); //getting cell object, writing text and adding image
/** * renders footnote/endnote */ public function render() { $stream = $this->_rtf->getWriter(); $typeSetting = $this->_typeSettingType != self::TYPE_NORMAL ? '\\' . $this->_typeSettingType : ''; $stream->write('{' . $typeSetting . '\\chftn}' . '{' . $this->getTypeAsRtfCode() . '\\pard\\plain\\lin283\\fi-283 '); if ($this->_parFormat) { $stream->write($this->_parFormat->getContent()); } if ($this->_font) { $stream->write($this->_font->getContent()); } $stream->write('{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} '); }
/** * registers the par format in color table * * @param PHPRtfLite_ParFormat $parFormat */ public function registerParFormat(PHPRtfLite_ParFormat $parFormat) { $parFormat->setColorTable($this->getColorTable()); }
/** * sets paragraph format for image * * @param PHPRtfLite_ParFormat $parFormat */ public function setParFormat(PHPRtfLite_ParFormat $parFormat) { $this->_parFormat = $parFormat; $parFormat->setColorTable($this->_rtf->getColorTable()); }
/** * Writes hyperlink to container. * * @param string $hyperlink hyperlink url (etc. "http://www.phprtf.com") * @param string $text hyperlinks text, if empty, hyperlink is written in previous paragraph format. * @param PHPRtfLite_Font $font font * @param PHPRtfLite_ParFormat $parFormat paragraph format, if null hyperlink is written in the same paragraph */ public function writeHyperLink($hyperlink, $text, PHPRtfLite_Font $font, PHPRtfLite_ParFormat $parFormat = null) { $content = $parFormat && count($this->_elements) != 0 && !$this->_emptyPar ? '\\par ' : ''; $content .= $parFormat ? $this->_pard . $parFormat->getContent($this->_rtf) : ''; $this->_emptyPar = false; $this->_elements[] = $content . '{\\field {\\*\\fldinst {HYPERLINK "' . $hyperlink . '"}}{\\fldrslt {'; $this->writeText($text, $font, null); $this->_elements[] .= '}}}' . "\r\n"; }
$fontHead = new PHPRtfLite_Font(12, 'Arial'); $fontSmall = new PHPRtfLite_Font(3); $fontAnimated = new PHPRtfLite_Font(10); $fontLink = new PHPRtfLite_Font(10, 'Helvetica', '#0000cc'); $parBlack = new PHPRtfLite_ParFormat(); $parBlack->setIndentRight(12.5); //$parBlack->setBackgroundColor('#000000'); $parBlack->setSpaceBefore(12); $parHead = new PHPRtfLite_ParFormat(); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parHead->setBackgroundColor('#baf4c1'); $parSimple = new PHPRtfLite_ParFormat(); $parSimple->setIndentLeft(1); $parSimple->setIndentRight(0.5); $par_child_text = new PHPRtfLite_ParFormat(); $par_child_text->setIndentLeft(0.5); $par_child_text->setIndentRight(0.5); //$rtf->setMargins(3, 1, 1 ,2); // *** Generate title of RTF file *** @($persDb = $db_functions->get_person($main_person)); // *** Use class to process person *** $pers_cls = new person_cls(); $pers_cls->construct($persDb); $name = $pers_cls->person_name($persDb); if (!$descendant_report == false) { $title = __('Descendant report') . __(' of ') . $name["standard_name"]; } else { $title = __('Family group sheet') . __(' of ') . $name["standard_name"]; } //$sect->writeText($title, $arial14, new PHPRtfLite_ParFormat());
$fontAnimated = new PHPRtfLite_Font(10); $fontLink = new PHPRtfLite_Font(10, 'Helvetica', '#0000cc'); $parNames = new PHPRtfLite_ParFormat(); $parNames->setBackgroundColor('#FFFFFF'); $parNames->setIndentLeft(0); $parNames->setSpaceBefore(0); $parNames->setSpaceAfter(0); $parHead = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parHead->setBackgroundColor('#baf4c1'); $parGen = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $parGen->setSpaceBefore(0); $parGen->setSpaceAfter(8); $parGen->setBackgroundColor('#baf4c1'); $parSimple = new PHPRtfLite_ParFormat(); $parSimple->setIndentLeft(2.5); $parSimple->setIndentRight(0.5); // *** Generate title of RTF file *** $pers = $dbh->query("SELECT * FROM humo_persons WHERE pers_tree_id='" . $tree_id . "' AND pers_gedcomnumber='{$family_id}'"); @($persDb = $pers->fetch(PDO::FETCH_OBJ)); // *** Use person class *** $pers_cls = new person_cls(); $pers_cls->construct($persDb); $name = $pers_cls->person_name($persDb); $title = __('Ancestor report') . __(' of ') . $name["standard_name"]; //$sect->writeText($title, $arial14, new PHPRtfLite_ParFormat()); $sect->writeText($title, $arial14, $parHead); $file_name = date("Y_m_d_H_i_s") . '.rtf'; // *** FOR TESTING PURPOSES ONLY *** if (@file_exists("../gedcom-bestanden")) {
//Fonts $fontHead = new PHPRtfLite_Font(12, 'Arial'); $fontSmall = new PHPRtfLite_Font(3); $fontAnimated = new PHPRtfLite_Font(10); $fontLink = new PHPRtfLite_Font(10, 'Helvetica', '#0000cc'); $parBlack = new PHPRtfLite_ParFormat(); $parBlack->setIndentRight(9); $parBlack->setBackgroundColor('#000000'); $parBlack->setSpaceBefore(12); $parHead = new PHPRtfLite_ParFormat(); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parSimple = new PHPRtfLite_ParFormat(); $parSimple->setIndentLeft(5); $parSimple->setIndentRight(0.5); $parPhp = new PHPRtfLite_ParFormat(); $parPhp->setShading(5); $border = PHPRtfLite_Border::create($rtf, 1, '#000000', 'dash', 0.3); $parPhp->setBorder($border); $parPhp->setIndentLeft(5); $parPhp->setIndentRight(0.5); //section $sect = $rtf->addSection(); //table $table = $sect->addTable(); $table->addRows(1); $table->addRows(1); $table->addColumn(1); $table->addColumn(14); $cell = $table->getCell(1, 2); $cell->writeText('Testing paragraphs in table cells.', new PHPRtfLite_Font(14, 'Arial'), $parHead);
//Fonts $fontHead = new PHPRtfLite_Font(12, 'Arial'); $fontSmall = new PHPRtfLite_Font(3); $fontAnimated = new PHPRtfLite_Font(10); $fontLink = new PHPRtfLite_Font(10, 'Helvetica', '#0000cc'); $parBlack = new PHPRtfLite_ParFormat(); $parBlack->setIndentRight(12.5); $parBlack->setBackgroundColor('#000000'); $parBlack->setSpaceBefore(12); $parHead = new PHPRtfLite_ParFormat(); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parSimple = new PHPRtfLite_ParFormat(); $parSimple->setIndentLeft(5); $parSimple->setIndentRight(0.5); $parPhp = new PHPRtfLite_ParFormat(); $parPhp->setShading(5); $border = PHPRtfLite_Border::create($rtf, 1, '#000000', 'dash', 0.3); $parPhp->setBorder($border); $parPhp->setIndentLeft(5); $parPhp->setIndentRight(0.5); $rtf->setMargins(3, 1, 1, 2); //Section $sect = $rtf->addSection(); $sect->writeText('Paragraphs, fonts and other', new PHPRtfLite_Font(14, 'Arial'), $parHead); $sect->addEmptyParagraph($fontSmall, $parBlack); $sect->writeText('Various fonts', $fontHead, $parHead); $sect->writeText('Times New Roman, 9pt, Red', new PHPRtfLite_Font(9, 'Times New Roman', '#ff0000'), $parSimple); $sect->writeText('Times New Roman, 10pt, Red, Pattern Yellow', new PHPRtfLite_Font(10, 'Times New Roman', '#ff0000', '#ffff00'), $parSimple); $sect->writeText('Tahoma, 10pt, Blue', new PHPRtfLite_Font(10, 'Tahoma', '#0000ff'), $parSimple); $sect->writeText('Verdana, 8pt, Green', new PHPRtfLite_Font(8, 'Verdana', '#00cc00'), $parSimple);