Move the position of a text annotation

If you are a C/C++/C# developer and have any questions about using our products from your application here is the place to post them.
Post Reply
pdfuser
Posts: 7
Joined: Tue Mar 01 2011

Move the position of a text annotation

Post by pdfuser »

I have a program that allows users to add text annotations to a PDF document.
I would like to give them the ability to move the text block once it has been added to the document.

I have tried putting the document into into acReportStateAnnotate and calling LockAllObjects(false). This allows me to edit the text, but doesn't let me move the position of the text, which is the exact opposite of what I am looking to do.

Is there a way to allow the user to move the text block and possibly resize it once added to the document?
Devteam
Posts: 119
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Re: Move the position of a text annotation

Post by Devteam »

You should switch to annotation mode before allowing the user to insert the text objects. When you switch to annotation mode, the objects will be created as annotations rather than static text objects and the user will be able to move these annotations.

If you are creating the objects using the CreateObject method rather than letting the user dynamically add the objects on the page, you should also set the Annotation attribute on the objects that you create. E.g.:

(pseudo-code)
pdf.ReportState = acReportStateAnnotate or pdf.DoCommandTool( acCommandToolAnnotationMode )
pdf.CreateObject( acObjectTypeText, "Label 1" )
with pdf.GetObjectByName( "Label 1" )
.AttributeByName( "Annotation" ) = 1
....
end with
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - https://www.amyuni.com
pdfuser
Posts: 7
Joined: Tue Mar 01 2011

Re: Move the position of a text annotation

Post by pdfuser »

I am creating the text object and setting the annotation property to true.
Here is the basic code for what I am doing:

pdfCreator_Viewer.Document.ReportState = IacReportState.acReportStateAnnotate;

Amyuni.PDFCreator.IacObject attribute = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "");

// Fill in the attribute details.
attribute.AttributeByName("Name").Value = "Annote 1";
attribute.AttributeByName("Text").Value = "Some Text";
attribute.AttributeByName("Annotation").Value = true;

Set height, width, location......


pdfCreator_Viewer.Document.ReportState = IacReportState.acReportStateRun;
pdfCreator_Viewer.Document.Save(_pdfFileStream, IacFileSaveOption.acFileSaveDefault);


Now if the document is sent to another person, who wants to change the location of the text annotation, I can't seem to be able to allow the user to drag the text to a new location.
Is there a way to put the document into some sort of edit mode so that they can move them?
Devteam
Posts: 119
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Re: Move the position of a text annotation

Post by Devteam »

If the recipients of the document have the Amyuni PDF Creator, Acrobat Standard or Professional or any other PDF editor, they will be able to edit or move the annotations. If the recipients only have Acrobat Reader then no changes to the annotations are allowed. Acrobat Reader X has some annotation capabilities and might allow editing the annotations, however anything earlier than Acrobat Reader X will not allow any editing.
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - https://www.amyuni.com
pdfuser
Posts: 7
Joined: Tue Mar 01 2011

Re: Move the position of a text annotation

Post by pdfuser »

Thanks for the replies.

I have a custom app that uses the Amyuni PDF Viewer control to view the PDF.
The user can then click on the doc and add a text annotation at the spot where they clicked. The annotation is added in the Fire Moune Down event using the code from above.
Still using the PDF viewer control, I'd like them to be able to move/resize the annotation they just added.

I expected the annotation to be movable just by dragging it around with the mouse, but this doesn't appear to be the case.
Do I need to implement code in the Fire Mouse Move event to move the selected annotation to wherever the mouse is or should it do this on its own?

Thanks again for your help.
Devteam
Posts: 119
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Re: Move the position of a text annotation

Post by Devteam »

At what time are you switching the control back into run mode? If you keep the control in Annotation mode, the user will be able to move or resize the annotations unless your MouseDown event handling code is preventing the control from receiving these events. When the user clicks on the control, how do you decide if you want to create a new annotation or let the control handle the event? One suggestion would be to to check the pObject parameter of the MouseDown event, if this parameters point to an annotation object, then let the control handle the event. If not, create the annotation the way you are currently doing it.

As a side note, you should use IacFileSaveOption.acFileSaveViewOnly rather than IacFileSaveOption.acFileSaveDefault as the latter produces larger PDF files.
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - https://www.amyuni.com
pdfuser
Posts: 7
Joined: Tue Mar 01 2011

Re: Move the position of a text annotation

Post by pdfuser »

Thanks for pointing me in the right direction on this one.
Turns out that the return value 'default(int);' that is automatically generated by the IDE was causing the problem.
I guess that this was causing the event to be canceled before it gets to the annotation.
I changed the return value to 1 and it works as expcected; I am able to move the annotations around and resize them.

I will change my code to return 0 when I am adding the annotation and 1 when I am not, so that the event is passed dowm to the control.
Post Reply