Asked  7 Months ago    Answers:  5   Viewed   327 times

I've taken a dive into FPDF lately and something that i don't seem to understand is - why is there no way to set a bottom margin? There are functions for setting margins from the top, left and right, but not from the bottom.

I assume now that i misunderstand something basic and conceptual about how FPDF works yet i got no clue on what that could possibly be.

So to cut it down:

Is it possible to define a fixed bottom margin in FPDF?

 Answers

91

I just found the solution - the bottom margin is simply left out of predefinition because it is part of the page break calculation process. Therefore, setting a bottom margin in itself is not possible, but it can be done using

SetAutoPageBreak(boolean auto, [float margin])
Wednesday, March 31, 2021
 
jab
answered 7 Months ago
jab
31

Use GetY to get the current position, subtract it from the height of your document. If that is less than 6x (you have 6 rows) your multicell height, then force a page break by using AddPage.

I know you fixed this, but for the benefit of anyone else, this should give a broad idea.

<?php
$p = new FPDF();
$p->AddPage();
$p->SetFont('Arial','B',16);
$p->SetAutoPageBreak(false);
$height_of_cell = 60; // mm
$page_height = 286.93; // mm (portrait letter)
$bottom_margin = 0; // mm
  for($i=0;$i<=100;$i++) :
    $block=floor($i/6);
    $space_left=$page_height-($p->GetY()+$bottom_margin); // space left on page
      if ($i/6==floor($i/6) && $height_of_cell > $space_left) {
        $p->AddPage(); // page break
      }
    $p->Cell(100,10,'This is a text line - Group '.$block,'B',2);
  endfor;
$p->Output();
?>
Wednesday, March 31, 2021
 
hjalpmig
answered 7 Months ago
64

http://www.fpdf.org/en/tutorial/tuto5.htm:

Just use:

$pdf->Cell(width, height, text, border, position-next-cell, alignment);

So this means, to add a column afterwards 'position-next-cell' should be 0 what you're looking for is probably:

$pdf->Cell(133.5, 2.7, $address, 0, 0, 'L');
$pdf->Cell(53.5, 2.7, $version, 0, 1, 'L');

After the 2nd call you noticed the 1 which means a next cell is being placed underneath and not after (which the 0 would do.)

Wednesday, March 31, 2021
 
bumperbox
answered 7 Months ago
33

The key is to realize that setting it in code like this:

sp2.Margin = new System.Windows.Thickness{ Left = 5 };

is equivalent to:

sp2.Margin = new System.Windows.Thickness{ Left = 5, Top = 0, Right = 0, Bottom = 0 };

You can't set just a single value in a Thickness instance through either code or XAML. If you don't set some of the values, they will be implicitly zero. Therefore, you can just do this to convert the accepted code sample in your other question to a XAML equivalent:

<StackPanel Margin="{Binding TopMargin, Converter={StaticResource MyConverter}}"/>

where MyConverter just returns a Thickness that sets only the Top and leaves all other values as zero.

Of course, you could write your own control that does expose these individual values as dependency properties to make your code a little cleaner:

<CustomBorder TopMargin="{Binding TopMargin}">
</CustomBorder>

A better option than a custom control would be to write an attached property and change the Thickness using the code above in the dependency property setter. The below code would be usable across ALL controls which have a Margin.

public static readonly DependencyProperty TopMarginProperty =
    DependencyProperty.RegisterAttached("TopMargin", typeof(int), typeof(FrameworkElement),
                                        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
public static void SetTopMargin(FrameworkElement element, int value)
{
    // set top margin in element.Margin
}
public static int GetTopMargin(FrameworkElement element)
{
    // get top margin from element.Margin
}

If you couple this with a Behavior, you can get notification changes on the TopMargin property.

Thursday, July 29, 2021
 
oroshnivskyy
answered 3 Months ago
62

The entry is called bugtrack_url, but it's not being picked up from setup.py.

From context and code I understand it was intended to be used through-the-web on PyPI only, as per-project metadata, and not the usual per-release information.

The field is now considered a legacy field (hardcoded to None) and you instead add such information through the Project-URL list, which you can set in setuptools via the project_urls entry:

    project_urls={
        'Documentation': 'https://packaging.python.org/tutorials/distributing-packages/',
        'Funding': 'https://donate.pypi.org',
        'Say Thanks!': 'http://saythanks.io/to/example',
        'Source': 'https://github.com/pypa/sampleproject/',
        'Tracker': 'https://github.com/pypa/sampleproject/issues',
    },

This option was finally added to setuptools in November 2017, and landed in version 38.3.0.

Monday, August 9, 2021
 
Boas Enkler
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :