• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Miseries in life and Zebra Printing

Here is my challenge,

I have a application (intranet) that prints badges for some of our seminars.  this application prints to a local printer (zebra stripe).

I have gotten cf to commuicate and pass the text and print but am having an issue when the "company is longer than 49 charactes.

when it is greater than 49 characters it does not know how to go to the next line so what I m trying to accoplish is the following.
Using the code below:

I want cf to count the using len of the string, once 49 is met display the first 49 chars on the first line then create another line and continue printing (displaying the remainder) on the newly created line.

let me know if any of you can help me: here is the code that is written to a text file for printing.

<CFSAVECONTENT VARIABLE="Preview">
 
  <CFLOOP QUERY="test">
 
   ^XA
     ^LH25,90
     ^CF0
     ^FB750,1,0,C
<!--- assuming this is coming from a query in a loop --->    
        ^XA
^LH25,90
^CF0
^FB750,1,0,C
<!---new line--->    
^FO0,80^A0,97,120^FD<cfoutput>#Trim(ucase(Fname))#</cfoutput>^FS

^FB750,1,0,C
<!---new line--->    
^FO0,185^A0,50,50^<cfoutput>FD#trim(fname)# #trim(LName)#</cfoutput> ^FS

<!---here is when it encounters a string less than 31 chars long, it displays fine--->
<cfif len(company)lte 31>
^FB750,1,0,C
<!---new line--->    
^FO0,250^A0,56,56^FD<cfoutput>#Trim(company)# </cfoutput>^FS
</cfif>

<!---here is when it encounters a string gte than 32 chars long but not longer than 42, it displays fine--->
<cfif len(company)gte 32 and len(company) lte 42>
^FB750,1,0,C
<!---new line--->    
^FO0,250^A0,43,43^FD<cfoutput>#Trim(company)# </cfoutput>^FS
</cfif>
<!---here is where I need it to split the string as stated in original delema--->

??????


^FB750,1,0,C
<!---new line--->    
^FO0,320^A0,56,56^FD<cfoutput>#Trim(city)#, #trim(state)#</cfoutput>^FS
^FS
^XZ

</CFLOOP>

</CFSAVECONTENT>

0
jriver12
Asked:
jriver12
  • 7
  • 6
  • 2
1 Solution
 
mrichmonCommented:
What you can do is loop over the string like this :

<cfset linecount = Ceiling(Len(company) / 49)>

<cfloop from="1" to="#linecount#" index="n">
#Mid(company, (n-1)*49 + 1, 49)#
<!--- print your new line here --->
</cfloop>

So the first time it prints 49 characters starting at position 1
The next time it prints 49 characters starting at position 50
The next time it prints 49 characters starting at position 99
etc...
0
 
jriver12Author Commented:
Mrichmon,
Thanks for the example, it works, with a bug.
here is the code:
<cfloop from="1" to="#linecount#" index="n">
^FB750,1,0,C
^FO0,250^A0,56,56^FD<cfoutput>#Mid(company, (n-1)*31 + 1, 31)# </cfoutput>^FS
</cfloop>

now what is happenin is that the code does cut it off at the right place, however
it does not drop a line because of the following bit of code.
^FO0,250
where the 250 is the position of the text on the badge. now im confronted with the issue of how to drop the possition down 70 for each additional line.

any suggestions?
0
 
jriver12Author Commented:
Figured it out,
<cfset linecount = Ceiling(Len(company) / 29)>

<cfif len(company) gt 29>

<cfloop from="1" to="#linecount#" index="n">

<cfif n eq 1>

<cfset pl = 250>

<cfelse>

<cfset pl = 250 + 70>

</cfif>
^FB750,1,0,C
^FO0,<cfoutput>#pl#</cfoutput>^A0,56,56^FD<cfoutput>#Mid(company, (n-1)*29 + 1, 29)# </cfoutput>^FS
</cfloop>
</cfif>

<cfif n gt 1>
<cfset csp = 320 + 70>
<cfelse>
<cfset csp = 320>
</cfif>
^FB750,1,0,C
^FO0,<cfoutput>#csp#</cfoutput>^A0,56,56^FD<cfoutput>#Trim(city)#, #trim(state)#</cfoutput>^FS
^FS
^XZ

now this is presenting me with another issue with the same process.

how can you have it wrap the next entire word.

for ex:

this is my test company it is very long
currently does thison the badge
this is my test company it is v
ery long

is there a way to detect the space and have it wrap.

this is my test company it is
very long
??????

My thought process originally was wrong and there fore producing an ugly badge.

0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
mrichmonCommented:
Yes there is a way to detect the space, but realize that it is possible (although unlikely) htat you could have over 49 characters without a space.

But your code becomes more complex.  You need to do something like the following :

Start with substring of position 1-49
See if position 49 is a space - if not look at position 48, etc  When you find a space (let's say position 44) then print from 1-44 and set start = 45
Repeat using substring 45-93

I think I have seen a tag out there that does this for you where you send it the string and the number of chars max per line , but I don't know where at the moment...

0
 
jriver12Author Commented:
no strings would have a continuous 49 characters the would all be names such as :

acme manufacturing corporation of north and south america

then if the for an example the 49 position would land after the m in america
the the badge would print something like :

acme manufacturing corporation of north and south am
             erica
(Ugly break)

now what I am trying to accomplish and figure out how is
how to make it back up to the Previous space befor the marked position(49)
then break the string their.

therefore looking like:
acme manufacturing corporation of north and south
                          america

Much Nicer

any suggs  I'm still searching for the tag you had mentioned.
0
 
PluckaCommented:
Here's an example on your data, just loop around the string while it's greater than 49 characters and pull apart the bits. If you need any of this explained let me know.

<cfset test="acme manufacturing corporation of north and south america the quick brown fox jumps over the lazy dog">

<cfloop condition="len(test) gt 49">
      <cfset current = left(test, 49)>
      <cfset pos = len(current) - find(" ", reverse(current))>
      <cfset current = left(test, pos)>
      <cfset test = mid(test, pos+1, 999)>
      <cfoutput>#current#<br></cfoutput>
</cfloop>

<cfset current = test>
<cfoutput>#current#<br></cfoutput>

Outputs

acme manufacturing corporation of north and
south america the quick brown fox jumps over
the lazy dog

And here it is with your Zebra codes.

<cfset test="acme manufacturing corporation of north and south america the quick brown fox jumps over the lazy dog">
<cfset pl = 250>

<cfloop condition="len(test) gt 49">
      <cfset current = left(test, 49)>
      <cfset pos = len(current) - find(" ", reverse(current))>
      <cfset current = left(test, pos)>
      <cfset test = mid(test, pos+1, 999)>
      <cfoutput>
            ^FB750,1,0,C
            ^FO0,#pl#^A0,56,56^FD<cfoutput>#current#</cfoutput>^FS
      </cfoutput>
      <cfset pl = pl + 70>
</cfloop>

<cfset current = test>
<cfoutput>
      ^FB750,1,0,C
      ^FO0,#pl#^A0,56,56^FD<cfoutput>#current#</cfoutput>^FS<br>
</cfoutput>

0
 
mrichmonCommented:
Sorry still haven't found the link to that tag, but you could just use Plucka's code instead... I'm still looking....
0
 
jriver12Author Commented:
mrichmon,
I'am going with Plucka's suggestion. however he has answered it in the cf section.
so being that you have also assisted in this area and your solution also worked with what I gave you you get some points to thanks a mil for the time and effort.

0
 
mrichmonCommented:
Thanks for giving me points since I did answer your original question.

If you are going with Plcka's solution I'll stop looking for the tag.
0
 
jriver12Author Commented:
please if you do find it please let me know it would be great to see how it works.

thank you again.
0
 
mrichmonCommented:
okay if I do I'll post a link to it here...
0
 
jriver12Author Commented:
Great..
thanks
0
 
mrichmonCommented:
In case it helps someone else locate it the tag was used for limiting the characters printed when generating text email messages when you had to be sure to keep the characters per line below 80 for some older email clients....
0
 
PluckaCommented:
The code above does that, change the two references at the top from 49 to whatever, it would be easy to write this as a tag. Would be more useful as a UDF, easy again, let me know if you want it and i'll do it.

This might be what you were thinking of mrichmon

http://www.cflib.org/udf.cfm?ID=424

Or here's the above as a custom tag.

<cfparam name="Attributes.Length" default="49">

<cfif ThisTag.ExecutionMode eq "Start">
     <cfloop condition="len(test) gt Attributes.Length">
          <cfset current = left(test, Attributes.Length)>
          <cfset pos = len(current) - find(" ", reverse(current))>
          <cfset current = left(test, pos)>
          <cfset test = mid(test, pos+1, 999)>
          <cfoutput>#current#<br></cfoutput>
     </cfloop>

     <cfset current = test>
     <cfoutput>#current#<br></cfoutput>
</cfif>
0
 
mrichmonCommented:
Yeah I know it would be easy to write, but the tag I am thinking of had some neat extras that I wouldn't want to bother with writing on my own that ended up with really detailed ways to control the output.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now