Automatically size PdfFreeTextAnotation while typing.

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Automatically size PdfFreeTextAnotation while typing.

Post by IntegraHarlan »

Hi,
I would like to automatically size the PdfFreeTextAnnotation while the text is entered to fit the annotation to the size of the text.
I am currently using a derived InteractionAreaAppearanceManager class to trap key board events and have been trying to do my sizing in this class.
I have not been able to figure out how to make it work.
Can you help with this?

Thanks
Harlan
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Automatically size PdfFreeTextAnotation while typing.

Post by Alex »

Hi Harlan,

How do you want to increase annotation size? Do you want to increase only width, i.e. work with single line text? Or maybe do you want to increase annotation width and height, i.e. work with multiline text?

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Automatically size PdfFreeTextAnotation while typing.

Post by IntegraHarlan »

Hi Alex,
Ideally, I would like to be able to configure how I can adjust the size.
1. In one configuration, I would like to adjust the height only so that the width will stay consistent and the height will adjust as the text is wrapped or the enter key is hit while typing text.
2. In a different configuration, I would like to width to adjust and keep the height consistent unless enter key is hit while typing text.

Thanks
Harlan.
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Automatically size PdfFreeTextAnotation while typing.

Post by Alex »

Hi Harlan,

Thank you for information. We need some time for implementing necessary functionality. I will contact you shortly.

Best regards, Alexander
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Automatically size PdfFreeTextAnotation while typing.

Post by Alex »

Hi Harlan,

We created the PdfFreeTextExpansionController class, which allows to control behaviour of PDF free text annotation, and send it to you. Please use the class and let me know if you will have any question or problem. Class can be used with version 9.1.0.3 or higher.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Automatically size PdfFreeTextAnotation while typing.

Post by IntegraHarlan »

Hi Alexander,
I finally got a chance to implement the PdfFreeTextExpansionController class you provided.
It does not work as I would expect it to.
As I type, the text will sometimes move around in the annotation instead of the annotation sizing itself.
This is most noticeable when I assign a maximum width value to the TextBoxMaxWidth property of the class.
As I am typing and the text reaches the width of the text box, some times the text is moved to the left instead of the text box width increasing.
Some times the text will prematurely be wrapped instead of the text box width increasing.
Also, some times when the text is wrapped, the text will just move up a line instead of the text box height changing.
I was able to reproduce this in the Winforms C# PdfEditorDemo application by adding the PdfFreeTextExpansionController to the application and setting the properties.

Are there any refinements that can be made to this to make it size the annotation correctly?

Thanks
Harlan
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Automatically size PdfFreeTextAnotation while typing.

Post by Alex »

Hi Harlan,

For getting "ideal" sizing of PdfFreeTextAnotation during text editing, you need to use the same font in PDF annotation and TextBox control, which is used for text editing. Now PdfFreeTextAnotation and TextBox control use different fonts with diffent sizes.

Please try to use the same font in PdfFreeTextAnotation and TextBox control.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Automatically size PdfFreeTextAnotation while typing.

Post by IntegraHarlan »

Hi Alexander,
I tried setting the font in the text box control to match the font in the annotation.
I am still seeing the same issue with the text moving around in the text box and premature wrapping.

Thanks
Harlan
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: Automatically size PdfFreeTextAnotation while typing.

Post by Alex »

Hi Harlan,
I tried setting the font in the text box control to match the font in the annotation.
I am still seeing the same issue with the text moving around in the text box and premature wrapping.
Please send us (to support@vintasoft.com) a small project, which allows to reproduce the problem. We need to reproduce the problem on our side.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Automatically size PdfFreeTextAnotation while typing.

Post by IntegraHarlan »

Hi Alexander
You can just use the PdfFreeTextExpansionController class that you sent me and add the code to add the font.
Using your sample PdfTextFields.pdf which uses the Times-Rome Pdf font I added the following line to the TextBoxShowing method.
Add the line after the _currentFont field is set.

Code: Select all

                // if annotation font does NOT have linked font in temporary PDF document
                if (!_annotationFontToTempFont.TryGetValue(annotation.Font, out _currentFont))
                {
                    // create copy of annotation font in temporary PDF document
                    _currentFont = annotation.Font.CreateCopy(_tempDocument);
                    // save link between annotation font and font in temporary PDF document
                    _annotationFontToTempFont.Add(annotation.Font, _currentFont);
                }
                
                e.TextBox.Font = new Font("Times New Roman", annotation.FontSize);
Thanks
Harlan
Post Reply