setFont() public method

It is mandatory to call this method at least once before printing text or the resulting document would not be valid. The font can be either a standard one or a font added via the {@link addFont()} method. Standard fonts use Windows encoding cp1252 (Western Europe). The method can be called before the first page is created and the font is retained from page to page. If you just wish to change the current font size, it is simpler to call {@link setFontSize()}.
See also: addFont()
See also: setFontSize()
See also: cell()
See also: multiCell()
See also: write()
public setFont ( string $family, string $style = '', integer $size = null, boolean $force = false )
$family string Family font. It can be either a name defined by {@link addFont()} or one of the standard families (case insensitive): - Courier (fixed-width) - Helvetica or Arial (sans serif) - Times (serif) - Symbol (symbolic) - ZapfDingbats (symbolic) It is also possible to pass an empty string. In that case, the current family is retained.
$style string Font style. Possible values are (case insensitive): - empty string: regular - B: bold - I: italic - U: underline or any combination. Bold and italic styles do not apply to Symbol and ZapfDingbats.
$size integer Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12.
$force boolean Force the setting of the font. Each new page will require a new call to {@link setFont()} and setting this to true will make sure that the checks for same font calls will be skipped.
Ejemplo n.º 1
0
 public function run()
 {
     extract($this->_params, EXTR_REFS);
     $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
     if (!$story_id) {
         try {
             $story_id = $GLOBALS['injector']->getInstance('Jonah_Driver')->getLatestStoryId($channel_id);
         } catch (Exception $e) {
             $this->_exit($e->getMessage());
         }
     }
     try {
         $story = $driver->getStory($story_id, !$browser->isRobot());
     } catch (Exception $e) {
         $this->_exit($e->getMessage());
     }
     // Convert the body from HTML to text if necessary.
     if (!empty($story['body_type']) && $story['body_type'] == 'richtext') {
         $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'html2text');
     }
     // Set up the PDF object.
     $pdf = new Horde_Pdf_Writer(array('format' => 'Letter', 'unit' => 'pt'));
     $pdf->setMargins(50, 50);
     // Enable automatic page breaks.
     $pdf->setAutoPageBreak(true, 50);
     // Start the document.
     $pdf->open();
     // Start a page.
     $pdf->addPage();
     // Publication date.
     if (!empty($story['published_date'])) {
         $pdf->setFont('Times', 'B', 14);
         $pdf->cell(0, 14, $story['published_date'], 0, 1);
         $pdf->newLine(10);
     }
     // Write the header in Times 24 Bold.
     $pdf->setFont('Times', 'B', 24);
     $pdf->multiCell(0, 24, $story['title'], 'B', 1);
     $pdf->newLine(20);
     // Write the story body in Times 14.
     $pdf->setFont('Times', '', 14);
     $pdf->write(14, $story['body']);
     // Output the generated PDF.
     $browser->downloadHeaders($story['title'] . '.pdf', 'application/pdf');
     echo $pdf->getOutput();
 }
Ejemplo n.º 2
0
Archivo: pdf.php Proyecto: horde/horde
}
/* If the requested note doesn't exist, display an error message. */
if (!$note || !isset($note['memo_id'])) {
    $notification->push(_("Note not found."), 'horde.error');
    Horde::url('list.php', true)->redirect();
}
/* Let's assume that the note content can be converted to ISO-8859-1 if this
 * is the current language's charset, as long as we don't have UTF-8 support
 * in Horde_Pdf. */
if ($GLOBALS['registry']->getLanguageCharset() == 'ISO-8859-1') {
    $note = Horde_String::convertCharset($note, 'UTF-8', 'ISO-8859-1');
}
/* Set up the PDF object. */
$pdf = new Horde_Pdf_Writer(array('format' => 'Letter', 'unit' => 'pt'));
$pdf->setMargins(50, 50);
/* Enable automatic page breaks. */
$pdf->setAutoPageBreak(true, 50);
/* Start the document. */
$pdf->open();
/* Start a page. */
$pdf->addPage();
/* Write the header in Times 24 Bold. */
$pdf->setFont('Times', 'B', 24);
$pdf->multiCell(0, 24, $note['desc'], 'B', 1);
$pdf->newLine(20);
/* Write the note body in Times 14. */
$pdf->setFont('Times', '', 14);
$pdf->write(14, $note['body']);
/* Output the generated PDF. */
$browser->downloadHeaders($note['desc'] . '.pdf', 'application/pdf');
echo $pdf->getOutput();
Ejemplo n.º 3
0
 /**
  * PEAR Bug #12310
  */
 public function testCourierStyle()
 {
     $pdf = new Horde_Pdf_Writer();
     $pdf->setFont('courier', 'B', 10);
 }