Inkscape to print labels

Discussion about writing code for Inkscape.
iconberg
Posts: 36
Joined: Wed Feb 04, 2015 7:46 pm

Inkscape to print labels

Postby iconberg » Thu Jun 25, 2015 11:39 pm

Hello,

i have made a small programm to combine svg-templates with csv-files, supporting linked gfx and EAN13-Barcode, pdf generating and printing.
GUI is not finished but working. Maybe someone has a hint how to choose printer for win and linux.

It works good so far, but i cant find a way to adjust font-size if replaced text is to big for a field.
Thought i could use transform to a specific size but that is not working, maybe someone have another idea.
It is complety in python3, so dont try to make an extension out of it. :)

It only modifies elements starting with id barcode, tspan, image and flowpara.
To make images working in templates delete "sodipodi:absref" and set "xlink:href" to "{image}" or "c:\temp\{image}" for example

Start it with ol_gui.py, anyway you can use the modules without gui. If it is not or partialy working check the config-file.

Any advises or hints are welcome.

Greetz
Attachments
openlabel.zip
(46.65 KiB) Downloaded 274 times

iconberg
Posts: 36
Joined: Wed Feb 04, 2015 7:46 pm

Re: Inkscape to print labels

Postby iconberg » Tue Jul 21, 2015 10:02 pm

Update:

- open templates with inkscape by double click on template
- big boost speed in generating pdfs by feeding one instance of inkscape shell with commands
maybe useful for others using inkscape shell:

Code: Select all

        self.ink_shell = ['c:/programme/inkscape/inkscape.com', '--shell']

        if self.make_pdf_flag:
            info = subprocess.STARTUPINFO()
            info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            info.wShowWindow = subprocess.SW_HIDE           
            cmd = subprocess.Popen(self.ink_shell,
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   startupinfo=info
                                   )
           
            for entry in filelist:
                shellcmd = self.pdf_cmd.format(**entry)
                shellcmd = shellcmd.replace('\\', '/') # didnt work else on win
                cmd.stdin.write(bytes(shellcmd + '\n', 'utf-8'))
                cmd.stdin.flush()
                print(shellcmd)

            cmd.stdin.write(bytes('quit' + '\n', 'utf-8'))
            cmd.stdin.flush()
            cmd_out, cmd_err = cmd.communicate()
            print(cmd_out.decode(), end="")
            print(cmd_err.decode(), end="") 
Attachments
openlabel_update.zip
(15.7 KiB) Downloaded 251 times

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Inkscape to print labels

Postby brynn » Wed Jul 22, 2015 4:44 am

This is not something I'm likely to use. But I wanted to say thanks for your work, and ask a couple of questions.

In the first message you said "don't try to make an extension out of it". So if it's not an extension, what is it? Is it a stand alone program that calls up Inkscape to do certain parts of the work? Or is this for the commandline? And why not make an extension out of it?

iconberg
Posts: 36
Joined: Wed Feb 04, 2015 7:46 pm

Re: Inkscape to print labels

Postby iconberg » Wed Jul 22, 2015 5:25 am

brynn wrote:This is not something I'm likely to use. But I wanted to say thanks for your work, and ask a couple of questions.

In the first message you said "don't try to make an extension out of it". So if it's not an extension, what is it? Is it a stand alone program that calls up Inkscape to do certain parts of the work? Or is this for the commandline? And why not make an extension out of it?


Just wanted to say you have write the code down to python2 first, if you want to make an extension out of it.
Yes, it is standalone. I thought about making an extension in python2 that passes all to an python3 enviroment. Should not be a big throw, but havent time for it yet. I posted an idea about it in the past, cant find it now.
I just layout the labels in inkscape. The standalone calls inkscape to open the label templates and for generating pdfs.
First i call inkscape via commandline for every pdf, changed it to feeding inkscape via shell, works much faster now if you need to generate lot of labels.
Didnt make an extension cause i dont want to write it in python2. But everyone can port in to python2 and make an extension out of it.
I upload it on an source code hoster if iam satisfied with it, but for that i have to find a way to size text fields for fitting on the label. Guessed i spent 3 times more in playing around to find a way for it than coding it till now. :D

You sayed: This is not something I'm likely to use.
No need for it? Or it is bad to use, just tell and i see if i can improve it.

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Inkscape to print labels

Postby brynn » Wed Jul 22, 2015 5:49 am

You sayed: This is not something I'm likely to use.
No need for it? Or it is bad to use, just tell and i see if i can improve it.


Oh no, nothing bad! Just personally I don't need to make labels. I'm sure lots of people need to make labels and are looking for a way to do it with Inkscape. So I'm happy now we can refer them to this topic, and they can try it.

Thanks again :D


Return to “Programming”