Android Question Problems with signature insertion in PDF

Wolli013

Well-Known Member
Licensed User
Longtime User
Hello friends I use this library to create PDF.


When I want to insert a signature, it does not fit on different devices.

The signature is read in as a PNG.
That's how I'm using it at the moment, where it fits reasonably well on different devices.
I'm probably not doing it right.

How do you solve this problem?

Translated with DeepL.com (free version)

B4X:
If File.Exists(xui.DefaultFolder, "unterschrift1.png") = True Then' Bild einfügen

    Dim Bitmap1 As Bitmap

    Bitmap1.Initialize(xui.DefaultFolder, "unterschrift1.png")

    Dim r As Rect



If (Bitmap1.Width/GetDeviceLayoutValues.Scale) >500 Then

    r.Initialize(310, 751, Bitmap1.Width/2/GetDeviceLayoutValues.Scale+140, Bitmap1.Height/2/GetDeviceLayoutValues.Scale+699) 'von links,von oben,bis rechts,bis unten

Else

    r.Initialize(310, 751, Bitmap1.Width/GetDeviceLayoutValues.Scale+140, Bitmap1.Height/GetDeviceLayoutValues.Scale+699) 'von links,von oben,bis rechts,bis unten

End If

    Log("Unterschrift-Breite "&(Bitmap1.Width/GetDeviceLayoutValues.Scale))

    pdf1.Canvas.DrawBitmap(Bitmap1, Null,r)

 End If
 

Wolli013

Well-Known Member
Licensed User
Longtime User
This is how I save the signature beforehand.

B4X:
Sub btnSignature_Click1
 
    Base = Activity
    Dialog.Initialize (Base)
    Dialog.TitleBarTextColor = xui.Color_White
    Dialog.TitleBarColor = 0xFF1A548A
    Dialog.TitleBarHeight = 60dip
    Dialog.Title = "Unterschrift Ausführender"
    SignatureTemplate.Initialize
 
    Dialog.ButtonsFont = xui.CreateFontAwesome(20)
    Dim rs As ResumableSub = Dialog.ShowTemplate(SignatureTemplate, Chr(0xF00C), "", Chr(0xF00D))
    Dialog.GetButton(xui.DialogResponse_Positive).TextColor = xui.Color_Green
    Dialog.GetButton(xui.DialogResponse_Cancel).TextColor = xui.Color_Red
    Dialog.ButtonsFont = xui.CreateDefaultBoldFont(15) 'return it to the default font. It will no longer affect the current dialog

    Wait For (rs) Complete (Result As Int)
        If Result = xui.DialogResponse_Positive Then
            If SignatureTemplate.NumberOfPoints = 0 Then
              Log("Keine Unterschrift!")
            End If           
            ImageViewUnterschrift1.SetBitmap(SignatureTemplate.Bitmap.Resize(ImageViewUnterschrift1.Width, ImageViewUnterschrift1.Height, True))
            Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "unterschrift1.png", False)
            SignatureTemplate.Bitmap.WriteToStream(out, 100, "PNG")
            out.Close
        End If
    
End Sub
 
Upvote 0
Top