[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Miseries in life and Zebra Printing

Posted on 2004-04-20
15
Medium Priority
?
345 Views
Last Modified: 2010-04-07
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
Comment
Question by:jriver12
  • 7
  • 6
  • 2
15 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 10873549
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
 

Author Comment

by:jriver12
ID: 10877651
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
 

Author Comment

by:jriver12
ID: 10878185
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 35

Accepted Solution

by:
mrichmon earned 2000 total points
ID: 10879570
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
 

Author Comment

by:jriver12
ID: 10881778
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
 
LVL 18

Expert Comment

by:Plucka
ID: 10884141
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10884193
Sorry still haven't found the link to that tag, but you could just use Plucka's code instead... I'm still looking....
0
 

Author Comment

by:jriver12
ID: 10892607
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10893206
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
 

Author Comment

by:jriver12
ID: 10893258
please if you do find it please let me know it would be great to see how it works.

thank you again.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10893387
okay if I do I'll post a link to it here...
0
 

Author Comment

by:jriver12
ID: 10893462
Great..
thanks
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10893644
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
 
LVL 18

Expert Comment

by:Plucka
ID: 10894860
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 10894922
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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question