Android Question [Solved] Print text, rectangle and image in PDFDocumet don't works.

asales

Expert
Licensed User
Longtime User
I try to create a PDF document using this library, based in the example of the post.

It is a profile form, with a title in a rectangle and an image,
The title with the rectangle is printing, but the image don't.
1675734058532.png


What could be happen? How can I fix this?

The code is below and the example is in attached.

Thanks in advance for any tip.
B4X:
Dim A4Width As Int = 595
Dim A4Height As Int = 842
    
Dim pdf As PdfDocument
pdf.Initialize
    
pdf.StartPage(A4Width, A4Height) 'A4 size
    
Dim Rect1 As Rect
Rect1.Initialize(50, 60, 545, 90)
pdf.Canvas.DrawRect(Rect1, Colors.Black, False, 0.8)
pdf.Canvas.DrawText("NAME OF THE USER", 300, 80, Typeface.DEFAULT_BOLD, 14 / GetDeviceLayoutValues.Scale , Colors.Black, "CENTER")
    
Dim Bitmap1 As Bitmap
Bitmap1 = LoadBitmap(File.DirAssets, "smiley.png")
Dim DestRect As Rect
DestRect.Initialize(100, 150, 80, 250)
pdf.Canvas.DrawBitmap(Bitmap1, Null, DestRect) 'draws the bitmap to the destination rectangle.
    
pdf.FinishPage
 

Attachments

  • printing.zip
    17.8 KB · Views: 66
Solution
I try to create a PDF document using this library, based in the example of the post.

It is a profile form, with a title in a rectangle and an image,
The title with the rectangle is printing, but the image don't.
View attachment 138998

What could be happen? How can I fix this?
You need to set the width and height of the rect.
B4X:
Dim DestRect As Rect
DestRect.Initialize(100, 150, 80, 250)
'------------------------------------------------------
DestRect.width = Bitmap1.width/Bitmap1.scale
DestRect.height = Bitmap1.height/Bitmap1.scale
'------------------------------------------------------
pdf.Canvas.DrawBitmap(Bitmap1, Null, DestRect) 'draws the bitmap to the destination rectangle.
pdf.FinishPage

teddybear

Well-Known Member
Licensed User
I try to create a PDF document using this library, based in the example of the post.

It is a profile form, with a title in a rectangle and an image,
The title with the rectangle is printing, but the image don't.
View attachment 138998

What could be happen? How can I fix this?
You need to set the width and height of the rect.
B4X:
Dim DestRect As Rect
DestRect.Initialize(100, 150, 80, 250)
'------------------------------------------------------
DestRect.width = Bitmap1.width/Bitmap1.scale
DestRect.height = Bitmap1.height/Bitmap1.scale
'------------------------------------------------------
pdf.Canvas.DrawBitmap(Bitmap1, Null, DestRect) 'draws the bitmap to the destination rectangle.
pdf.FinishPage
 
Upvote 1
Solution
Top