PNG transparency in PDF button

Hello,
I need to place png image into the button field in pdf and I have problem with png that have trancparency. The image appears with black background on the button field. Here is my code:

Aspose.Pdf.Forms.ButtonField logo = field as Aspose.Pdf.Forms.ButtonField;
System.Drawing.Bitmap img = new System.Drawing.Bitmap(dataDir + “logos\” + TextBox1.Text);
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
img.Save(memStream, img.RawFormat);
System.Drawing.Image image = System.Drawing.Image.FromStream(memStream);
logo.AddImage(image);
}

                    img.Dispose();

Could you please advice me ? We are considering to buy the product but this is what stops us at the moment…
Thank you.

@magentrix

Thank you for contacting support.

I would like to request you to please share the source PDF file, PNG image and complete code snippet to reproduce this issue. Please also share a screenshot explaining the problem so that we may investigate further to help you out.

Thanks for the reply Farhan. Please find input.pdf, image file and output.pdf. As you can see in the output.pdf the inserted image into the button field has black background. Here is the code snippet:

protected void Button1_Click(object sender, EventArgs e)
{
// The path to the documents directory.
string dataDir = “c:\testpdf\”;

        // Load the source PDF document
        Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");

        // Instantiate Form object
        Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(doc);


        foreach (Aspose.Pdf.Forms.Field field in doc.Form.Fields)
        {
            if (field.FullName.Contains("cobrandedText"))
            {
                Aspose.Pdf.Forms.TextBoxField textBoxField = field as Aspose.Pdf.Forms.TextBoxField;
                textBoxField.Value = "Impartner PRM\n" + "123 King str, Toronto, ON L4J9J3 ";

            }
           
            if (field.FullName.Contains("img"))
            {
                Aspose.Pdf.Forms.ButtonField logo = field as Aspose.Pdf.Forms.ButtonField;
                System.Drawing.Bitmap img = new System.Drawing.Bitmap(dataDir + "logos\\" + TextBox1.Text);
                using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                {
                    img.Save(memStream, img.RawFormat);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(memStream);
                    logo.AddImage(image);
                }

                img.Dispose();
            }
        }
        dataDir = dataDir + "output.pdf";
        // Save updated document
        doc.Save(dataDir);

    }

input.pdf (2.4 MB)
output.pdf (2.3 MB)

Nintex-icon_N-60px.png (2.6 KB)

@magentrix

Thank you for sharing requested data.

I have worked with the data shared by you and have been able to reproduce the issue in our environment. I have logged a ticket with ID PDFNET-43911 in our issue management system, as a feature request to support specifying a ButtonField’s fill color. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.

Farhan, the solution of specifying a ButtonField’s fill color would not work for us as in our requirement we don’t know what this parameter would be. We don’t have control over the background of this button is placed on. In our system people can upload any pdf file and any image to be use as background of the button. Ideal solution would be is if aspose component will handle the transparency of the png image.

@magentrix

I would like to share with you that Aspose.Pdf API mimics the behavior of Adobe Acrobat. I have investigated the scenario with the same and have found that after setting the image “Nintex-icon_N-60px.png” as an icon picture, when we set the button fill as ‘no color’ then your requirements are fulfilled (see attached expected.png). So, ideally, once the feature for setting ButtonField’s fill is supported, you will be able to handle transparency by specifying below lines of code, for instance.

Aspose.Pdf.Forms.ButtonField logo = field as Aspose.Pdf.Forms.ButtonField;
logo.Color = Color.Transparent;

I hope this will clarify the concept. Please let us know if you need any further clarification or assistance.

Thanks, this solution will work for us. Do you have any estimation when this feature will be supported ?

@magentrix,

The feature request (under the ticket ID PDFNET-43911) has just been logged in our issue tracking system. Our product team will investigate as per their development schedules. We will let you know once a significant progress has been made in this regard.

@Farhan.Raza
Hi Farhan,
I am having the same problem now. Have you fixed this issue yet?

@thaiphap95

Regretfully, the ticket could not get resolved yet. We will surely provide an update in this forum thread once the issue is resolved. We are sorry for the inconvenience.