public void PutSquareAnnotationExample() { //ExStart: PutSquareAnnotationExample SquareAnnotation annotation = new SquareAnnotation() { Name = "Updated Example", 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" }; var lineResponse = api.GetDocumentSquareAnnotations(Name, folder: FolderName); string annotationId = lineResponse.Annotations.List[0].Id; var response = api.PutSquareAnnotation(Name, annotationId, annotation, folder: FolderName); Console.WriteLine(response); //ExEnd: PutSquareAnnotationExample }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // If you wish to load an existing document uncomment the line below and comment the Add page section instead // pdfDocument.Load(@".\existing_document.pdf"); // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Draw sample markup annotations SquareAnnotation squareAnnotation = new SquareAnnotation(20, 20, 80, 80); squareAnnotation.BackgroundColor = new ColorRGB(255, 240, 240); squareAnnotation.BorderStyle.Style = BorderStyle.Dashed; squareAnnotation.BorderStyle.DashPattern = new DashPattern(new float[] { 3, 1, 3 }); page.Annotations.Add(squareAnnotation); CircleAnnotation circleAnnotation = new CircleAnnotation(120, 20, 80, 80); circleAnnotation.BackgroundColor = new ColorRGB(240, 250, 240); circleAnnotation.Color = new ColorRGB(128, 0, 128); circleAnnotation.BorderEffect.Effect = BorderEffect.Cloudy; circleAnnotation.BorderEffect.Intensity = 2; page.Annotations.Add(circleAnnotation); LineAnnotation lineAnnotation = new LineAnnotation(20, 180, 100, 120); lineAnnotation.Color = new ColorRGB(255, 0, 0); lineAnnotation.StartLineStyle = LineEndingStyle.Butt; lineAnnotation.EndLineStyle = LineEndingStyle.OpenArrow; page.Annotations.Add(lineAnnotation); PointF[] pp = { new PointF(120, 120), new PointF(130, 130), new PointF(140, 120), new PointF(150, 130), new PointF(160, 120), new PointF(170, 130) }; PointsArray points = new PointsArray(pp); PolylineAnnotation polylineAnnotation = new PolylineAnnotation(points); polylineAnnotation.BorderStyle.Width = 2; page.Annotations.Add(polylineAnnotation); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Draw sample markup annotations SquareAnnotation squareAnnotation = new SquareAnnotation(20, 20, 80, 80); squareAnnotation.BackgroundColor = new ColorRGB(255, 240, 240); squareAnnotation.BorderStyle.Style = BorderStyle.Dashed; squareAnnotation.BorderStyle.DashPattern = new DashPattern(new float[] { 3, 1, 3 }); page.Annotations.Add(squareAnnotation); CircleAnnotation circleAnnotation = new CircleAnnotation(120, 20, 80, 80); circleAnnotation.BackgroundColor = new ColorRGB(240, 250, 240); circleAnnotation.Color = new ColorRGB(128, 0, 128); circleAnnotation.BorderEffect.Effect = BorderEffect.Cloudy; circleAnnotation.BorderEffect.Intensity = 2; page.Annotations.Add(circleAnnotation); LineAnnotation lineAnnotation = new LineAnnotation(20, 180, 100, 120); lineAnnotation.Color = new ColorRGB(255, 0, 0); lineAnnotation.StartLineStyle = LineEndingStyle.Butt; lineAnnotation.EndLineStyle = LineEndingStyle.OpenArrow; page.Annotations.Add(lineAnnotation); PointF[] pp = { new PointF(120, 120), new PointF(130, 130), new PointF(140, 120), new PointF(150, 130), new PointF(160, 120), new PointF(170, 130) }; PointsArray points = new PointsArray(pp); PolylineAnnotation polylineAnnotation = new PolylineAnnotation(points); polylineAnnotation.BorderStyle.Width = 2; page.Annotations.Add(polylineAnnotation); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start("result.pdf"); }
internal override Annotation Clone(IDocumentEssential owner, Page page) { if (Page == null) { ApplyOwner(owner); SetPage(page, true); return(this); } PDFDictionary res = AnnotationBase.Copy(Dictionary); MarkupAnnotationBase.CopyTo(Dictionary, res); SquareCircleAnnotation.CopyTo(Dictionary, res); SquareAnnotation annot = new SquareAnnotation(res, owner); annot.SetPage(Page, false); annot.SetPage(page, true); return(annot); }
public void PutSquareAnnotationTest() { SquareAnnotation annotation = new SquareAnnotation(Rect: new Rectangle(100, 100, 200, 200)) { 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.GetDocumentSquareAnnotations(Name, folder: TempFolder); string annotationId = lineResponse.Annotations.List[0].Id; var response = PdfApi.PutSquareAnnotation(Name, annotationId, annotation, folder: TempFolder); Assert.That(response.Code, Is.EqualTo(200)); }
/** * 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); }
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); var page = doc.NewPage(); var g = page.Graphics; // User names for annotations' authors: var user1 = "Jaime Smith"; var user2 = "Jane Donahue"; TextFormat tf = new TextFormat() { Font = StandardFonts.Helvetica, FontSize = 10 }; var noteWidth = 72 * 4; var gap = 8; var rc = Common.Util.AddNote( "This sample demonstrates some types of annotations that can be created with GcPdf.\n" + "Note that some annotation types may not display in certain viewers (such as built-in browser viewers)." + "To see all annotations on this page, open it in Acrobat Reader or other full-featured PDF viewer.", page); // Text annotation: var ip = new PointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote( "A red text annotation is placed to the right of this note.", page, new RectangleF(ip.X, ip.Y, noteWidth, 100)); var textAnnot = new TextAnnotation() { UserName = user1, Contents = "This is annotation 1, a red one.", Rect = new RectangleF(rc.Right, rc.Top, 72 * 2, 72), Color = Color.Red, }; page.Annotations.Add(textAnnot); // A reply to previous annotation: var textAnnotReply = new TextAnnotation() { UserName = user2, Contents = "This is a reply to the first annotation.", Rect = new RectangleF(rc.Right, rc.Top, 72 * 2, 72), ReferenceAnnotation = textAnnot, ReferenceType = AnnotationReferenceType.Reply, }; page.Annotations.Add(textAnnotReply); // An initially open text annotation: ip = new PointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote( "A green text annotation that is initially open is placed to the right of this note.", page, new RectangleF(ip.X, ip.Y, noteWidth, 100)); var textAnnotOpen = new TextAnnotation() { Open = true, UserName = user1, Contents = "This is an initially open annotation (green).", Rect = new RectangleF(rc.Right, rc.Top, 72 * 2, 72), Color = Color.Green, }; page.Annotations.Add(textAnnotOpen); // A free text annotation (shows directly on page): ip = new PointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote( "A blue free text annotation is placed below and to the right, with a callout going from it to this note.", page, new RectangleF(ip.X, ip.Y, noteWidth, 100)); var freeAnnot = new FreeTextAnnotation() { Rect = new RectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72), CalloutLine = new PointF[] { new PointF(rc.Left + rc.Width / 2, rc.Bottom), new PointF(rc.Left + rc.Width / 2, rc.Bottom + 9 + 36), new PointF(rc.Right + 18, rc.Bottom + 9 + 36), }, LineWidth = 1, LineEndStyle = LineEndingStyle.OpenArrow, LineDashPattern = new float[] { 8, 4 }, Contents = "This is a free text annotation with a callout line going to the note on the left.", Color = Color.LightSkyBlue, }; page.Annotations.Add(freeAnnot); // Another free text annotation, with some rich text inside: ip = new PointF(rc.X, freeAnnot.Rect.Bottom + gap); var freeRichAnnot = new FreeTextAnnotation() { Rect = new RectangleF(ip.X - 144, ip.Y, 72 * 4, 72), LineWidth = 1, Color = Color.LightSalmon, RichText = "<body><p>This is another <i>free text annotation</i>, with <b><i>Rich Text</i></b> content.</p>" + "<p><br />Even though a <b>free text</b> annotation displays text directly on a page, " + "as other annotations it can be placed outside the page's bounds.</p></body>" }; page.Annotations.Add(freeRichAnnot); // A square annotatou around a note: ip = new PointF(rc.X, freeRichAnnot.Rect.Bottom + gap * 2); rc = Common.Util.AddNote( "A square annotation drawn with a 3pt wide orange line around this note has a rich text associated with it.", page, new RectangleF(ip.X, ip.Y, noteWidth, 100)); rc.Inflate(8, 8); var squareAnnot = new SquareAnnotation() { UserName = user2, Rect = rc, LineWidth = 3, Color = Color.Orange, RichText = "<body><p>This <b><i>rich text</i></b> is associated with the square annotation around a text note.</p></body>" }; page.Annotations.Add(squareAnnot); // Done: doc.Save(stream); }
private void parseAnnotations() { for (int i = 0; i < _array.Count; ++i) { PDFDictionary annotDict = _array[i] as PDFDictionary; if (annotDict != null) { if (annotDict["IRT"] == null) { PDFName subtype = annotDict["Subtype"] as PDFName; if (subtype != null) { Annotation annot = null; switch (subtype.GetValue()) { case "Text": annot = new TextAnnotation(annotDict, _owner); break; case "Link": annot = new LinkAnnotation(annotDict, _owner); break; case "FreeText": annot = new FreeTextAnnotation(annotDict, _owner); break; case "Line": annot = new LineAnnotation(annotDict, _owner); break; case "Square": annot = new SquareAnnotation(annotDict, _owner); break; case "Circle": annot = new CircleAnnotation(annotDict, _owner); break; case "Polygon": annot = new PolygonAnnotation(annotDict, _owner); break; case "PolyLine": annot = new PolylineAnnotation(annotDict, _owner); break; case "Highlight": annot = new HighlightAnnotation(annotDict, _owner); break; case "Underline": annot = new UnderlineAnnotation(annotDict, _owner); break; case "Squiggly": annot = new SquigglyAnnotation(annotDict, _owner); break; case "StrikeOut": annot = new StrikeOutAnnotation(annotDict, _owner); break; case "Stamp": annot = new RubberStampAnnotation(annotDict, _owner); break; case "Caret": annot = new CaretAnnotation(annotDict, _owner); break; case "Ink": annot = new InkAnnotation(annotDict, _owner); break; case "FileAttachment": annot = new FileAttachmentAnnotation(annotDict, _owner); break; case "Sound": annot = new SoundAnnotation(annotDict, _owner); break; case "Movie": annot = new MovieAnnotation(annotDict, _owner); break; case "Screen": annot = new ScreenAnnotation(annotDict, _owner); break; case "3D": annot = new ThreeDAnnotation(annotDict, _owner); break; case "Widget": PDFName ft = annotDict["FT"] as PDFName; if (ft == null) { PDFDictionary parent = annotDict["Parent"] as PDFDictionary; if (parent != null) { ft = parent["FT"] as PDFName; } } if (ft != null) { switch (ft.GetValue()) { case "Tx": annot = new EditBox(annotDict, _owner); break; case "Ch": uint flag = getFlag(annotDict); if ((flag >> 17) % 2 != 0) { annot = new ComboBox(annotDict, _owner); } else { annot = new ListBox(annotDict, _owner); } break; case "Btn": flag = getFlag(annotDict); if ((flag >> 16) % 2 != 0) { annot = new PushButton(annotDict, _owner); } else if ((flag >> 15) % 2 != 0) { annot = new RadioButton(annotDict, _owner); } else { annot = new CheckBox(annotDict, _owner); } break; } } break; } if (annot != null) { annot.SetPage(_page, false); _annotations.Add(annot); } } } } } }