Page 1 of 2

DocuVieware ASP.Net Annotation

Posted: Fri Dec 19, 2014 9:58 pm
by parthas
Hello I tried to retrieve the contents of the annotations on the sample PDF document "st_exupery_le_petit_prince.pdf" with the following code:

Code: Select all

            GdPicture11.GdPicturePDF lPdf = new GdPicture11.GdPicturePDF();
            if (DocuVieware1.GetNativePDF(out lPdf) == GdPicture11.GdPictureStatus.OK) 
            {
                int lAnnotationCounts = lPdf.GetAnnotationCount();
                for (int i = 0; i < lAnnotationCounts; i++) 
                {
                    string lContents = lPdf.GetAnnotationContents(i);
                    
                    string lSubtype = lPdf.GetAnnotationSubType(i);
                    string lType = lPdf.GetAnnotationType(i);
                }
            }
I can successfully retrieve the subtypes and types but the contents are always empty.

Re: Docuviewware ASP.Net Annotation Contents are empty

Posted: Sat Dec 20, 2014 8:57 pm
by Loïc
Hello parthas,

Thank you for inaugurating the DocuVieware section :)

If you want full control over annotations you need to use the AnnotationManager class.

Here an example that demonstrates some concepts which, I hope, will shed some lights.
It consists to use a custom action in order to asynchronously alter the current page annotations. All page annotations will be iterated, and for each rubber stamp annotation, the text will be switched to "I Love DocuVieware".

Please let me know if there is anything obscure.


Here the JS code to execute in the client-side for such purpose:

Code: Select all

      DocuViewareAPI.PostCustomServerAction('DocuVieware1', true, 'MyPageAnnotationsUpdate', null);



Here the C# server-side code to use for such purpose:

Code: Select all

       
        protected void Page_Load(object sender, EventArgs e)
        {
            DocuVieware1.CustomAction += handleCustomAction;
        }


        private void handleCustomAction(object sender, CustomActionEventArgs e)
        {
            if (e.actionName == "MyPageAnnotationsUpdate")
            {

                if (DocuVieware1.GetDocumentType() == GdPicture11.DocumentType.DocumentTypePDF)
                {
                    GdPicture11.GdPicturePDF gdPicturePDF;
                    //Getting native PDF
                    if (DocuVieware1.GetNativePDF(out gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
                    {
                        //Using an AnnotationManager object to parse PDF annotations
                        using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager())
                        {
                            if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
                            {
                                //Iterating through all annotation and changing sticky-note text to "I Love DocuVieware"
                                int annotationCount = annotationManager.GetAnnotationCount();
                                for (int i = 0; i < annotationCount; i++)
                                {
                                    GdPicture11.Annotations.Annotation annot = annotationManager.GetAnnotationFromIdx(i);
                                    if (annot is GdPicture11.Annotations.AnnotationRubberStamp)
                                    {
                                        ((GdPicture11.Annotations.AnnotationRubberStamp)annot).Text = "I Love\r\nDocuVieware";
                                    }
                                }
                                //Now we are done with the annotation manager, let's save annotations into the PDF.
                                annotationManager.SaveAnnotationsToPage();

                                //Asking DV to update client page
                                DocuVieware1.RedrawPage();
                            }
                        }
                    }
                }
            }
        }

Re: DocuVieware ASP.Net Annotation

Posted: Mon Dec 22, 2014 11:57 pm
by parthas
This is a nice and clear example. Thank you very much. We are looking forward to the release of GdPicture11.

Re: DocuVieware ASP.Net Annotation

Posted: Wed May 06, 2015 11:50 pm
by badger
I am trying to do something similar but it's not working. Essentially what I want to do it be able to show and hide annotations and I want to be able to enable and disable the ability to edit the annotations depending upon users permissions. I can't find anyway to hide annotations so I thought I would use the same call back as above. Here below I am trying load them. The xml annotations file does load correctly on my pageload call so I know that the annotations do work on the screens and the format is good. Also I generated the format by using the gdviewer code. Also, what does DocuVieware1.AnnotationEditorMode = False; do??? I tried it but it doesn't work????

This is my code snippet that isn't working

Code: Select all

                if (e.docuVieware.GetDocumentType() == GdPicture11.DocumentType.DocumentTypePDF) {

                    GdPicture11.GdPicturePDF gdPicturePDF;
	                //Getting native PDF
	                if (e.docuVieware.GetNativePDF(out gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {
		                //Using an AnnotationManager object to parse PDF annotations
		                e.docuVieware.AnnotationEditorMode = false;

		                using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager()) {
			                if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {
				                //Iterating through all annotation and changing sticky-note text to "I Love DocuVieware"
				                GdPicture11.GdPictureStatus status = default(GdPicture11.GdPictureStatus);

/////////////////////////// the status of the next call comes back as an invalid parameter.  Not sure why????????
				                status = annotationManager.LoadAnnotationsFromXMP("c:\\convert\\newfile_113684506.xml");

				                annotationManager.SaveAnnotationsToPage();

				                //Asking DV to update client page
				                e.docuVieware.ReloadAnnotations();
				                e.docuVieware.RedrawPage();
				                //End If
			                }
		                }
	                }
                }

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 12:39 pm
by Loïc
Hello badger,

I don't fully understand what the problem is and all i can tell so far is that your code snippet does not reflects what you are saying.
So could you explain clearly what you are trying to do?

Thanks for any clarification.

With best regards,

Loïc

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 3:01 pm
by badger
Hi Loic,

Basically I need to be able to do things with annotations. I need to have the ability to display them and hide them as well as control whether the user can make changes or have the screen as read only.

The code I provided essentially takes one of the demos called image_cleanup.aspc.cs and tweaks the callback. I am trying to load annotations to it as a work around because I don't know how to display the annotations and hide them.

Code: Select all

        public static void handleImageCleanupAction(CustomActionEventArgs e)
        {


            if (e.docuVieware.PageCount > 0)
            {
                if (e.docuVieware.GetDocumentType() == GdPicture11.DocumentType.DocumentTypePDF) {

                    GdPicture11.GdPicturePDF gdPicturePDF;
	                //Getting native PDF
	                if (e.docuVieware.GetNativePDF(out gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {

                        // just testing this next line to see if that can put the annotation into read only mode.... it doesn't seem to do anything
                        e.docuVieware.AnnotationEditorMode = false;

		                using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager()) {

                            if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {
				                GdPicture11.GdPictureStatus status = default(GdPicture11.GdPictureStatus);
				                status = annotationManager.LoadAnnotationsFromXMP("c:\\convert\\newfile_113684506.xml");

                                // status from above returens an error #2 about an invalid paramater yet when I make the same call with the
                                // same xml file in the pageload section of code it works fine.
                                annotationManager.SaveAnnotationsToPage();

				                e.docuVieware.ReloadAnnotations();
				                e.docuVieware.RedrawPage();
			                }
		                }
	                }
                }
}

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 5:34 pm
by Loïc
OK I see,

Here a code snippet that iterates all annotations of the current page and when a sticky annotation is detected the text will be changed and the annotation is made as read-only. With it you should learn all basics annotation related concepts in DocuVieware. You can use it "as is" in the Annotation Demo source code shipped with the installation package.

This is a code snippet using post-back, if you need the ajax version using custom actions just let me know.

Code: Select all

       protected void Button1_Click(object sender, EventArgs e)
        {
            GdPicture11.GdPicturePDF gdPicturePDF;
            if (DocuVieware1.GetNativePDF(out gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
            {
                using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager())
                {
                    if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
                    {
                        int annotationCount = annotationManager.GetAnnotationCount();
                        for (int i = 0; i < annotationCount; i++)
                        {
                            GdPicture11.Annotations.Annotation annotation = annotationManager.GetAnnotationFromIdx(i);
                            if (annotation is GdPicture11.Annotations.AnnotationStickyNote)
                            {
                                GdPicture11.Annotations.AnnotationStickyNote stickyAnnot = annotation as GdPicture11.Annotations.AnnotationStickyNote;
                                stickyAnnot.Text = "My new text";
                                stickyAnnot.CanMove = false;
                                stickyAnnot.CanSelect = false;
                                stickyAnnot.CanResize = false;
                                stickyAnnot.CanRotate = false;
                            }
                        }
                        annotationManager.SaveAnnotationsToPage();
                        DocuVieware1.ReloadAnnotations();
                    }
                }
            }
        }

With best regards,

Loïc

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 6:08 pm
by badger
Hi Loic,

I am getting closer. I am using the Ajax code. I have it mostly working, I was indexing by 0 instead of 1 and my annotations were on page 2 of a two page document so that was causing my problem. So I am now getting my annotations to display and when I click on a button and hide as well by removing the annotations.

Is there a way for me to lock down (put in read only mode?) the annotations? Something like this in my customaction event handler?

If (e.docuVieware.EnableGdPictureAnnotations = True) Then
e.docuVieware.AnnotationEditorMode = False
e.docuVieware.EnableGdPictureAnnotations = False
Else
e.docuVieware.AnnotationEditorMode = True
e.docuVieware.EnableGdPictureAnnotations = True
End If

Thanks!

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 6:10 pm
by badger
Sorry, I miss read your email, so I can just go through the annotations and turn on or off the can move etc. Got it.

Thanks!

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 6:13 pm
by Loïc
You're very welcome. Just let me know if you need any other detail.

Re: DocuVieware ASP.Net Annotation

Posted: Thu May 07, 2015 8:41 pm
by badger
Hi Loic,

I am getting closer.

In the code below, I toggle the visible value when I click a button on the screen using ajax from true to false and back again. Note that on the screen the thumbnail does draw correctly in either direction.

When going through the annotations and it will hide them properly (I default to all the annotations being visible) but when I turn it back to true I get a javascript exception:

Unhandled exception at line 387, column 491 in http://localhost:50976/WebResource.axd? ... 7505915949

0x800a139e - JavaScript runtime error: NotFoundError



Here is procedure:

Code: Select all

public static void handleCustomAction(CustomActionEventArgs e)
{
	// this is just a place holder.... we can add buttons on our screen and catch them here based on the action
	// and we can pass in data from the args
	if (e.actionName == "MyPageAnnotationsUpdate") {
		string docRef = Convert.ToString(e.args);
		annotParamaters readerParameters = (annotParamaters)JsonConvert.DeserializeObject<annotParamaters>(e.args.ToString());
		bool displayAnnot = true;
		bool editAnnot = true;
		bool moveAnnot = true;


		if (e.docuVieware.GetDocumentType() == GdPicture11.DocumentType.DocumentTypePDF) {
			GdPicturePDF gdPicturePDF = new GdPicturePDF();
			//Getting native PDF

			if (e.docuVieware.GetNativePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {
				using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager()) {
					if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK) {
						//Iterating through all annotation and inverting visible flag

						int count = 0;

						for (int page = 1; page <= gdPicturePDF.GetPageCount; page += 1) {
							//Dim page As Integer = readerParameters.currentPage
							gdPicturePDF.SelectPage(page);
							annotationManager.SelectPage(page);

							int annotationCount = annotationManager.GetAnnotationCount();
							if (annotationCount > 0) {
								int x = 1;
								if (x == 1) {
									for (int ann = annotationCount - 1; ann >= 0; ann += -1) {
										Annotation sticky = annotationManager.GetAnnotationFromIdx(ann);
										if ((sticky.Visible == true)) {
											sticky.Visible = false;
										} else {
											sticky.Visible = true;
										}

										//sticky.CanMove = moveAnnot
										//sticky.CanResize = moveAnnot
										//sticky.CanRotate = moveAnnot
										//sticky.CanSelect = editAnnot
									}
								}
								count += 1;
								annotationManager.SaveAnnotationsToPage();
								e.docuVieware.RedrawPage();
								e.docuVieware.ReloadAnnotations();
							}
						}
					}
				}
			}
		}
	}

}

Re: DocuVieware ASP.Net Annotation

Posted: Fri May 08, 2015 5:09 pm
by badger
Hi Loic,

To get around the javascript exception error, I am doing a postback when I want to make the annotations visible again. Now the problem is my thumbnails look like they are stuck trying to reload. If I close the thumbnail viewer and open it again it the images come up correctly.

Any chance that the javascript exception could be validated to see why it's not working on my previous post or how do I fix the thumbnails?

I am so close to having this work the way I need it to and I can then move forward with licensing this for our servers.

Thanks.

Re: DocuVieware ASP.Net Annotation

Posted: Fri May 08, 2015 7:38 pm
by badger
Hi Loic,

I have traced it down to this javascript section that is failing when I turn the annotations back on

for(var c=0;c<a.cache.Annots.length;c++)
{
var d=a.cache.Annots[c];
d.annotApp.pageNo==b&&(a.dom.viewerArea.removeChild(d.canvas),a.cache.Annots.splice(c,1),c--)
}

When debugging, I can see that d.annotApp.visible is false which is correct so it shouldn't be calling the removeChild.

Anything you can do for me on this?

Thanks.

Re: DocuVieware ASP.Net Annotation

Posted: Fri May 08, 2015 9:23 pm
by badger
Hi Loic,

I was editing the javascript in Chrome to see if I could solve it. It was pretty easy:

for the removeAnnot procedure I did this change.....

d.annotApp.pageNo==b&&(a.dom.viewerArea.removeChild(d.canvas)

to this:

d.annotApp.pageNo==b&&d.annotApp.visible==true&&(a.dom.viewerArea.removeChild(d.canvas)


Let me know what I can do next? I really need this to work.

Thanks!

Re: DocuVieware ASP.Net Annotation

Posted: Mon May 11, 2015 5:17 pm
by badger
Just checking if anyone has had a chance to look into the problem?

Thanks