Text (list) to image - help...

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hello,

i have a list loaded with text lines, say 10 to 15 lines, each line has max 40 chars.

can anyone help on how to print it to an image so i will have as a result an image to show the text, so i can print it or send it but no changes can be done for example a voucher or ticket etc


thanks
 

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi
managed to create the canvas and save it as png file using a sample i found in forum.

2 questions:

can i write beyond the actual screen height and still when i save it to have the whole text in the image ?

how do i send it to BT printer?
i now know how to send text but not image

thank you
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
if i send a text that has CrLf in it will it skip to next line or just be ignored ?
i have a full structured text that contains CrLf in it
i just want to create it as an image
if i send it as is to drawtext it does not reflect the CrLf so it goes as one long line out of screen boundaries
how can i send it as is ? and yet keep it's structure and spaces ?
thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
i have a list loaded with text lines, say 10 to 15 lines ...
In post #1 you speak about a list do you mean the content of a List object or a text file or a text in a string variable.

Could you post a text example.
And I'll have a look at it.

Best regards.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Perhaps the code below might inspire you.
B4X:
Sub Globals
    Dim pnlText As Panel
    Dim cvsText As Canvas
    Dim bmpText As Bitmap
    Dim txt As String
    Dim LineHeight As Float
    Dim LineSpace = 2dip As Float
    Dim TopMargin = 5dip As Float
    Dim BottomMargin = 5dip As Float
    Dim TextSize As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlText.Initialize("")
    Activity.AddView(pnlText, 0, 0, 500dip, 1000dip)    
End Sub

Sub Activity_Resume
    Dim i As Int

    txt = "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
    txt = txt & "This is a test text" & CRLF
        
    TextSize = 18
    cvsText.Initialize(Activity)
    LineHeight = cvsText.MeasureStringHeight("Ag", Typeface.DEFAULT, TextSize) + LineSpace
    Dim Lines() As String
    Lines = Regex.Split(CRLF, txt)
    Log(Lines.Length)
    pnlText.Height = Lines.Length * LineHeight + TopMargin + BottomMargin

    cvsText.Initialize(pnlText)
    cvsText.DrawColor(Colors.White)
    Dim y As Float
    y = TopMargin
    For i = 0 To Lines.Length - 1
        y = y + LineHeight
        cvsText.DrawText(Lines(i), 0, y, Typeface.DEFAULT, TextSize, Colors.Black, "LEFT")
    Next
    pnlText.Invalidate
End Sub
It contains only the printing onto the bitmap.

Best regards.
 

Attachments

  • TextImage.zip
    6 KB · Views: 250
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Hi and thanks again.
i did manage to do something close but not as nice as this

it seems that the mail problem will be either print the image - will be perfect if i just could send it to the printer but i don't know how

i did find an alternative way but now i have a new, harder problem:
it seems that what i send to the printer is not in the right codepage, i need to use 1255 codepage

i have a list with text elements (in hebrew) and if i send it as is it get the wrong font, i must convert each line to codepage 1255 - can it be done ?

help please...
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

all is solved on this matter, there is a big problem with b4a as it messes up completely the hebrew. all is reversed and actually looks like old DOS days
even when writing in code text
for this there is no solution - i can now print freely to the printer and read the card's mag stripe all like charm but when printing the text it is all messed up
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…