Set AcroField Text Size to Auto
Asked Answered
W

1

5

Using itextsharp, I'm attempting to set the font size of my form's text fields to auto.

I'm currently doing something like this:

Object d = 0.0;

PdfReader reader = new PdfReader(path);

byte [] pdf;

using (var ms = new MemoryStream())
{
    PdfStamper stamper = new PdfStamper(reader, ms);

    AcroFields fields = stamper.AcroFields;

    foreach (var f in fields.Fields.Keys)
    {
        fields.SetFieldProperty(f, "textsize", d, null);
    }
}

But I'm getting the following error:

System.InvalidCastException: Specified cast is not valid.
at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object value, Int32[] inst)

How can I fix this?

Woodnote answered 24/7, 2014 at 21:14 Comment(0)
W
8

Using 0f instead of d in the call SetFieldProperty let me change the font size to auto.

Woodnote answered 24/7, 2014 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.