Exemplo n.º 1
0
        public void PutPolyLineAnnotationTest()
        {
            PolyLineAnnotation annotation = new PolyLineAnnotation()
            {
                Name  = "Updated Test",
                Rect  = new Rectangle(100, 100, 200, 200),
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex   = 1,
                Title    = "Title Updated",
                Vertices = new List <Point>
                {
                    new Point(10, 10),
                    new Point(20, 10),
                    new Point(10, 20),
                    new Point(10, 10)
                }
            };

            var    lineResponse = api.GetDocumentPolyLineAnnotations(Name, folder: FolderName);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = api.PutPolyLineAnnotation(Name, annotationId, annotation, folder: FolderName);

            Console.WriteLine(response);
        }
        public void PutPolyLineAnnotationTest()
        {
            PolyLineAnnotation annotation = new PolyLineAnnotation(Rect: new Rectangle(100, 100, 200, 200),
                                                                   Vertices: new List <Point>
            {
                new Point(10, 10),
                new Point(20, 10),
                new Point(10, 20),
                new Point(10, 10)
            })
            {
                Name  = "Updated Test",
                Flags = new List <AnnotationFlags> {
                    AnnotationFlags.Hidden, AnnotationFlags.NoView
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                RichText            = "Rich Text Updated",
                Subject             = "Subj Updated",
                ZIndex = 1,
                Title  = "Title Updated"
            };

            var    lineResponse = PdfApi.GetDocumentPolyLineAnnotations(Name, folder: TempFolder);
            string annotationId = lineResponse.Annotations.List[0].Id;

            var response = PdfApi.PutPolyLineAnnotation(Name, annotationId, annotation, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
Exemplo n.º 3
0
        /**
         * Creates annotation, type of annotation is taken from given properties
         */
        public static Annotation CreateAnnotation(Document doc, Page page, int index, AnnotationProperties props)
        {
            Annotation ann      = null;
            int        addAfter = index - 1;

            switch (props.Subtype)
            {
            case "Line": ann = new LineAnnotation(page, props.BoundingRect, props.StartPoint, props.EndPoint, addAfter); break;

            case "Circle": ann = new CircleAnnotation(page, props.BoundingRect, addAfter); break;

            case "Square": ann = new SquareAnnotation(page, props.BoundingRect, addAfter); break;

            case "FreeText": ann = new FreeTextAnnotation(page, props.BoundingRect, "", addAfter); break;

            case "PolyLine": ann = new PolyLineAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break;

            case "Polygon": ann = new PolygonAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break;

            case "Link": ann = new LinkAnnotation(page, props.BoundingRect, addAfter); break;

            case "Ink": ann = new InkAnnotation(page, props.BoundingRect, addAfter); break;

            case "Underline": ann = new UnderlineAnnotation(page, addAfter, props.Quads); break;

            case "Highlight": ann = new HighlightAnnotation(page, addAfter, props.Quads); break;

            default: throw new Exception("Logic error");
            }
            AnnotationAppearance app = new AnnotationAppearance(doc, ann);

            app.CaptureAnnotation();
            app.Properties.SetFrom(props);
            app.Properties.Dirty = true;
            app.UpdateAppearance();
            app.ReleaseAnnotation();
            return(ann);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("PolyLineAnnotation Sample:");
            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../PolyLineAnnotations-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                // Create a new document and blank first page
                Document doc  = new Document();
                Rect     rect = new Rect(0, 0, 612, 792);
                Page     page = doc.CreatePage(Document.BeforeFirstPage, rect);
                Console.WriteLine("Created new document and first page.");

                // Create a vector of polyline vertices
                List <Point> vertices = new List <Point>();
                Point        p        = new Point(100, 100);
                vertices.Add(p);
                p = new Point(200, 300);
                vertices.Add(p);
                p = new Point(400, 200);
                vertices.Add(p);
                Console.WriteLine("Created an array of vertex points.");

                // Create and add a new PolyLineAnnotation to the 0th element of first page's annotation array
                PolyLineAnnotation polyLineAnnot = new PolyLineAnnotation(page, rect, vertices, -1);
                Console.WriteLine("Created new PolyLineAnnotation as 0th element of annotation array.");

                // Now let's retrieve and display the vertices
                IList <Point> vertices2;
                vertices2 = polyLineAnnot.Vertices;
                Console.WriteLine("Retrieved the vertices of the polyline annotation.");
                Console.WriteLine("They are:");
                for (int i = 0; i < vertices2.Count; i++)
                {
                    Console.WriteLine("Vertex " + i + ": " + vertices2[i]);
                }

                // Add some line ending styles to the ends of our PolyLine
                polyLineAnnot.StartPointEndingStyle = LineEndingStyle.ClosedArrow;
                polyLineAnnot.EndPointEndingStyle   = LineEndingStyle.OpenArrow;

                // Let's set some colors and then ask the polyline to generate an appearance stream
                Color color = new Color(0.5, 0.3, 0.8);
                polyLineAnnot.InteriorColor = color;
                color = new Color(0.0, 0.8, 0.1);
                polyLineAnnot.Color = color;
                Console.WriteLine("Set the stroke and fill colors.");
                Form form = polyLineAnnot.GenerateAppearance();
                polyLineAnnot.NormalAppearance = form;
                Console.WriteLine("Generated the appearance stream.");

                // Update the page's content and save the file with clipping
                page.UpdateContent();
                doc.Save(SaveFlags.Full, sOutput);

                // Kill the doc object
                doc.Dispose();
                Console.WriteLine("Killed document object.");
            }
        }