Public Notification - Avery Label 5160 Aligning Issues

4572
7
06-20-2013 12:52 PM
Labels (1)
JeremyWilliams
New Contributor II
Hi,
I've been working on the Public Notification app for 10.1.  Everything is working, but when the 5160 label is generated, and printed on a 5160 Avery sheet, the labels dont line up.  The first few rows of each sheet are ok, but by the bottom of each page the labels are very far off. 

Any suggestions?  Check out the attachment, this is a label creation from the app.

Thank you!
0 Kudos
7 Replies
MikeTschudi
Occasional Contributor
Hi Jeremy,

Thanks for reporting the problem; I'm able to reproduce it and we will work on it.

Regards,
Mike
0 Kudos
MikeTschudi
Occasional Contributor
Hi Jeremy,

Just to let you know that part of our team is fixing the problem now.

Regards,
Mike
0 Kudos
by Anonymous User
Not applicable
I was also having some major alignment issues with this.  I used the function for the 5160 script and made some modifications.  I have now successfully got it to line up with the 5160 format.  Here is the function with modifications to the python script:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
import os, glob, sys, time
import textwrap

#Logic for averyLabel 5160
def avery5160(outfile, font, font_size, addressInput):
    print 'Creating labels in Avery 5160 format'
    # PDF vars
    if os.path.exists(outfile):
        os.remove(outfile)
    out_pdf = canvas.Canvas(outfile, pagesize = letter)
    out_pdf.setFont(font, font_size)
    addressItem = addressInput.split('$')
    hs = 0.25
    vs = 10.3
    horizontal_start = hs * inch #staring point of label horizontally
    vertical_start = vs * inch #starting point of label vertically
    count = 0           #initially the count is 0

    for item in addressItem:
        
        if count > 0 and count % 30 == 0:
            out_pdf.showPage()
            out_pdf.setFont(font, font_size)
            horizontal_start = hs * inch
            vertical_start = vs * inch
        elif count > 0 and count % 10 == 0:
            horizontal_start = horizontal_start + 2.8 *inch
            vertical_start = vs * inch

        label = out_pdf.beginText()
        label.setTextOrigin(horizontal_start, vertical_start)

        details = item.split('~')
        
        for detail in details:
            if len(detail) > 45:
                name = detail[0:44]
                label.textLine(name)
                name = detail[44:60]
                label.textLine(name)
            else:
                label.textLine(detail)
           
        out_pdf.drawText(label)

        vertical_start = vertical_start - 1.05 * inch  
        count = count + 1

    out_pdf.showPage()
    out_pdf.save()
    print '\nCreated %s\n' %outfile


I have this working together with another script to generate labels (I'm not using it as part of a JS web map service) for the staff in the Assessor's office for my county.  The staff runs a query on parcels they want mailing addresses for and I have a dictionary that pulls the addresses out for the selected parcels and puts them in a text file and generates the labels using the above script.  It took a lot of playing around with the numbers, but finally just got it working properly this morning.  Here's the pdf:


EDIT: I just want to add a small disclaimer.  This works well in my unique situation and I am not sure how well it would work in other situations.  I have this as part of a script that works with another script that builds a text file to add the proper delimiters, etc.  I was using a relatively small font (size 9) with the 'Helvetica' typeface. 

I spent a lot of time playing around with the different intervals(and banging my head against the desk) to ensure the text was properly fitted inside all the slots for the Avery 5160 sheet with my specific fontsize/type.  So my advice to anyone else is to just kind of play around with it and see what kind of outputs you get.  One thing I know, I am definitely sick of looking at this code! 🙂
0 Kudos
ScottOppmann
Esri Contributor
As Mike mentioned, we have been actively working on a resolution to this issue and we'll be shipping a new version of the scripts with our 10.2 release.  The new versions include changes we've made to improve alignment with 5160 labels.  We have tested these changes on several different printers and believe we have a solution that will work for most, but there may still be cases where you need to "tune" the scripts to work with your specific printers. 

Jeremy - thank you for pointing bug out. 

Caleb - thank you for the sample code, it really helped us narrow down the problem and improve the scripts. 

Scott
0 Kudos
JeremyWilliams
New Contributor II
Thanks everyone for following up on this.  I was also able to fix this by changing some of the alignment as stated above.
0 Kudos
JeremyWilliams
New Contributor II
BTW, The staff loves this new application.
0 Kudos
ScottOppmann
Esri Contributor
Jeremy,

Glad to hear you got the Public Notification app working in your organization and for the feedback.  Keep the feedback coming.

Scott
0 Kudos