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;
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