iOS Question canvas.drawview

Lyndon

Member
Licensed User
Hi I am trying to create a pdf with several layout items and later draw text from an sqlite.
I am struggling to understand how to draw a multi line label to the canvas?

Can I create the label with text in the designer, position the label,set visible to false, and then drawview that label to the canvas, using the left,top,height,bottom values for Rect, from the label properties in the designer ?

The code below fails to draw the LblAddress label..

B4X:
Dim rect As Rect
    logo = LoadBitmap(File.DirAssets, "47A.png")
    pcvs.InitializePDF(File.DirDocuments, "3.pdf", 612, 792)
    rect.Initialize(200,0,500,100)
    pcvs.DrawBitmap(logo, rect)
    rect.Initialize(300,110,500,300)
    pcvs.DrawView(LblAddress,rect)
    pcvs.Release

Thank you
 

Lyndon

Member
Licensed User
Hi Erel and thanks for your reply, However I am still struggling, in the following code you will see I am trying as you suggested. I am trying to draw to a pdf file.
B4X:
public Sub show
    page1.Initialize("Page1")
    page1.Title = "Create"
    page1.RootPanel.Color = Colors.White
    page1.RootPanel.LoadLayout("CreateQoute")
    Main.NavControl.ShowPage(page1)
    Main.NavControl.ToolBarVisible = True
                                
    DateTime.DateFormat = "dd/MM/yy"
    Dim rect As Rect
    logo = LoadBitmap(File.DirAssets, "47A.png")
    pcvs.InitializePDF(File.DirDocuments, "3.pdf", 612, 792)
    rect.Initialize(ImageView1.Left,ImageView1.Top,ImageView1.Width,ImageView1.Height)
    'rect.Initialize(0,0,Panel1.Width,Panel1.Height)
    pcvs.DrawBitmap(logo, rect )
    rect.Initialize(LblAddress.Left,LblAddress.Top,LblAddress.Width,LblAddress.Height)
    'pcvs.DrawView(Panel1,rect)
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text = " hello world"
    pcvs.DrawView(lbl, rect)
    Panel1.AddView(lbl,LblAddress.Left,LblAddress.Top,LblAddress.Width,LblAddress.Height)
    pcvs.Refresh
    pcvs.Release
End Sub

After the drawview I have addview to draw the local label to the panel, this works fine, but the lable is not being written to the pdf.

Any help appreciated.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Example:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Dim cvs As Canvas
   cvs.InitializePDF(File.DirDocuments, "1.pdf", 612, 792)
   cvs.DrawColor(Colors.Red)
   Dim lbl As Label
   lbl.Initialize("")
   lbl.SetLayoutAnimated(0, 1, 0, 0, 100, 300)
   lbl.Multiline = True
   lbl.TextColor = Colors.Blue
   lbl.Text = $"j dsfkl jsdlkf sdf
sjdlfk sdk lfjsdlfkjsdf
sdfjlksd fjlskdfj lskd f
sdfj lsdfj lskdf jlsdf "$
   Dim r As Rect
   r.Initialize(10, 10, 110, 310)
   cvs.DrawView(lbl, r)
   cvs.Release
   WebView1.LoadUrl("file://" & File.Combine(File.DirDocuments, "1.pdf"))
End Sub
The layout file includes a single WebView named WebView1.
 
Upvote 0
Top