Elderl23 / pyfpdf

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Print avery labels with pyfpdf #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have "translated" http://www.fpdf.org/en/script/script29.php to be used with 
pyfpdf.
Just tell me if you want me to send it to to you using this issue or commiting 
it to the repo if you give me write access.

It adds one file to the sources, BUT it requires one change in fpdf.py:

class FPDF():
must be modified to
class FPDF(object):

The labels class inherited from FPDF and  needs to call a couple of super 
methods, so FPDF needs to be created in this way.
As far as I know, this change doesn't imply anything in the behaviour of FPDF.

Regards.
José L.

Original issue reported on code.google.com by jredr...@gmail.com on 30 Sep 2011 at 8:03

GoogleCodeExporter commented 8 years ago
Added the code with a web2py example project at 
https://github.com/jredrejo/Labels-for-pyfpdf

Original comment by jredr...@gmail.com on 1 Oct 2011 at 3:41

GoogleCodeExporter commented 8 years ago
Yes, your are welcome, thanks!

If you don't broke anything, you can just commit the changes ;-)

Please create a scripts directory for pdflabels.py

A wiki page explaining how it works would be good.

Original comment by reingart@gmail.com on 3 Oct 2011 at 5:46

GoogleCodeExporter commented 8 years ago
Code changes committed in rev 208314825f21
I'll upload an example of use and a wiki page asap.

Original comment by jredr...@gmail.com on 7 Oct 2011 at 11:55

GoogleCodeExporter commented 8 years ago
When I tried to use it, the Avery-5160 did not format correctly.  I got it to 
work by changing it to:

'Avery-5160':{'paper-size':'letter', 'metric':'mm', 
'marginLeft':6.762,'marginTop':12.7,'NX':3,'NY':10,'SpaceX':3.175,'SpaceY':0, 
'width':66.675,'height':25.4,'font-size':10}

I believe the marginTop was a typo during inch-mm conversion from the Avery 
specs.  The marginLeft may have been okay, but all of the labels were left 
justified.  Not sure if that should be changed in the code or not.  The 
font-size is a personal preference.

Original comment by schn...@gmail.com on 21 Jul 2014 at 8:22

GoogleCodeExporter commented 8 years ago
I can not confirm it because I don't have that avery paper. I based this  on 
http://fpdf.de/downloads/addons/29/ . The differences between both values don't 
match with a inches-mm conversion error. Now I have found 
https://github.com/lsolesen/fpdf/blob/master/examples/label/PDF_Label.php that 
adds some improvement to the previous code, but it still keeps the same margin 
values.
Is there any source with the right values that we can trust?

Original comment by jredr...@gmail.com on 23 Jul 2014 at 9:19

GoogleCodeExporter commented 8 years ago
This page is the second result when doing a Google search "python avery 
labels". So, if someone else comes here wanting a straightforward how-to, 
here's what worked for me:

1. pip install fpdf
2. Download 
https://raw.githubusercontent.com/jredrejo/Labels-for-pyfpdf/master/pyfpdf/pdfla
bels.py into your working directory.

Example code:
    import pdflabels # pity this can't be merged into the fpdf package

    pl = pdflabels.PDFLabel('Avery-5160')
    pl.add_page()
    pl.add_label("%s\n%s\n%s\n%s %s"%("Joe Blow","123 Main St","Anytown","Anystate","XY 12345")
    pl.add_label(....)
    pl.output('addresslabels.pdf', 'F')

Original comment by phi...@taits.org on 30 Nov 2014 at 11:51