Esempio n. 1
0
// Text at x=100 and y=100.
$pdf->text(100, 100, 'First page');
// Set font size to 20 pt.
$pdf->setFontSize(20);
// Text at x=100 and y=200.
$pdf->text(100, 200, 'HELLO WORLD!');
// Add a new page.
$pdf->addPage();
// Set font to Arial bold italic 12 pt.
$pdf->setFont('Arial', 'BI', 12);
// Text at x=100 and y=200.
$pdf->text(100, 100, 'Second page');
// Print the generated file.
echo $pdf->getOutput();
// Set up the pdf object.
$pdf =& File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
// Start the document.
$pdf->open();
// Deactivate compression.
$pdf->setCompression(false);
// Start a page.
$pdf->addPage();
// Set font to Courier 8 pt.
$pdf->setFont('Courier', '', 8);
// Text at x=100 and y=100.
$pdf->text(100, 100, 'First page');
// Set font size to 20 pt.
$pdf->setFontSize(20);
// Text at x=100 and y=200.
$pdf->text(100, 200, 'HELLO WORLD!');
// Add a new page.
 /**
  * Sets the font used to print character strings.
  *
  * 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()}.
  *
  * @param string $family  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.
  * @param string $style   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.
  * @param integer $size   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.
  * @param boolean $force  Force the setting of the font. Each new page will
  *                        require a new call to {@link setFont()} and
  *                        settings this to true will make sure that the
  *                        checks for same font calls will be skipped.
  *
  * @see addFont()
  * @see setFontSize()
  * @see cell()
  * @see multiCell()
  * @see write()
  */
 function setFont($family, $style = '', $size = null, $force = false)
 {
     $family = strtolower($family);
     if (empty($family)) {
         $family = $this->_font_family;
     }
     if ($family == 'arial') {
         /* Use helvetica instead of arial. */
         $family = 'helvetica';
     } elseif ($family == 'symbol' || $family == 'zapfdingbats') {
         /* These two fonts do not have styles available. */
         $style = '';
     }
     $style = strtoupper($style);
     /* Underline is handled separately, if specified in the style var
      * remove it from the style and set the underline flag. */
     if (strpos($style, 'U') !== false) {
         $this->_underline = true;
         $style = str_replace('U', '', $style);
     } else {
         $this->_underline = false;
     }
     if ($style == 'IB') {
         $style = 'BI';
     }
     /* If no size specified, use current size. */
     if (is_null($size)) {
         $size = $this->_font_size_pt;
     }
     /* If font requested is already the current font and no force setting
      * of the font is requested (eg. when adding a new page) don't bother
      * with the rest of the function and simply return. */
     if ($this->_font_family == $family && $this->_font_style == $style && $this->_font_size_pt == $size && !$force) {
         return;
     }
     /* Set the font key. */
     $fontkey = $family . $style;
     /* Test if already cached. */
     if (!isset($this->_fonts[$fontkey])) {
         /* Get the character width definition file. */
         $font_widths = File_PDF::_getFontFile($fontkey);
         if (is_a($font_widths, 'PEAR_Error')) {
             return $font_widths;
         }
         $i = count($this->_fonts) + 1;
         $this->_fonts[$fontkey] = array('i' => $i, 'type' => 'core', 'name' => $this->_core_fonts[$fontkey], 'up' => -100, 'ut' => 50, 'cw' => $font_widths[$fontkey]);
     }
     /* Store font information as current font. */
     $this->_font_family = $family;
     $this->_font_style = $style;
     $this->_font_size_pt = $size;
     $this->_font_size = $size / $this->_scale;
     $this->_current_font =& $this->_fonts[$fontkey];
     /* Output font information if at least one page has been defined. */
     if ($this->_page > 0) {
         $this->_out(sprintf('BT /F%d %.2' . FILE_PDF_FLOAT . ' Tf ET', $this->_current_font['i'], $this->_font_size_pt));
     }
 }
Esempio n. 3
0
 public function createPDF()
 {
     if ($this->pdf === null && $this->outputFormat == 'pdf') {
         if ($this->pdfUseTempFileForOutput) {
             $this->pdfFilename = tempnam('/tmp', 'rpt');
         }
         $this->pdf = @File_PDF::factory(array('format' => $this->pdfPageFormat, 'orientation' => $this->pdfPageOrientation, 'unit' => 'pt'));
         $this->pdf->_auto_page_break = false;
     }
     $this->pdfFilePointer = fopen($this->pdfFilename, 'wb');
 }