diff --git a/Annotation/Getting-annotation-creation-date-from-existing-pdf/.NET/Getting-annotation-creation-date-from-existing-pdf/Program.cs b/Annotation/Getting-annotation-creation-date-from-existing-pdf/.NET/Getting-annotation-creation-date-from-existing-pdf/Program.cs index 7338c81b..8f748fe7 100644 --- a/Annotation/Getting-annotation-creation-date-from-existing-pdf/.NET/Getting-annotation-creation-date-from-existing-pdf/Program.cs +++ b/Annotation/Getting-annotation-creation-date-from-existing-pdf/.NET/Getting-annotation-creation-date-from-existing-pdf/Program.cs @@ -20,71 +20,16 @@ // Iterate through all annotations on the current page for (int j = 0; j < numAnnotations; j++) { - // Identify the type of the annotation and process accordingly - switch (annotations[j].GetType().ToString()) + // Iterate through rectangle annotations + if (annotations[j].GetType().ToString() == "Syncfusion.Pdf.Interactive.PdfLoadedRectangleAnnotation") { - case "Syncfusion.Pdf.Interactive.PdfLoadedFreeTextAnnotation": - // Handle FreeText annotation - PdfLoadedFreeTextAnnotation freeTextAnnot = annotations[j] as PdfLoadedFreeTextAnnotation; - DateTime creationDate0 = freeTextAnnot.CreationDate; - Console.WriteLine(creationDate0); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedEllipseAnnotation": - // Handle Ellipse annotation - PdfLoadedEllipseAnnotation ellipseAnnot = annotations[j] as PdfLoadedEllipseAnnotation; - DateTime creationDate1 = ellipseAnnot.CreationDate; - Console.WriteLine(creationDate1); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedRectangleAnnotation": - // Handle Rectangle annotation - PdfLoadedRectangleAnnotation rectangleAnnot = annotations[j] as PdfLoadedRectangleAnnotation; - DateTime creationDate2 = rectangleAnnot.CreationDate; - Console.WriteLine(creationDate2); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedSquareAnnotation": - // Handle Square annotation - PdfLoadedSquareAnnotation squareAnnot = annotations[j] as PdfLoadedSquareAnnotation; - DateTime creationDate3 = squareAnnot.CreationDate; - Console.WriteLine(creationDate3); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedAnnotation": - // Handle Circle annotation - PdfLoadedCircleAnnotation circleAnnot = annotations[j] as PdfLoadedCircleAnnotation; - DateTime creationDate4 = circleAnnot.CreationDate; - Console.WriteLine(creationDate4); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedLineAnnotation": - // Handle Line annotation - PdfLoadedLineAnnotation lineAnnot = annotations[j] as PdfLoadedLineAnnotation; - DateTime creationDate5 = lineAnnot.CreationDate; - Console.WriteLine(creationDate5); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedInkAnnotation": - // Handle Ink annotation - PdfLoadedInkAnnotation inkAnnot = annotations[j] as PdfLoadedInkAnnotation; - DateTime creationDate6 = inkAnnot.CreationDate; - Console.WriteLine(creationDate6); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedRubberStampAnnotation": - // Handle Rubber Stamp annotation - PdfLoadedRubberStampAnnotation stampAnnot = annotations[j] as PdfLoadedRubberStampAnnotation; - DateTime creationDate7 = stampAnnot.CreationDate; - Console.WriteLine(creationDate7); - break; - - case "Syncfusion.Pdf.Interactive.PdfLoadedTextMarkupAnnotation": - // Handle Text Markup annotation - PdfLoadedTextMarkupAnnotation textAnnot = annotations[j] as PdfLoadedTextMarkupAnnotation; - DateTime creationDate8 = textAnnot.CreationDate; - Console.WriteLine(creationDate8); - break; + // Handle rectangle annotation + PdfLoadedRectangleAnnotation rectangleAnnot = annotations[j] as PdfLoadedRectangleAnnotation; + DateTime creationDate = rectangleAnnot.CreationDate; + Console.WriteLine(creationDate); } } } +//Close the document +document.Close(true); +inputStream.Dispose(); diff --git a/Annotation/Getting-annotation-type-from-existing-PDF/.NET/Getting-annotation-type-from-existing-PDF/Program.cs b/Annotation/Getting-annotation-type-from-existing-PDF/.NET/Getting-annotation-type-from-existing-PDF/Program.cs index 69731fa4..b93edc95 100644 --- a/Annotation/Getting-annotation-type-from-existing-PDF/.NET/Getting-annotation-type-from-existing-PDF/Program.cs +++ b/Annotation/Getting-annotation-type-from-existing-PDF/.NET/Getting-annotation-type-from-existing-PDF/Program.cs @@ -2,9 +2,10 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -//Load the PDF document using a file stream +// Load the PDF document using a file stream FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); PdfLoadedDocument document = new PdfLoadedDocument(inputStream); + // Load the page collection from the PDF document PdfLoadedPageCollection loadedPages = document.Pages; @@ -21,39 +22,36 @@ foreach (PdfLoadedAnnotation annot in loadedPage.Annotations) { // Identify the type of the annotation - PdfLoadedAnnotationType annotationType = FindType(annot); + PdfLoadedAnnotationType annotationType; + + if (annot is PdfLoadedRectangleAnnotation) + { + annotationType = PdfLoadedAnnotationType.RectangleAnnotation; + } + else if (annot is PdfLoadedTextMarkupAnnotation) + { + annotationType = PdfLoadedAnnotationType.TextMarkupAnnotation; + } + else if (annot is PdfLoadedTextWebLinkAnnotation) + { + annotationType = PdfLoadedAnnotationType.TextWebLinkAnnotation; + } + else if (annot is PdfLoadedPopupAnnotation) + { + annotationType = PdfLoadedAnnotationType.PopupAnnotation; + } + else + { + annotationType = PdfLoadedAnnotationType.Null; + } // Print the annotation type to the console Console.WriteLine(annotationType); } } } + // Close the document and release resources document.Close(true); inputStream.Dispose(); -Console.ReadKey(); - -// Method to find the type of a given annotation -static PdfLoadedAnnotationType FindType(PdfLoadedAnnotation annotation) -{ - if (annotation is PdfLoadedRectangleAnnotation) - { - return PdfLoadedAnnotationType.RectangleAnnotation; - } - else if (annotation is PdfLoadedTextMarkupAnnotation) - { - return PdfLoadedAnnotationType.TextMarkupAnnotation; - } - else if (annotation is PdfLoadedTextWebLinkAnnotation) - { - return PdfLoadedAnnotationType.TextWebLinkAnnotation; - } - else if (annotation is PdfLoadedPopupAnnotation) - { - return PdfLoadedAnnotationType.PopupAnnotation; - } - else - { - return PdfLoadedAnnotationType.Null; - } -} \ No newline at end of file +Console.ReadKey(); \ No newline at end of file