Forum Moderators: open

Message Too Old, No Replies

Not printing labels from Asp page correctly

Not printing labels from Asp page correctly

         

danielm28

8:30 pm on Dec 22, 2003 (gmt 0)

10+ Year Member



Hello,

I need to be able to print labels (Avery 5160) from an asp page. The label info is coming from a mssql7 db. Here is the code currently being used to create the labels asp page:

--------------------

<html>
<head>
<STYLE TYPE="text/css">
P.breakhere {page-break-before: always}
</STYLE>
<STYLE TYPE="text/css">
#break
{
PAGE-BREAK-AFTER: always;
}
td { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; font-variant: normal; text-transform: none}
</STYLE>
</head>
<title>Salon Nomination Congrat Letter - World Beauty Awards</title>
<body bgcolor="#FFFFFF" link="#FBB214" leftmargin="10" topmargin="1" marginwidth="8" marginheight="1" >
<%
Set Con2 = Server.CreateObject( "ADODB.Connection" )
Con2.Open session("DBLogin")
%>
<%
Set RS2 = Con2.Execute( "SELECT DISTINCT SalonFirstName,SalonLastName,SalonName,SalonAddress,SalonCity,SalonState,SalonZip,SalonCountry from nomination_form " )
%>
<table width="750" border="0" cellspacing="0" cellpadding="0" valign="top">
<TR> <!-- FIRST ROW-->
<% i = 0 %>
<% While NOT RS2.EOF
i = i +1
%>
<td width="0" valign="top" >
<!-- i :::: <%=i %> -->
<table width="260" border="0" cellspacing="0" cellpadding="0" valign="top"> <!-- START - INNER TABLE -->
<tr valign="top">
<td colspan="3" Height="15">
<%=Left(RS2("SalonFirstName")& " " &RS2("SalonLastName"),40)%></b></font>
</td>
</tr>
<tr valign="top">
<td colspan="3" Height="15">
<%=Left(RS2("SalonName"),50) %>
</td>
</tr>
<tr valign="top">
<td colspan="3" Height="15">
<%=Left(RS2("SalonAddress"),40) %>
</td>
</tr>
<tr valign="top">
<td colspan="3" Height="15">
<%=RS2("SalonCity") %>, &nbsp;<%=RS2("SalonState") %> ,&nbsp;<%=RS2("SalonZip") %>
</td>
</tr>
<tr valign="top">
<td colspan="3" Height="15">
<% SalonCountry = RS2("SalonCountry") %>

<% IF RS2("SalonCountry") = "UNITED STATES OF AMERICA" THEN%>
<% SalonCountry = "USA" %>
<% END IF %>
<% response.write SalonCountry %>
</td>
</tr>
<tr valign="top">
<td colspan="6" Height="15"></td>
</tr>
</table> <!-- END - INNER TABLE -->
</td>
<% if i MOD 30 = 0 then %>
</TR>
</TABLE><P CLASS="breakhere">
<table width="750" border="0" cellspacing="0" cellpadding="0" valign="top">
<TR valign="top">
<% end if %>

<% IF i mod 3 = 0 THEN%>
</TR><TR>
<% END IF %>
<%
RS2.MoveNext
Wend
RS2.Close
%>
</TR>
</table>

<%
'RS.MoveNext
'Wend
'RS.Close
%>

<% 'end if %>
<P ID="break"></P>
</BODY>
</HTML>

--------------------

The problem is that when I try to print labels they are aligned incorrectly. I read that I can use css absolute positioning to fix this problem. Does anyone have any ideas on how I can get these labels to line up properly?

Thanks,

Daniel

txbakers

11:35 pm on Dec 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HEE HEE! Welcome to my world.

I think I beat this problem in 95% percent of the cases.

It is a long solution though, and requires some client smarts as well. I use absoliute positioning CSS like you described, and everything is created dynamically.

I don't have the code at my finger tips, but basically you need to know the exact position of the first line's labels, and the exact space between the start of each label.

I use variables to store those values, then populate based on the row number and column number.

The actual code is very short, but it replicates as needed.

The real trick, however, is setting the page break margin. Every printer sets different bottom margins. I let the user set how much space is needed between each page by trial and error, then store that value in the database. The next time they sign in it remembers that value so they don't have to go through it again.

It doesn't work all the time, but eliminated about 95% of the complaints.

It is a pain though. I wish there was a better solution. When I find the code, I'll post that section of it.

danielm28

12:39 am on Dec 23, 2003 (gmt 0)

10+ Year Member



TxBakers,

Please let me know if you find that code. It would help tremendously.

Thanks

txbakers

1:27 am on Dec 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the code I use for the labels: I left off all the database stuff, hopefully this will make sense to you. Basically, the horizontal positions are kept in the array called "hor" and the first label is kept at "topmar". I check to see if there is a page break in there and use it. The top position is set with "verti" and incremented by 96 px each row.

Good luck with it, I hope you can solve it better than I did. If you want a demo, drop me a sticky mail and I'll show you through what I did.

CODE:
var topmar = 30;
if (rsLblSet.EOF){
var pgbreak = Number(Request.Form("pgbreak"));
} else {
pgbreak = Number(rsLblSet("pgbreak"));
}
var verti = -13;
var hor = [10, 79, 148];

<DIV STYLE="position:absolute;
left:<%=hor[colnum]%>mm;
<% if (rownum == 0 && firsttime == 1) {
verti = topmar ;
firsttime = 0;
} else {
if (rownum == 0 && colnum == 0) {
verti += pgbreak;
} else if (colnum == 0){
verti += 96
}
} %>
top:<%=verti%>px;
font-family:<%=ffamily%>;
font-size:<%=fsize%>;
">

<font color="<%=colors[0]%>"><%=line[0]%></font><br>
<font color="<%=colors[1]%>"><%=line[1]%></font><br>
<font color="<%=colors[2]%>"><%=line[2]%></font><br>
<font color="<%=colors[3]%>"><%=line[3]%></font><br>
<font color="<%=colors[4]%>"><%=line[4]%></font><br>
<font color="<%=colors[5]%>"><%=line[5]%></font>
</div>

<% colnum += 1;
if( colnum == 3) {
colnum = 0;
rownum += 1;
if (rownum == 10) rownum = 0;
}

rsStu.MoveNext(); }
%>