PDF print bitmap background color changes from white to black

kamalkishor

Member
Licensed User
Longtime User
Hi

I am making an app and i need to paste an image on another image and finally convert to PDF and got some prob like:

I have changed the color of canvas in signature to transparent. It comes correctly on the App, but when it is printed on PDF the background is black instead of white.

For this I used this

Canvassignaturemain.DrawColor(Colors.Transparent

and rest also paste below:

:sign0085:


Dim temprect2 As Rect
Dim temprect As Rect
Dim imageback As Int
Dim imageback2 As Int


temprect = pnlsign.GetScaleRect
signleftposition = temprect.Left
Log(signleftposition)
signtopposition = temprect.Bottom
Log(signtopposition)


Dim datetimePdf As String

' PDFWriter1.Initialize("PDFWriter1",100%x,100%y)
PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)


If s <> "" Then
bmchoosefile.Initialize(File.DirRootExternal,s)

PDFWriter1.addImage2(5%x,5%y,100%x,100%y,bmchoosefile)
End If

If bgsign <> "" Then

ksignp.Initialize(File.DirRootExternal,bgsign)

'PDFWriter1.addImage(signleftposition,signtopposition, ksignp )
PDFWriter1.addImage(signleftposition,signtopposition, ksignp )


End If

PDFWriter1.addText(30%x,95%y,20,emailtext1)
PDFWriter1.addText(30%x,85%y,20,emailtext2)
PDFWriter1.addText(30%x,75%y,20,emailtext3)
PDFWriter1.addText(30%x,65%y,20,emailtext4)
PDFWriter1.addText(30%x,55%y,20,emailtext5)
PDFWriter1.addText(30%x,45%y,20,emailtext6)
PDFWriter1.addText(30%x,35%y,20,emailtext7)


'PDFWriter1.addText(20,300,20,lbl2slide1.Text)

PDFWriter1.ConverseDocument

datetimePdf = ""
datetimePdf = DateTime.GetDayOfYear(DateTime.Now)
datetimePdf = datetimePdf & DateTime.GetHour(DateTime.Now)
datetimePdf = datetimePdf & DateTime.GetMinute(DateTime.Now)
datetimePdf = datetimePdf & DateTime.GetSecond(DateTime.Now)


PDFfilename = datetimePdf & ".pdf"

PDFWriter1.outputToFile(File.DirRootExternal,PDFfilename,PDFContent,"ISO-8859-1")



ToastMessageShow("saving Document complete.",False)

End Sub



thanks

Kamal
 

klaus

Expert
Licensed User
Longtime User
Try this:
B4X:
Canvassignaturemain.DrawColor(Colors.ARGB(0, 255, 255, 255))
Just a thought, if I remember well by default Transparent is Colors.ARGB(0, 0, 0, 0) the printer doesn't use the alpha part but and remaining color is black.
So Colors.ARGB(0, 255, 255, 255) transparent white.

Best regards.
 
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
Problem with printing signature.

thanks for reply but we want to print signature over on image with transparent background...
with this code DrawColor(Colors.ARGB(0, 255, 255, 255)) we get white background instead transparent background.
any help appreciated...





rgds....
kamal kishor
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You need to post the code how you draw the signature on the other picture otherwise it's impossible to help you and what you are doing with it afterwards.
Or better post a small project as a zip file that shows the problem.

Best regards.
 
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
Problem with printing signature on image..

thanks for reply
i have attached my code (signature app . txt) so we are using the signature module from basics4android and trying to create the pdf. we want to add that signature over the image in pdf .
due to this we face a problem while creating pdf, signature comes with black background. we want only transparent background of signature on pdf. any solution regarding this problem is appreciated.
 

Attachments

  • signature app.txt
    13.6 KB · Views: 496
Upvote 0

klaus

Expert
Licensed User
Longtime User
I cannot test your program because lots of things are missing.
Why haven't you posted your project as a zip file (IDE menu File / Export As Zip) as requested ?
I don't want to waste time trying to add everything that is missing.

Best regards.
 
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
hi
thanx fr reply and i attached project as zip file.

Ina my project I am trying to put image on image.
-> As first i chose or open an image and put that image as background.
-> After that I go for Sign button and do my signature, save my sign as png.
-> Put my sign.png on image
-> savePDF to create pdf fiile.
-> ViewPDF to open the pdf. I get sign image with black or white background, while i want signature to have transparent background.
thanks
 

Attachments

  • signature image example.zip
    52.1 KB · Views: 419
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your project, but couldn't test it completely because there is no background image.

But I have following comments:

1) PDFWriter doesn't not support the alpha value for colors that means no transparency.
You have two possibilities:
- set the background color of the signature the same as the background image color
- copy the signature onto the background image with a Canvas and then copy the whole into the PDF document.

2) The size of the panel for the signature takes almost the whole screen, I think you should reduce it to a smaller rectangle with a frame around so the user sees exactly where to put the signature.

3) When you fill the PDF document you use %x and %y values for the positioning of text and images, why?
%x and %y values are percentages of the screen size in pixels and not percentages of the PDF scheet size !
So depending on the device screen size the PDF document will be different.
You should use absolute values.
I made some tests to find out what the unit is.
1 unit = 0.343 mm

The original unit is supposed to be 1 unit = 1 point = 1/72 inch = 0.3528 mm
Calculating PDFPaperSize.Ae_Width / 210 = 0.353
But printing a file and measuring the distance between line gives 0.343 instead of 0.353 !

Best regards.
 
Last edited:
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
ok and thanks for erply

And I would like to go with second option as
- copy the signature onto the background image with a Canvas and then copy the whole into the PDF document

but problem is that i haven't experience with image processing so will you give me some hint, tutorials or material for same.

Thanks again
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try this code:
B4X:
If s <> "" Then
  bmchoosefile.Initialize(File.DirRootExternal,s)
  If bgsign <> "" Then 
    ksignp.Initialize(File.DirRootExternal,bgsign)
    Dim r As Rect
    Dim w, h As Int
    w = 200dip
    h = 50dip
    r.Initialize(signleftposition, signtopposition, signleftposition + w, signtopposition + h)
    cvsBmChooseFile.Initialize(bmchoosefile)
    cvsBmChooseFile.DrawBitmap(ksignp, Null, r)
  End If 
  PDFWriter1.addImage2(5%x, 5%y, 100%x, 100%y, bmchoosefile)
End If
cvsBmChooseFile must be Dimed in Globals Dim cvsBmChooseFile As Canvas.
You must adjust the two variables w and h according to the dimesions you want for the signature.

Best regards.
 
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
Thanks Klaus

Tried "- copy the signature onto the background image with a Canvas and then copy the whole into the PDF document.". But it doesnt work. Look like the PDFWriter library needs to be changed

rgds
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
But it doesnt work.
What doesn't work ?
There is no reason it must work.
Copying a bitmap onto another bitmap is no problem and adding a bitmap to a pdf document either so the problem must be in your code.

How did you do it ?

Post your latest version of your project as a zip file but with a background image and I'll have a look at it.

Best regards.
 
Upvote 0

kamalkishor

Member
Licensed User
Longtime User
Problem with printing signature on image..

Thanks klaus
Please find exported project.
With open button we can set background image available on sd card.

We have made the following changes to pdf file creation code
If s <> "" Then
bmchoosefile.Initialize(File.DirRootExternal,s)
If bgsign <> "" Then
ksignp.Initialize(File.DirRootExternal,bgsign)
Dim r As Rect
Dim w, h As Int
w = 200dip
h = 50dip
r.Initialize(signleftposition, signtopposition, signleftposition + w, signtopposition + h)
bmchoosefile.InitializeMutable(Activity.Width, Activity.Height)
cvsBmChooseFile.Initialize2(bmchoosefile)

cvsBmChooseFile.DrawBitmap(ksignp, Null, r)
End If
PDFWriter1.addImage2(5%x, 5%y, 100%x, 100%y, bmchoosefile)
End If
 

Attachments

  • signature app.zip
    52.3 KB · Views: 407
Upvote 0

klaus

Expert
Licensed User
Longtime User
I looked at your program.
Unfortunately your Report image is too big for the PDFWriter it raises an Out of Memory error.
But you can see that the signature is copied with transparency onto the Report image.

I'm afraid that you need to look for another solution to generate the PDF document without the big image.
Copying the signature to the PDF document works but not with transparency.

Best regards.
 
Upvote 0
Top