Android Question how to display pdf format

Discussion in 'Android Questions' started by Makumbi, Apr 10, 2019.

  1. Makumbi

    Makumbi Active Member Licensed User

    Please help below is some code i was trying out to show PDF document in my Layout

    Code:
    #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.
        Private rp As RuntimePermissions
        
    Private xui As XUI

    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.

    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("Layout1")
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        
    If Result Then
            
    Dim pdf As PdfDocument
            pdf.Initialize
            pdf.StartPage(
    595842'A4 size
            Dim bmp As B4XBitmap = TextToBitmap(200dip, xui.CreateDefaultBoldFont(20), xui.Color_Black, _
            
    $"s dflkj sdfkls
    dffwje klfj wlkef jwlke fjlwkef jklwe jflkwe jflkwe jflkwe jflkwe jfl
    sdf
    we
     gfkwe lg;kw e;lg wklelg; weg wel;g"$
    )
            
    Dim rect As Rect
            
    rect.Initialize(303000)
            
    rect.Width = bmp.Width / bmp.Scale
            
    rect.Height = bmp.Height / bmp.Scale
            pdf.Canvas.DrawBitmap(bmp, 
    Nullrect)
            pdf.FinishPage
            
    Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "sula.pdf"False)
            pdf.WriteToStream(out)
            out.Close
            pdf.Close
        
    End If
    End Sub

    Sub Activity_Resume

    End Sub
    Sub TextToBitmap (Width As Int, Fnt As B4XFont, Clr As Int, Text As StringAs B4XBitmap
        
    Dim lbl As Label
        lbl.Initialize(
    "")
        
    Dim x As B4XView = lbl
        x.Font = Fnt
        x.TextColor = Clr
        x.SetLayoutAnimated(
    000, Width, 0)
        
    Dim su As StringUtils
        x.Height = su.MeasureMultilineTextHeight(x, Text)
        x.Text = Text
        
    Return x.Snapshot
    End Sub
    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
     
  2. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice