public Sub PanelToPdf(Panel As B4XView, FileName As String)
Try
Dim pdf As PdfDocument
pdf.Initialize
pdf.StartPage(Panel.Width, Panel.Height)
' 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, True)
pdf.WriteToStream(out)
out.Close
pdf.Close
Catch
Log(LastException)
End Try
End Sub