B4J Question Textengine

Status
Not open for further replies.

jesuslizonsoluciones

Member
Licensed User
Longtime User
good morning

How could I write the content of textengine in pdf

Sorry but I don't have much experience with this library and I didn't find anything in the forum

thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You have two options:
1. Assuming that the text is not too long, disable the lazy drawing feature and get the complete bitmap from BBCodeView.ForegroundImageView.
2. If it is too long then you will need to understand how the lazy drawing works and do something similar to draw the text line by line.
 
Upvote 0

jesuslizonsoluciones

Member
Licensed User
Longtime User
Hello


This is the code that I have used to create a multi-page enriched pdf, with the BBCodeView1 and PDFjetPDF libraries


btnUpdate_Click
Try

BBCodeView1.LazyLoading=False

Dim Lineas_texto As String =File.ReadString(File.DirAssets,"declaración responsable del cliente en check_in (vf)_esp_txt.txt") & CRLF & CRLF & CRLF

TextArea1.Text=""
TextArea1.Text=Lineas_texto
AddViews(TextArea1.Text)
BBCodeView1.Text = TextArea1.Text
Dim imagen As B4XBitmap = BBCodeView1.ForegroundImageView.GetBitmap
Dim Out As OutputStream
Out = File.OpenOutput(File.DirApp, "pagina1.png", False)
imagen.WriteToStream(Out, 100, "PNG")
Out.Close


BBCodeView1.Views.Clear


BBCodeView1.LazyLoading=False

Dim Lineas_texto As String =File.ReadString(File.DirAssets,"bienvenido_restohoteles_esp_txt.txt") & CRLF & CRLF & CRLF

TextArea1.Text=""
TextArea1.Text=Lineas_texto
AddViews(TextArea1.Text)
BBCodeView1.Text = TextArea1.Text
Dim imagen1 As B4XBitmap = BBCodeView1.ForegroundImageView.GetBitmap
Dim Out As OutputStream
Out = File.OpenOutput(File.DirApp, "pagina2.png", False)
imagen1.WriteToStream(Out, 100, "PNG")
Out.Close


BBCodeView1.Views.Clear


BBCodeView1.LazyLoading=False

Dim Lineas_texto As String =File.ReadString(File.DirAssets,"policia_esp_txt.txt") & CRLF & CRLF & CRLF

TextArea1.Text=""
TextArea1.Text=Lineas_texto
AddViews(TextArea1.Text)
BBCodeView1.Text = TextArea1.Text
Dim imagen As B4XBitmap = BBCodeView1.ForegroundImageView.GetBitmap
Dim Out As OutputStream
Out = File.OpenOutput(File.DirApp, "Pagina3.png", False)
imagen.WriteToStream(Out, 100, "PNG")
Out.Close

' *************************** crear pdf


Dim PDFjetPDF1 As PDFjetPDF=CreateBasePDFDocument

Dim PDFPage As PDFjetPage
PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

Dim PDFFont1 As PDFjetFont
PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA)


Dim Image1 As PDFjetImage
Image1.Initialize(PDFjetPDF1, File.OpenInput(File.DirApp, "pagina1.png"), PDFjetConstants1.ImageType.PNG)
Image1.ScaleBy(0.6)

Dim Image2 As PDFjetImage
Image2.Initialize(PDFjetPDF1, File.OpenInput(File.DirApp, "pagina2.png"), PDFjetConstants1.ImageType.png)
Image2.ScaleBy(0.6)


Dim Image3 As PDFjetImage
Image3.Initialize(PDFjetPDF1, File.OpenInput(File.DirApp, "pagina3.png"), PDFjetConstants1.ImageType.png)
Image3.ScaleBy(0.6)

Image1.SetPosition(20, 20)
Image1.DrawOn(PDFPage)

Dim PDFPage2 As PDFjetPage
PDFPage2.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

Image2.SetPosition(20, 20)
Image2.DrawOn(PDFPage2)

Dim PDFPage3 As PDFjetPage
PDFPage3.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.A4_PORTRAIT)

Image3.SetPosition(20, 20)
Image3.DrawOn(PDFPage3)

PDFjetPDF1.Close

Catch
TextEngine.TagParser.ErrorString.Append(CRLF).Append(LastException.Message)
Log(LastException)
End Try
If TextEngine.TagParser.ErrorString.Length > 0 Then
xui.MsgboxAsync(TextEngine.TagParser.ErrorString, "Error")
End If
end sub

Sub CreateBasePDFDocument As PDFjetPDF
Dim PDFDestination As OutputStream
PDFDestination=File.OpenOutput(File.DirApp, "paginas.pdf", False)

PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
PDFjetPDF1.SetAuthor("Martin Pearman")
PDFjetPDF1.SetSubject("jPDFjet Examples")
'PDFjetPDF1.SetTitle(ExampleChooser.Value)

Return PDFjetPDF1
End Sub

Sub PDFjetPDF1_CloseComplete(Success As Boolean)
If Success Then
'JFX1.ShowExternalDocument(File.GetUri(LastSelectedDir, ExampleChooser.Value&".pdf"))
Else
Log("An error has occurred and creation of the PDF document has failed")
End If
End Sub
 
Upvote 0

jesuslizonsoluciones

Member
Licensed User
Longtime User
Hello


I forgot to pass you the final result


greetings and thanks Erel



1601487139386.png
 
Upvote 0

jesuslizonsoluciones

Member
Licensed User
Longtime User
Hi Erel

I have a problem with the BBCodeView1.ForegroundImageView.GetBitmap command

when I insert an image [img FileName = "firma2.png" /]

and then I run BBCodeView1.ForegroundImageView.GetBitmap

the signature does not appear in the document converted to an image

these are the steps i follow:







Dim imagen As B4XBitmap


imagen= BBCodeView1.ForegroundImageView.GetBitmap
Dim Out As OutputStream
Out = File.OpenOutput(File.DirApp, "pagina1.png", False)
imagen.WriteToStream(Out, 100, "PNG")
Out.Close

What can be the motive?

The rest works correctly

Greetings
 
Upvote 0

Dieter Baumgartner

Member
Licensed User
Longtime User
You have two options:
1. Assuming that the text is not too long, disable the lazy drawing feature and get the complete bitmap from BBCodeView.ForegroundImageView.
2. If it is too long then you will need to understand how the lazy drawing works and do something similar to draw the text line by line.

Could anyone give a idea, how Erel's answer (2 nd. point) could work ?
if you generated a nice listview with bbcodeview inside and it is dynamic how long the list is, how could i get this into a PDF ?

test.png
 
Upvote 0
Status
Not open for further replies.
Top