Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Oct 28, 2025 3:43 pm

Hi,

I'm trying to put an image in a PdfButtonField. I'm following the example given in the .NET Tutorials (Assign an Icon to a PDF Button Field and Set Icon Layout in C#), but these 2 lines of code
Code: Select all
btn.IconLayout.ScaleMode = PdfButtonIconScaleMode.Proportional;
btn.IconLayout.ScaleReason = PdfButtonIconScaleReason.Always;
seem not to work. The image is not scaled proportionally to the rectangle's size. I tried to use different ScaleMode and ScaleReason properties, but the result is the same.

This is my code:
Code: Select all
var ms = new MemoryStream();
var doc = new PdfDocument();
var page = doc.Pages.Add();

var btn = new PdfButtonField(page, "button1");
btn.Bounds = new RectangleF(0, 0, 270, 70);
btn.LayoutMode = PdfButtonLayoutMode.IconOnly;
btn.Icon = PdfImage.FromFile("C:\\Users\\marco\\Downloads\\logo.png");
btn.BorderWidth = 1;
btn.BackColor = PdfRGBColor.Empty;
btn.IconLayout.Spaces = new float[] { 0, 0 };
btn.IconLayout.ScaleMode = PdfButtonIconScaleMode.Proportional;
btn.IconLayout.ScaleReason = PdfButtonIconScaleReason.IconIsSmaller;
btn.IconLayout.IsFitBounds = true;

doc.Form.Fields.Add(btn);
doc.SaveToStream(ms);
doc.Close();

The result of the code above is in the attachment.

I'm using the latest version of Spire.Pdf (11.10.04) in a .NET Core 9 Web API

sofos86
 
Posts: 1
Joined: Wed Dec 12, 2018 11:00 am

Wed Oct 29, 2025 3:34 am

Hello,

Thank you for your inquiry.
I reproduced your issue and logged it into our bug tracking system with the ticket SPIREPDF-7808. Our dev team will investigate and fix it, once it is resolved or there is any update, I will notify you immediately. Apologize for the inconvenience caused.
Sincerely,
Talia
E-iceblue support team
User avatar

talia.liu
 
Posts: 331
Joined: Mon Apr 14, 2025 3:33 am

Mon Nov 24, 2025 9:46 am

Hello,

Thank you for your patience.
Regarding SPIREPDF-7808, our latest version Spire.Pdf for.NET 11.11.5 includes its fixes. Please update and test it with the latest version on your end. We look forward to your test results.
Website link: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
NuGet link: https://www.nuget.org/packages/Spire.PDFfor.NETStandard/11.11.5
https://www.nuget.org/packages/Spire.PDF/11.11.5
Sincerely,
Talia
E-iceblue support team
User avatar

talia.liu
 
Posts: 331
Joined: Mon Apr 14, 2025 3:33 am

Return to Spire.PDF

cron