FreeText annotation in editing mode

126 views
Skip to first unread message

Dũng Nguyễn

unread,
Feb 28, 2018, 4:06:11 PM2/28/18
to PDFTron WebViewer
Hi, 

I followed this guide to create FreeTextAnnotation programmatically: 
https://groups.google.com/forum/#!msg/pdfnet-webviewer/YCHK1TQp3pg/48Q-Mn6zFcgJ

It works, and I want to modify a little bit like this:
1. Right after the freetext annotation draw on viewer, I want it auto switch to editing mode and focus on editbox (like the way TextAnnotationCreateTool works)
2. How can we change the font size of editbox when switch to editing mode?

Thanks. 

Matt Parizeau

unread,
Mar 1, 2018, 2:16:38 PM3/1/18
to PDFTron WebViewer
Hi,

1. Can you clarify what you mean by auto switch to editing mode and focus on the edit box? Do you want it to be the same behavior that happens after creating a FreeText annotation from the tool in the UI where you can start typing in the box right away?
When I run the code to programmatically create a FreeText then this is the behavior that I'm already seeing; the annotation is automatically switched to editing mode.

2. A user can change the font size of the annotation by clicking it to select, pressing the "Style" button that appears above and then clicking on the buttons labelled 8, 12, 24, 36. To change the font size programmatically you can set the FontSize property on the annotation. For example:
freeText.FontSize = '36pt';

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Dũng Nguyễn

unread,
Mar 2, 2018, 1:17:53 PM3/2/18
to PDFTron WebViewer
Hi Matt,

1. Yes, I create a custom tool to add a FreeText annotation, follow the guide (https://groups.google.com/forum/#!msg/pdfnet-webviewer/YCHK1TQp3pg/48Q-Mn6zFcgJ) to add free text programmatically, and I need to start typing in the box right away.

2. From my custom tool, I set the FreeText's FontSize = 0pt to auto font sizing. However, when double click to change text from textbox, the box's font size still too small (9pt, I think), Can we change the box's font size?

Thanks,

Vào 02:16:38 UTC+7 Thứ Sáu, ngày 02 tháng 3 năm 2018, Matt Parizeau đã viết:

Matt Parizeau

unread,
Mar 5, 2018, 2:55:38 PM3/5/18
to PDFTron WebViewer
1. Here is code that works for me. I've made it add a new FreeText annotation when clicking the search button and after doing this the FreeText is immediately editable:
$('#searchButton').on('click', function() {
 
var freeText = new Annotations.FreeTextAnnotation();
  freeText
.X = 150;
  freeText
.Y = 200;
  freeText
.Width = 150;
  freeText
.Height = 50;
  freeText
.setPadding(new Annotations.Rect(0, 0, 0, 0));
  freeText
.PageNumber = 1;
  freeText
.setContents("My Text");
  freeText
.FillColor = new Annotations.Color(0, 255, 255);
  freeText
.FontSize = '0pt';

 
var annotManager = readerControl.docViewer.getAnnotationManager();
  annotManager
.addAnnotation(freeText);
  annotManager
.drawAnnotations(freeText.PageNumber);
});

2. I see, with auto font sizing WebViewer sets the value to a specific number when editing. If you wanted to change this you could add the following code to a config file:

$(document).on('DOMNodeInserted', function(e) {
 
if (e.target.className === 'freetext') {
    setTimeout
(function() {
     
var zoom = readerControl.docViewer.getZoom();

      e
.target.style.fontSize = 30 * zoom + 'pt';
   
}, 0);
 
}
});

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Reply all
Reply to author
Forward
0 new messages