top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Making Labels from python

+1 vote
445 views

Does anybody an idea how to make small formated documents redy to print with python? I would like to print address labels as

firstname lastname
street and number
cip and city

The best should be to form a PDF and send it to the label printer. So the PDF could be given the pagesize (labelsize) and a minimum format (boldface). But may be there is another light-weight-format besides PDF?

posted Mar 9, 2014 by Ahmed Patel

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote

The most reliable ready to print  document formats are:

  • plain text
  • PDF

All others, AFAIK, are significantly less reliable for that purpose.

The ReportLab PDF library is a comprehensive library for this for general page layout and PDF generation.

answer Mar 9, 2014 by Bob Wise
0 votes

If generating PDF is too heavy for your liking, you could generate some simple HTML instead and use appropriate CSS (page-break etc) to make it suitable for correct printing (which you can do from your web browser). I've used this technique rather successfully myself and generating the HTML for address labels should be fairly trivial. Getting the css right can be a bit of trial and error depending on the browser you're using.

answer Mar 9, 2014 by Majula Joshi
0 votes

You can try PostScript. It can be emitted from any programming language without any special support (and any special support would probably only get in the way).

A possibility is also the xlwt module, which allows you to generate Excel documents. I have used to great success, but the results may not be ready to print.

answer Mar 9, 2014 by anonymous
Similar Questions
+1 vote

I am working on integration of multiple GUI (Tkinter) elements, such a progress bar, label update, etc, and throughout my research i discovered that i need to have Threading modules used to distribute the calls for GUI update and processing of my main App.

My Application is broken into multiple Classes(modules), and i wanted to hear your thought on the best practices to implement the Threading model.

I was thinking to create a new py-module, and reference all other modules/class to it, and create thread.start() objects, that would execute the GUI part, other will handle GUI Updates, and other - will be doing the processing.

Please share some of your thought on this approach, or maybe you may suggest a more effective way.

0 votes

i want to sent a response for my form submit from server to client, that means python flask to javascript. My javascript code is given follows

document.addEventListener('DOMContentLoaded', function() {

chrome.tabs.getSelected(null, function(tab) {
  d = document;
  var f = d.createElement('form');
  f.action = 'http://127.0.0.1:5000/Get%20Form/';
  f.method = 'post';
  var i = d.createElement('input');
  i.type = 'hidden';
  i.name = 'url';
  i.value = tab.url;
  f.appendChild(i);
  d.body.appendChild(f);
  f.submit();   
});
$(".button").click(function(){
    request = new XMLHttpRequest();
    request.open("POST","http://127.0.0.1:5000/PutValue/",true);
    request.send();
    request.addEventListener("readystatechange", processRequest,false);
    function processRequest(e)
    {
    if(request.readyState==4 && request.status == 200)
    {
    var response = JSON.parse(request.responseText);
    a=response.result
    alert(a);
    }
    }
});
},false);

And my Python server code is follows

from flask import Flask, flash, redirect, url_for, request, render_template,jsonify
import json
import UrlTest
import trainingSet as ts

app = Flask(__name__)
user=""
s=0

@app.route('/Get Form/',methods = ['POST'])
def GetForm():
request.method == 'POST'
url=request.form['url']
UrlTest.process_test_url(url,'test_features.csv')
s=ts.main_caller('url_features.csv','test_features.csv')
print s
return str(s)

@app.route('/PutValue/',methods = ['POST'])
def PutValue():
request.method == 'POST'
print s
return jsonify(result=s)


if (__name__ == '__main__'):
app.run(debug=True,host='0.0.0.0', use_reloader=False)

I want to send the value of s to the javascript client. please help me to send this the value of s.
and if u can suggest the complete code in javascipt and python

0 votes

I want to submit a qsub job to my hpc cluster from within python. In this case, I must set some environment variables specific for this qsub job and then invoking a bash script from within python.

What python code should be used for this job?

...