Some time ago, we include PDFLabel too, so you can simplify your code
if you are using an avery-compatible format ( the sys stuff is only
needed if you're using a non-english language):
def label_bikes():
from gluon.contrib.pyfpdf.pdflabels import PDFLabel
import sys
reload(sys)
sys.setdefaultencoding( "latin-1" )
pdf = PDFLabel('Apli-01277')
pdf.add_page()
rows = db(db.bike.id.belongs(bikeIds)).select()
# Print labels
for row in rows:
idString = row.destination + str(row.id)
more_text = idString
more_text += "Make: " + row.make + "\n" if row.make else ""
more_text += "Model: " + row.model + "\n" if row.model else ""
more_text += "Size: " + row.size + "\n" if row.size else ""
pdf.add_label(more_text)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition']='attachment.filename = sample.pdf'
return pdf.output(dest='S')
Regards
José L.
2013/1/16 Paul Rykiel <[email protected]>:
> Hi Mariano,
> thank you for the response. Let me look into the margin issue, maybe you
> have given me enough to figure this out.
> thanks so much for the response. you know, Massimo was my professor last
> term.
>
> On Wednesday, January 16, 2013 12:39:06 AM UTC-6, Mariano Reingart wrote:
>>
>> Hello Paul:
>>
>> Could you send a sample without actual data?
>> (without the db query, so it can be reproduced)
>>
>> fpdf.cell will jump to the next page if no more room available, maybe
>> there is a sizing or rounding issue.
>> Also, you have to take a look at page margins.
>>
>> Best regards,
>>
>> Mariano Reingart
>> http://www.sistemasagiles.com.ar
>> http://reingart.blogspot.com
>>
>>
>> On Tue, Jan 15, 2013 at 8:02 PM, Paul Rykiel <[email protected]> wrote:
>> > Greetings this is my code:
>> >
>> > def triagePrintTags(bikeIds):
>> > assert(bikeIds != None)
>> > assert(isinstance(bikeIds, list) or isinstance(bikeIds, tuple))
>> > pdf = FPDF('P', 'mm', (66.548, 25.4))
>> > # get all the r(ows
>> > rows = db(db.bike.id.belongs(bikeIds)).select()
>> > for row in rows:
>> > pdf.add_page()
>> > pdf.set_font('Times', 'B', 8)
>> > idString = row.destination + str(row.id)
>> > pdf.cell(0, 2, idString, 0, 1)
>> > if row.make != None:
>> > pdf.cell(0, 2, "Make: " + row.make,0,1)
>> > if row.model != None:
>> > pdf.cell(0, 2, "Model: " + row.model,0,1)
>> > if row.size != 0:
>> > sz = "Size: " + str(row.size)
>> > pdf.cell(0, 2, sz,0,1)
>> > if row.color != None:
>> > pdf.cell(0, 2, "Color: " + row.color,0,1)
>> > # TODO this should be a true temp file, stored in /tmp with random
>> > unique filename.
>> > fileName = request.folder + '/static/temp.pdf'
>> > pdf.output(name=fileName)
>> > response.headers['Content-Disposition']='attachment.filename =
>> > sample.pdf'
>> > response.headers['Content-Type']='application/pdf'
>> > return response.stream(open(fileName, 'rb'), chunk_size=4096)
>> >
>> > the problem with the above code is:
>> >
>> > my dimentions of my page are supposed to simulate a label (no problem)
>> > my text should all be on the same label, but when the next cell prints,
>> > it
>> > jumps to the
>> > next label. What am I doing incorrectly here?
>> >
>> > Or maybe is it is just wrong print with pdf.cell, maybe there is a
>> > better
>> > way.
>> > Please help if you can?
>> >
>> > Thank you in advance.
>> >
>> >
>> >
>> >
>> >
>> > --
>> >
>> >
>> >
>
> --
>
>
>
--