本文整理汇总了PHP中FPDF::setMargins方法的典型用法代码示例。如果您正苦于以下问题:PHP FPDF::setMargins方法的具体用法?PHP FPDF::setMargins怎么用?PHP FPDF::setMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FPDF
的用法示例。
在下文中一共展示了FPDF::setMargins方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pdf_export_dots
function pdf_export_dots(&$dots, &$more)
{
# PLEASE FOR TO BE CACHING ME, OBIWAN...
# (20110120/straup)
$w = 11;
$h = 8.5;
$margin = 0.5;
$dpi = 72;
$header_h = 0.2;
$row_h = 0.2;
$col_width = 1.25;
# Here we go...
$pdf = new FPDF("P", "in", array($w, $h));
$pdf->setMargins($margin, $margin);
# The legend gets added below (once we've figured out what page
# each dot is on) but we'll just declare it here.
$legend = array();
$count_legend_items = floor($h / ($row_h * 1.4));
$count_clusters = ceil(count($dots) / $count_legend_items);
# Just turn clusters off for now... the map rendering time
# is still too long for multiple map images (20110120/straup)
$count_clusters = 1;
$clusters = array();
if ($count_clusters == 1) {
$clusters = array($dots);
} else {
$points = array();
$i = 0;
foreach ($dots as $dot) {
$points[] = array('x' => (double) $dot['longitude'], 'y' => (double) $dot['latitude'], 'id' => $dot['id'], 'idx' => $i);
$i++;
}
$_clusters = kmeans_cluster($points, $count_clusters);
foreach ($_clusters as $_cluster) {
$_dots = array();
foreach ($_cluster as $_pt) {
$_dots[] = $dots[$pt['idx']];
}
$clusters[] = $_dots;
}
}
#
# First generate all the maps
#
$maps = array();
$img_more = array('width' => $h * $dpi, 'height' => $h * $dpi, 'dot_size' => 15);
foreach ($clusters as $dots) {
list($map, $gd_img) = maps_image_for_dots($dots, $img_more);
$maps[] = maps_gd_to_png($gd_img, 'pdf');
}
# Now figure out the what is the what of the dots
$columns = array();
$cols_per_page = floor(($w - $margin * 2) / $col_width);
$count_cols = count($more['columns']);
$pages_per_row = ceil($count_cols / $cols_per_page);
# See this? We're adding enough extra columns and re-counting
# everything in order to ensure that every page for each row
# has an 'id' column
if ($pages_per_row > 1) {
$_count = $count_cols + ($pages_per_row - 1);
$pages_per_row = ceil($_count / $cols_per_page);
}
# First, chunk out the header in (n) pages and measure the
# height of the (header) row itself
$_h = $header_h * 1.3;
$pdf->SetFont('Helvetica', 'B', 10);
for ($i = 0; $i < $count_cols; $i++) {
$col_name = $more['columns'][$i];
$b = floor($i / $cols_per_page);
if (!is_array($columns[$b])) {
$columns[] = array();
}
$columns[$b][] = $col_name;
$str_width = ceil($pdf->GetStringWidth($more['columns'][$i]));
if ($str_width > $col_width) {
$lines = ceil($str_width / $col_width);
$_h = max($_h, $lines * $header_h);
}
}
$header_h = $_h;
# make sure every page has an 'id' field
# (see above)
$count_columns = count($columns);
for ($i = 0; $i < $count_columns; $i++) {
$cols = $columns[$i];
if (!in_array('id', $cols)) {
array_unshift($cols, 'id');
$columns[$i] = $cols;
}
# move stuff around so that we keep the pages nice and tidy
if (count($columns[$i]) > $cols_per_page) {
$to_keep = array_slice($columns[$i], 0, $cols_per_page);
$extra = array_slice($columns[$i], $cols_per_page);
$columns[$i] = $to_keep;
$columns[$i + 1] = $extra;
}
}
# Now work out the height of each row of dots
$row_heights = array();
$pdf->SetFont('Helvetica', '', 10);
//.........这里部分代码省略.........
示例2: initialize_pdf
/**
* Sets up a new PDF object with the necessary settings
*
* @return FPDF A new PDF object
*/
protected function initialize_pdf()
{
global $CFG;
require_once $CFG->libdir . '/fpdf/fpdf.php';
$newpdf = new FPDF('L', 'in', 'letter');
$newpdf->setMargins(self::marginx, self::marginy);
$newpdf->SetFont('Arial', '', 9);
$newpdf->AddPage();
$newpdf->SetFont('Arial', '', 16);
$newpdf->MultiCell(0, 0.2, $this->report->title, 0, 'C');
$newpdf->Ln(0.2);
$newpdf->SetFont('Arial', '', 8);
$newpdf->SetFillColor(225, 225, 225);
return $newpdf;
}
示例3: pdf_barcode
Define("H_MARGIN", 13);
Define("COL_SIZE", 22);
Define("ROW_SIZE", 16);
Define("COL_NUM", 9);
Define("ROW_NUM", 17);
Define("V_PADDING", 0);
Define("H_PADDING", 0);
Define("BARCODE_WIDTH", 20);
Define("BARCODE_HEIGHT", 10);
Define("TEXT_HEIGHT", 3);
Define("TEXT_SIZE", 8);
}
require_once \Pasteque\PT::$ABSPATH . "/lib/barcode-master/php-barcode.php";
$font = "./lib/barcode-master/NOTTB___.TTF";
$pdf = new \FPDF(PAPER_ORIENTATION, "mm", PAPER_SIZE);
$pdf->setMargins(H_MARGIN, V_MARGIN);
$pdf->setAutoPageBreak(false, V_MARGIN);
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', TEXT_SIZE);
function pdf_barcode($pdf, $productId, $col, $row)
{
$product = \Pasteque\ProductsService::get($productId);
$x = H_MARGIN + $col * COL_SIZE + $col * H_PADDING;
$y = V_MARGIN + $row * ROW_SIZE + $row * V_PADDING;
$pdf->SetXY($x, $y);
$pdf->Cell(BARCODE_WIDTH, TEXT_HEIGHT, utf8_decode($product->reference), 0, 1, "C");
$pdf->SetXY($x, $y + TEXT_HEIGHT);
$data = \Barcode::fpdf($pdf, "000000", $pdf->GetX() + BARCODE_WIDTH / 2, $pdf->GetY() + BARCODE_HEIGHT / 2, 0, "ean13", array('code' => $product->barcode), BARCODE_WIDTH / (15 * 7), BARCODE_HEIGHT);
$pdf->SetXY($x, $y + BARCODE_HEIGHT + TEXT_HEIGHT);
$pdf->Cell(BARCODE_WIDTH, TEXT_HEIGHT, $product->barcode, 0, 1, "C");
}
示例4: download
//.........这里部分代码省略.........
$formatr->set_color('red');
$formatr->set_align('center');
$formatg =& $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
$rownum = 0;
$colnum = 0;
foreach ($this->headers as $header) {
$myxls->write($rownum, $colnum++, $header, $formatbc);
}
foreach ($this->data as $datum) {
if (!is_object($datum)) {
continue;
}
$rownum++;
$colnum = 0;
foreach ($this->headers as $id => $header) {
if (isset($datum->{$id})) {
$myxls->write($rownum, $colnum++, $datum->{$id}, $format);
} else {
$myxls->write($rownum, $colnum++, '', $format);
}
}
}
$workbook->close();
break;
case 'pdf':
require_once $CFG->libdir . '/fpdf/fpdf.php';
$filename .= '.pdf';
$newpdf = new FPDF('L', 'in', 'letter');
$marginx = 0.75;
$marginy = 0.75;
$newpdf->setMargins($marginx, $marginy);
$newpdf->SetFont('Arial', '', 9);
$newpdf->AddPage();
$newpdf->SetFont('Arial', '', 16);
$newpdf->MultiCell(0, 0.2, $this->title, 0, 'C');
$newpdf->Ln(0.2);
$newpdf->SetFont('Arial', '', 8);
$newpdf->SetFillColor(225, 225, 225);
$heights = array();
$widths = array();
$hmap = array();
$rownum = 0;
/// PASS 1 - Calculate sizes.
foreach ($this->headers as $id => $header) {
$widths[$id] = $newpdf->GetStringWidth($header) + 0.2;
}
$row = 0;
foreach ($this->data as $datum) {
if (!isset($heights[$row])) {
$heights[$row] = 0;
}
foreach ($this->headers as $id => $header) {
if (isset($datum->{$id})) {
$width = $newpdf->GetStringWidth($datum->{$id}) + 0.2;
if ($width > $widths[$id]) {
$lines = ceil($width / $widths[$id]);
$widths[$id] = $width;
} else {
$lines = 1;
}
$height = $lines * 0.2;
if ($height > $heights[$row]) {
$heights[$row] = $height;