Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Printing address labels from a web application

Printing address labels from the web



10:45 am on Jul 8, 2005 (gmt 0)

10+ Year Member

Anybody got any good ideas for printing a mailing list from a web site?

The web site collects client contact details including mailing address and I want to output that on a local printer onto printing label. The web site is hosted remotely so I canít access the database directly but I was thinking about a web service of some type. Ideally I would search the database by criteria and print off labels as appropriate.

Anybody know if you can run a word mail merge using a web service as a data source?

Anybody got any better ideas?


12:18 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

The webservice or WordML is the better solution for word 2003.

For word 2K I use find and replace on a standard label template from VBScript in HTML. For word 2002/XP mailmerge over OLEDB works fine.

One big problem is sending a record id parameter to word when automating it, in theory it can be done with the Run command, but its buggy. So for Word2K I code client side vbscript with actual text values, after calling the database query


10:13 am on Jul 12, 2005 (gmt 0)

10+ Year Member

Thanks for your input.

Just to get this straight in my mind when you talk about a mail merge with OLEDB are you suggesting you create a VB application that accepts the web service data and then passes that data to an underlying database with which you can then mail merge?

Or are you suggesting you can somehow create an OLEDB data connection to the web service (please excuse my ignorance if this is a silly question!)


6:34 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

If your database reachable by IP, i.e a VPN, you can just use Words built in mailmerge and connect to a View or Table.

If your database is not reachable then you need to connect to a webservice on the webserver, I havent done such in Work2K or XP but Word03, WordProcessingML seems to be able to do this.

The other way is to connect to the data source via ASP, & create a clientside vbscript with actual data, then automate word on the client with a pre-defined template and populate it using find and replace

Actually, I find the latter, VBScript methods much faster for a single page of labels because all the automation and address formatting is done before making the word application visible.


6:51 pm on Jul 14, 2005 (gmt 0)

10+ Year Member

I think you might be going about this task the hard way...

I just created some label maker pages a couple of months ago. Here's how:

Top of the ASP page:

Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment; filename=LabelExport.doc"

Use a SQL query or web service to retrieve your name/address results.

Here's my CSS style. Notice the "@page"

font-family: IDAutomationHC39M;
font-size: 10pt;
font-family: Arial;
font-size: 12pt;

@page Section1
size:3.5in 1.0in;
margin: .10in .15in .0in .15in;


Output code enclosed inside of a div

response.Write "<div class=""Section1"">"
response.Write "</div>"

Output a page break after each label

response.Write "<br clear=all style='page-break-before:always'>"

Let me know if you need all the code - I'd be happy to email it to you.



2:48 pm on Jul 15, 2005 (gmt 0)

10+ Year Member

I like the last response although I'll admit the style sheet is a little over my head.

I've got no problem grabbing the address details from the database and sticking in them on the page using a repeater or something similar.

I assume I can ignore the barcode bit and that the second section just defines the font used on each label.

I assume that @page Section1 defines the page size (label size) with margins etc and then the div.Section1 assigns the page size to the content of each div?

Presumably you have a number of columns/rows to match the number of labels on the sheet?

Have you ever tried this sort of approach with a label printer rather than sticking sheets through a conventional printer? I assume this would be easier still as you donít have to worry about which label you are starting on?

Thanks for all the comments.


4:58 pm on Jul 15, 2005 (gmt 0)

10+ Year Member

You know, I probably should have just left the ".barcode" and "TD" sections out of the stylesheet. You're right on with the second two pieces of stylesheet code.

This piece of code is, in fact, only for a label printer setup. The "<br clear=all style='page-break-before:always'>" piece of the code will actually cause a page break when printing the document. To use this piece of code with a normal printer of label stickies, you'd have to leave the <br> out and use more <tr><td> spacing...


2:45 pm on Jul 17, 2005 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I found another way to "prepare" labels. I'm still having a wee bit of trouble with your idea, especially since I want to prepare address labels (3 across - 10 down) as well as other templates. Your idea will produce one label per page.

I tried the MS Word route - did the merge, saved as an MTH file and examined the code. I thought I would prepare a file that way, but what a mess!

So instead I prepared a TXT document which was downloaded to the users desktop, which they can use to merge their own in Word or Works, etc. Even works on the Mac.

And with the Mozilla printing bug, several of my users couldn't print labels past the first page, so this will help them. Plus I don't have to worry about web formating the labels any more.

I created a ".lbl" file (which forces the download instead of txt) and let them do the Mail Merge into labels.

The next step would be to write a VBA in Word that would read that file automatically and avoid all the steps involved.

Anyone know how to do that?



2:52 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

You can use a remote merge file like this.

Set objXML = CreateObject("Microsoft.XMLHTTP")
Set objFile = CreateObject("Scripting.FileSystemObject")
objXML.Open "GET", "http:<public address>/RemoteMergeFile.txt", False
strMergeData = objXML.responseText
strMergeFile = "\\<local address>\My Data Sources\LocalMergeFile.txt"
Set objTextStream = objFile.OpenTextFile(strMergeFile, 2, True)
objTextStream.Write strMergeData
with ActiveDocument.MailMerge
.OpenDataSource Name:= strMergeFile
.Execute Pause:=False
end with


Featured Threads

Hot Threads This Week

Hot Threads This Month