Android Question convert webview layout to PDF

Makumbi

Well-Known Member
Licensed User


Please help i would want the user to print this in PDF format how can i got a bot it using the PDF library
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private WebView1 As WebView
    Private HtmlCSS As String
    HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
        & " th { font-weight: bold;    background-color: #acf;    border-bottom: 1px solid #cef; }" _
        & "td,th {    padding: 4px 5px; }" _
        & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
        & "a { text-decoration:none; color: #000;}"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("displayalevel")
    Activity.Title="Provisional Results"
    ShowTableAlevel
End Sub


Sub ShowTableAlevel
    'Dim SQLQry As String = "DELETE FROM Balances"
    'Starter.SQL1.ExecNonQuery(SQLQry)
    Private Query As String
    Query = "SELECT DISTINCT Name,Subject,Points FROM Alevelreport"
    'depending if the filter is active or not we add the filter query at the end of the query
    'the filter query is defined in the Filter Activity
    If Starter.flagFilterActive = False Then
        'btnFilter.Initialize("Filter")
        'se
        'Query = Query & Starter.FilterQuery
        'btnFilter.Text = "UnFilter"    'change the text in the Filter button
    End If
    'displays the database in a table

    WebView1.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
    'ReadDataBaseIDs
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
    'parse the row and column numbers from the URL
    Private values() As String
    values = Regex.Split("[.]", Url.SubString(7))
    Private row As Int
    row = values(1)
    Starter.CurrentIndex = row
    'UpdateSelectedItem
    'Dim values() As String
    'values = Regex.Split("[.]", Url.SubString(7))
    
    'ToastMessageShow("User pressed on column: " & col & " and row: " & row, False)
    'Return True 'Don't try to navigate to this URL
    Return True 'Don't try to navigate to this URL
End Sub


Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean) As String
    Private cur As Cursor
    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    Log("ExecuteHtml: " & Query)
    If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
    Private sb As StringBuilder
    sb.Initialize
    sb.Append("<html><body>").Append(CRLF)
    sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
    sb.Append("<table><tr>").Append(CRLF)
    For i = 0 To cur.ColumnCount - 1
        sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
    Next
    
    sb.Append("</tr>").Append(CRLF)
    For row = 0 To Limit - 1
        cur.Position = row
        If row Mod 2 = 0 Then
            sb.Append("<tr>")
        Else
            sb.Append("<tr class='odd'>")
        End If
        For i = 0 To cur.ColumnCount - 1
            sb.Append("<td>")
            If Clickable Then
                sb.Append("<a href='http://").Append(i).Append(".")
                sb.Append(row)
'                sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
                sb.Append(".stub'>").Append(cur.GetString2(i)).Append("</a>")
        
            Else
                sb.Append(cur.GetString2(i))
            End If
            sb.Append("</td>")
        Next
        sb.Append("</tr>").Append(CRLF)
        
    Next
    cur.Close
    sb.Append("</table></body></html>")
    Return sb.ToString
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    StartActivity(academicextract)
End Sub


Sub Button1_Click
    'Activity.RemoveAllViews
        StartActivity(academicextract)
End Sub
 

Attachments

  • Screenshot_1553577768.png
    49.3 KB · Views: 349

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…