lookiagro.blogg.se

Soda pdf shrink text size in field
Soda pdf shrink text size in field





soda pdf shrink text size in field

/ A font size that would ensure the value fit within the / The model representing the name and value / Compute the font size to ensure a given value would fit within } Find the appropriate font size to fit a value into a text field /// } Find the width of a value based on a font size private float ComputeValueWidth( string value, float targetFontSize)įloat valueWidth = BaseFont.CreateFont().GetWidthPoint(value, targetFontSize) TextField tmp = new TextField(null, null, null) ĪcroFields.DecodeGenericDictionary(mergedFieldAttributes, tmp) PdfDictionary mergedFieldAttributes = fieldItem.GetMerged(0) Private float GetFontSizeForField(AcroFields acroFields, string fieldName)ĪcroFields.Item fieldItem = acroFields.GetFieldItem(fieldName) / The font size attribute of the field.

soda pdf shrink text size in field

/ Helper method to compute the font size of a field. } Find the font size of a text field /// If (fieldPositions != null & fieldPositions.Length = 5) Private float? ComputeFieldWidth(AcroFields acroFields, string name)įloat fieldPositions = acroFields.GetFieldPositions(name) / The container's width or null if the data is not available / The acro fields representing the PDF. / Helper method to compute the width of a field's container Set the font size of the text field to the final font size.Ī PDF text field is basically a rectangular container and we can compute the width using the left and right positions of the container on the page, as the below snippets demonstrate.Keep reducing the font size until the width of the value is less than or equal to the width of the text field.Compute the width of the value using the current font size as the starting point.Find the current font size and width of the text field.After a bit of googling, I found and adopted the solution in this StackOverFlow to solve this problem by dynamically compute the appropriate font size I can use so that the value can fit within the field. Sometimes, we have a string that is too long to fit within the rectangle area of the text field. In one of the asp.net core projects I worked on, I used to programmatically fill out a PDF form.







Soda pdf shrink text size in field