Android Question PDF Writer: addImage

ST500

Active Member
Licensed User
With addImage you set the distance from left and from the bottom of the page.
How can I set the distance from the bottom dynamically. Each time, if I generate new PDF-file, the included picturces should have the same distance from the top of the page, allways.

Could you help me please?
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
PDF.addImage(left,PageSize.A4_HEIGHT-Top,Image)

Change PageSize.A4_HEIGHT with a size that you select
 
Upvote 0

ST500

Active Member
Licensed User
Hi Star Dust,

thanks a lot. There is a problem.
I save a SQLITE query with different number of lines from WebViev as JPG. After then I imoprt it in an ImageView in an activity and add it in my PDF document.
Each time the JPG has another size. Therfore I can not fix the distance from top of the page.

Dim bm As Bitmap
Dim Hi As Int
bm.Initialize(File.DirDefaultExternal & "/SQLite/Fuhrbericht", baustelleneu.result & ".jpg")
Hi = bm.Height
ImageView2.Bitmap = LoadBitmapSample(File.DirDefaultExternal & "/SQLite/Fuhrbericht", baustelleneu.result & ".jpg", 280, Hi)
PDFWriter1.addImage(50,PaperSize.A4_HEIGHT - ???????????????, ImageView2.Bitmap)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Hi, try it

B4X:
    Dim ImageView2 As ImageView
    Dim PDFWriter1 As PDFWriter
    Dim PaperSize As PDFPaperSizes
    Dim bm As Bitmap
    Dim Hi As Int 
 
    bm.Initialize(File.DirDefaultExternal & "/SQLite/Fuhrbericht", baustelleneu.result & ".jpg")
    Hi = bm.Height
 
    ImageView2.SetBackgroundImage(bm)
    PDFWriter1.addImage(50,PaperSize.A4_HEIGHT-Hi, bm)
End Sub

More difficult. If Image is out of page?
B4X:
    Dim ImageView2 As ImageView
    Dim PDFWriter1 As PDFWriter
    Dim PaperSize As PDFPaperSizes
    Dim bm As Bitmap
    Dim Hi As Int 
 
    bm.Initialize(File.DirDefaultExternal & "/SQLite/Fuhrbericht", "baustelleneu.result" & ".jpg")
    Hi = bm.Height
 
    If Hi>PaperSize.A4_HEIGHT Then
        ' out of page
        ' Resize image as fit to page
        Dim R As Float
        R=PaperSize.A4_HEIGHT/bm.Height
        bm=CreateScaledBitmap(bm,bm.Width*R,bm.Height*R)
        End If
     
    ImageView2.SetBackgroundImage(bm)
    PDFWriter1.addImage(50,PaperSize.A4_HEIGHT-Hi, bm)
End Sub

Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
    Dim r As Reflector
    Dim b As Bitmap
    Dim filter As Boolean: filter=True
 
    b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
        Array As Object(Original, Width, Height, filter), _
        Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
    Return b

End Sub
 
Upvote 0
Top