function image_scaled($image, $x, $y, $scale_x, $scale_y) { $tmpname = tempnam(WRITER_TEMPDIR, WRITER_FILE_PREFIX); imagepng($image->get_handle(), $tmpname); $pim = pdf_open_image_file($this->pdf, "png", $tmpname, "", 0); $this->save(); pdf_translate($this->pdf, $x, $y); pdf_scale($this->pdf, $scale_x, $scale_y); pdf_place_image($this->pdf, $pim, 0, 0, 1); $this->restore(); pdf_close_image($this->pdf, $pim); unlink($tmpname); }
// winansi, host, iso8859-1, unicode >> unicode and glyph id addressing not supported in PDFlib Lite!!! if (NJB_DEFAULT_CHARSET == 'UTF-8') { pdf_set_parameter($pdf, 'textformat', 'utf8'); } pdf_set_info($pdf, 'Creator', 'netjukebox ' . NJB_VERSION); pdf_set_info($pdf, 'Title', $album['artist'] . ' - ' . $album['album']); $width = 210; // A4 $height = 297; // A4 $scale = 72 / 25.4; // mm to dtp-point (1 point = 1/72 inch; 1 inch = 25.4 mm) $hash_data = pdf_get_value($pdf, 'major', 0) . '-' . pdf_get_value($pdf, 'minor', 0) . '-' . NJB_VERSION; $hash_data .= '-' . $album['artist'] . ' - ' . $album['album'] . '-' . $width . '-' . $height; pdf_begin_page($pdf, $width * $scale, $height * $scale); pdf_scale($pdf, $scale, $scale); pdf_setlinewidth($pdf, 0.1); // +------------------------------------------------------------------------+ // | PDF back cover | // +------------------------------------------------------------------------+ $x0 = 30; $y0 = 22; pdf_translate($pdf, $x0, $y0); pdf_moveto($pdf, 0, -1); pdf_lineto($pdf, 0, -11); pdf_moveto($pdf, 6.5, -1); pdf_lineto($pdf, 6.5, -11); pdf_moveto($pdf, 144.5, -1); pdf_lineto($pdf, 144.5, -11); pdf_moveto($pdf, 151, -1); pdf_lineto($pdf, 151, -11);
function _bullet(&$bullet) { $type = ''; $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi'); $height = 10; $txt = strip_markups($bullet->text); pdf_save($this->pdf); pdf_translate($this->pdf, 0, $this->pdf_y); pdf_scale($this->pdf, 1, -1); pdf_set_font($this->pdf, $this->pdf_font, 12, 'winansi'); $leading = pdf_get_value($this->pdf, "leading", null); $inc = $leading; while (pdf_show_boxed($this->pdf, $txt, $this->pdf_cx + 30, $this->pdf_y - $this->pdf_cy, $this->pdf_x - 2 * ($this->pdf_cx + 20), $height, 'left', 'blind')) { $height += $inc; } pdf_restore($this->pdf); //clean up eols so we get a nice pdf output if (strstr($txt, "\r\n")) { $eol = "\r\n"; } elseif (strstr($txt, "\r")) { $eol = "\r"; } else { $eol = "\n"; } $txt = str_replace($eol, " ", $txt); $txt = str_replace(" ", " ", $txt); if ($this->pdf_cy + $height > $this->pdf_y - 40) { $this->my_pdf_page_number($this->pdf, $this->pdf_x, $this->pdf_y); $this->my_new_pdf_end_page($this->pdf); $this->my_new_pdf_page($this->pdf, $this->pdf_x, $this->pdf_y, true); $this->pdf_cx = 40; $this->pdf_cy = 60; } pdf_set_font($this->pdf, $this->pdf_font, -12, 'winansi'); if ($bullet->type == 'speaker') { pdf_setcolor($this->pdf, 'fill', 'rgb', 1, 0, 0, null); } if (!empty($bullet->start)) { if (is_numeric($bullet->start)) { $this->objs[$this->coid]->num = (int) $bullet->start; } else { $this->objs[$this->coid]->alpha = $bullet->start; } } if (!empty($bullet->type)) { $type = $bullet->type; } else { if (!empty($this->objs[$this->coid]->type)) { $type = $this->objs[$this->coid]->type; } } switch ($type) { case 'numbered': case 'number': case 'decimal': $symbol = ++$this->objs[$this->coid]->num . '.'; $pdf_cx_height = 30; break; case 'no-bullet': case 'none': $symbol = ''; $pdf_cx_height = 20; break; case 'alpha': $symbol = $this->objs[$this->coid]->alpha++ . '.'; break; case 'ALPHA': $symbol = strtoupper($this->objs[$this->coid]->alpha++) . '.'; $pdf_cx_height = 30; break; case 'asterisk': $symbol = '*'; $pdf_cx_height = 20; break; case 'hyphen': $symbol = '-'; $pdf_cx_height = 20; break; default: $symbol = 'o'; $pdf_cx_height = 20; break; } pdf_show_xy($this->pdf, $symbol, $this->pdf_cx + 20 + $bullet->level * 10, $this->pdf_cy + $leading - 1); pdf_show_boxed($this->pdf, $txt, $this->pdf_cx + 40 + $bullet->level * 10, $this->pdf_cy - $height, $this->pdf_x - 2 * ($this->pdf_cx + 20), $height, 'left', null); pdf_continue_text($this->pdf, "\n"); $this->pdf_cy = pdf_get_value($this->pdf, "texty", null); pdf_set_text_pos($this->pdf, $this->pdf_cx, $this->pdf_cy - $leading / 2); pdf_setcolor($this->pdf, 'fill', 'rgb', 0, 0, 0, null); }
// Do we have album art? if ($node->getMainArt() != false) { $extension = substr(strrchr($node->getMainArt(), '.'), 1); $extension = strtolower($extension); if ($extension == 'jpg') { $pdfdfimage = pdf_open_image_file($pdf, 'jpeg', $node->getMainArt(), '', 0); } if ($extension == 'png') { $pdfdfimage = pdf_open_image_file($pdf, 'png', $node->getMainArt(), '', 0); } if ($extension == 'gif') { $pdfdfimage = pdf_open_image_file($pdf, 'gif', $node->getMainArt(), '', 0); } $sx = 121 / pdf_get_value($pdf, 'imagewidth', $pdfdfimage); $sy = 120 / pdf_get_value($pdf, 'imageheight', $pdfdfimage); pdf_scale($pdf, $sx, $sy); pdf_place_image($pdf, $pdfdfimage, 0, 0, 1); } // +---------------------------------------------------------------------------+ // | Close PDF | // +---------------------------------------------------------------------------+ pdf_end_page($pdf); pdf_close($pdf); $buffer = pdf_get_buffer($pdf); $file = $artist . ' - ' . $album . '.pdf'; header('Content-Type: application/force-download'); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . $file . '"'); //rawurlencode not needed for header echo $buffer; pdf_delete($pdf);