Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private provider As FileProvider
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
provider.Initialize
End Sub
Private Sub PanelToPdf(Panel As B4XView, FileName As String)
Dim pdf As PdfDocument
pdf.Initialize
pdf.StartPage(595, 842) 'A4 size
Dim bmp As B4XBitmap = Panel.Snapshot
Dim dest As Rect
dest.Initialize(10, 10, 0, 0)
dest.Width = bmp.Width / bmp.Scale
dest.Height = bmp.Height / bmp.Scale
pdf.Canvas.DrawBitmap(bmp, Null, dest)
pdf.FinishPage
Dim out As OutputStream = File.OpenOutput(provider.SharedFolder, FileName, False)
pdf.WriteToStream(out)
out.Close
pdf.Close
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
provider.SetFileUriAsIntentData(in, FileName)
in.SetType("application/pdf")
Try
StartActivity(in)
Catch
Log("PDF viewer is not installed.")
Log(LastException)
End Try
End Sub
Private Sub Button1_Click
PanelToPdf(Root, "1.pdf")
End Sub