Using Digital Ink in PowerPoint .NET - c#

I was wondering how PowerPoint slides can be automatically annotated using digital ink in .NET (using c#). Currently, I'm doing the same thing using free-form shapes, which is straightforward but has some issues. When selecting Office.MsoEditingType.msoEditingAuto as an editing type, the free-forms are smooth, but when constructing them and then converting into a shape (when consisting of more than a couple of points) takes a very long time (the following method would take ca 5s!)
PowerPoint.Shape Shape = builder.ConvertToShape();
When using Office.MsoEditingType.msoEditingCorner, the shape is generated much quicker, but the resulting shapes are jagged (surprise!).
I found the following code sample for doing the same using digital ink:
DrawingAttributes drawingAttributes1 = new DrawingAttributes();
drawingAttributes1.Color = Colors.Green;
StylusPoint stylusPoint1 = new StylusPoint(100, 100);
StylusPoint stylusPoint2 = new StylusPoint(100, 200);
StylusPoint stylusPoint3 = new StylusPoint(200, 200);
StylusPoint stylusPoint4 = new StylusPoint(200, 100);
StylusPoint stylusPoint5 = new StylusPoint(100, 100);
StylusPointCollection points = new StylusPointCollection(
new StylusPoint[] { stylusPoint1, stylusPoint2, stylusPoint3,
stylusPoint4, stylusPoint5 });
Stroke newStroke = new Stroke(points, drawingAttributes1);
InkPresenter inkPres = new InkPresenter();
inkPres.Strokes.Add(newStroke);
However, not being a PowerPoint Add-in expert (hardly even a beginner, actually), I don't know how to attach the inkpresenter to the current slide. Ideally, a new inkpresenter would be created & kept per slide (so I don't have to worry about re-drawing on each slide navigation)
I understood it's possible to create an ink canvas using the designer, and then drawing on that, but would that canvas then be attached to the entire presentation or just the current slide? And would it allow users to draw on the canvas (which is not the goal; drawing would be done automatically)?
I spent quite some time looking for relevant code samples, but none of them seemed to do what I am intending. For instance, as mentioned, I'm not planning to allow users to draw on the slide, but automatically annotating the slide.
Thanks,
William

Related

Graphics not displaying in esri scene

I am trying to build an AR app for navigation, and i am trying to modify the app for rest points, so I decided to add 3d graphics overlay in esri maps while building the app in visual studio, but the problem is I can see a 2d point but when I try to implement a 3d point on a scene it doesn't show up in the map or scene , i tried creating the app in windows, android and iOS but there was no solution and i kept on trying adding layers they are working fine, but every time I am using simple marker scene symbol it's not working at all, not even basic points are reflecting in the map/scene
So this is the developer documentation tutorial on how to create a graphic on a scene:
https://developers.arcgis.com/net/scenes-3d/add-graphics-to-a-scene-view/
This is my code that I have written exactly to avoid any mistakes in generation of graphics:
var go = new GraphicsOverlay();
var pierPoint = new MapPoint(xx.xxxx, xx. xxxxxx,SpatialReferences.Wgs84);
// Create a new symbol for the graphic.
var redSphereSymbol = new SimpleMarkerSceneSymbol(SimpleMarkerSceneSymbolStyle.Sphere,
System.Drawing.Color.Red,
500, 500, 500,
SceneSymbolAnchorPosition.Center);
// Create a new graphic.
var santaMonicaPierGraphic = new Graphic(pierPoint, redSphereSymbol);
// Add attribute values (if needed).
santaMonicaPierGraphic.Attributes.Add("Name", "Santa Monica Pier");
santaMonicaPierGraphic.Attributes.Add("type", "pier");
// Add the graphic to the graphics overlay's graphics collection.
go.Graphics.Add(santaMonicaPierGraphic);
// Add the graphic overlay to the geo view's graphics overlay collection.
arSceneView.GraphicsOverlays.Add(go);
arSceneView.Scene = scene;
arSceneView.Scene = scene;
The arSceneView is the sceneview class
the xx.xxxxx is the latitude/longitude for the reference point

SVG rendering in C# with SVG library always fills shapes with black

I'm using the Svg.Core library (version 3.0.49.2) to render SVGs (defined in strings) to PNG images. No matter what I do, any shape seems to be rendered with a black stroke and a black fill.
Here's the code I'm using for a simple rectangle, as an example:
var svgString = #"<svg width=""300"" height=""300"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink""><rect x=""5"" y=""5"" height=""90"" width=""50"" fill=""#ef0000"" stroke=""#00ef00"" /></svg>";
var svgDocument = SvgDocument.FromSvg<SvgDocument>(svgString);
var bitmap = svgDocument.Draw();
bitmap.Save(fileName, ImageFormat.Png);
which ends up rendering a rectangle of the correct height and width, but all black:
I've seen a number of posts that mention various versions of inlining styles, but regardless of whether I'm using a style="" approach or a fill="", the problem continues. Also seems to happen without fill color specified or using standard color names instead of RGB values.
Any help or ideas are appreciated!
The best answer I have come up with here is from the comment earlier. If you put the following around it: svgDoc.Color = new SvgColourServer(Color.DarkGreen); svgDoc.StopColor = new SvgColourServer(Color.DarkGreen); svgDoc.Stroke = new SvgColourServer(Color.DarkGreen); svgDoc.Fill = new SvgColourServer(Color.DarkGreen); , you will get colors in the SVG. Posting this as the answer in case anyone runs into this issue down the road.

WPF to XPS Very Slow

Hello We are trying to create a custom template system based such as WPF Header and Footer elements, with a canvas for 2D Drawings for export to PDF. The problem is the XpsWriter takes about 7 seconds to write the XPS Document, and another 3 Seconds to convert to pdf with PDFSharp. We need to get this down as the user waits for the PDF. I first suspected its due to the number of FrameworkElements in the, but there are only 5000. The framework elements are mostly PATH data with fills, strokes, and brushes.
Canvas ComplexCanvas = new Canvas();
ComplexCanvas.Children.Add(5000Elements);
System.Windows.Documents.FixedDocument fixedDoc = new System.Windows.Documents.FixedDocument();
System.Windows.Documents.PageContent pageContent = new System.Windows.Documents.PageContent();
System.Windows.Documents.FixedPage fixedPage = new System.Windows.Documents.FixedPage();
//Create first page of document
fixedPage.Children.Add(ComplexCanvas);
fixedPage.Width = PageWidth;
fixedPage.Height = PageHeight;
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
System.Windows.Xps.Packaging.XpsDocument xpsd = new XpsDocument(Path, System.IO.FileAccess.Write);
System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(fixedDoc);
xpsd.Close();
Does anyone know a way to speed this up? Perhaps some type Visual Object, or "Flatten" the Canvas somehow or any ideas. When it does work the PDF is over 5MB.
Would like to keep it VECTOR as much as possible
There are several ways to speed up the conversion from WPF to XPS to PDF:-
Freeze any pens or brushes as this will speed up rendering:-
SolidColorBrush brush = new SolidColorBrush(Colors.PaleGreen);
brush.Opacity = .25d;
brush.Freeze();
Pen paleGreenPen = new Pen(brush, 1);
paleGreenPen.Freeze();
Pen linePen = new Pen(Brushes.Red, 1);
linePen.Freeze();
Render in the background (create a background UI thread).
Do not save the interim XPS document to disk but use a MemoryStream.

Adding Point Objects To ZedGraph

A nice extension exists for ZedGraph to plot markers/points (PointObj.cs). However, I am having trouble rendering the point on the graph.
When I call the ZedGraph.Invalidate() function, the marker is drawn momentarily but then disappears.
In the following code, the variable zedGraph is the visible graph object on the form UI.
// Create point
ZedGraph.PointObj point = new ZedGraph.PointObj(5, 10000, 50, 50, ZedGraph.SymbolType.Square, Color.Green);
ZedGraph.PaneBase paneBase = zedGraph.GraphPane;
point.Fill = new ZedGraph.Fill(Color.Green);
System.Drawing.Graphics graphics = zedGraph.CreateGraphics();
// Draw point to graph
point.Draw(graphics, paneBase, paneBase.CalcScaleFactor());
// Re-draw graph, but point only flashes momentarily.
zedGraph.Invalidate();
EDIT: I realise there are other ways of adding "points", such as described here (Labelling and circle a specific point in zedgraph). But it would be still good to know why this doesn't work.
Try adding the point to the GraphObjList after creation
zedGraph.GraphPane.GraphObjList.Add(point);

Using OutlineTextControl

I am using the OutlineTextControl that I found linked here somewhere and its great, however the outline gets drawn on the text instead of outside the text (like an outline). Is there any way to modify the class to do what I need?
Link to control code:
http://blogs.msdn.com/b/wpfsdk/archive/2006/12/24/using-text-as-a-decorative-graphic.aspx
Maybe there is an alternative way to do sharp outlines on text?
**Edit
I modified the class to draw the outline separately as below, and created a private variable in the class to hold my formatted text. This works almost perfect, the N letter has a little sharp point above it, and the W has a sharp point below as shown in my image, what would cause this?
drawingContext.DrawGeometry(null, new Pen(Stroker, StrokeThickness), _textGeometry);
drawingContext.DrawText(_formattedText, new Point(0, 0));
****Edit 2
Added the following code above the drawing code to define my stroke pen:
Pen pop = new Pen(Stroker, StrokeThickness);
pop.LineJoin = PenLineJoin.Round;
pop.MiterLimit = 10;
Now my outline is smooth and exactly what I wanted:
Added the following code above the drawing code to define my stroke pen:
Pen pop = new Pen(Stroker, StrokeThickness);
pop.LineJoin = PenLineJoin.Round;
pop.MiterLimit = 10;
Now my outline is smooth and exactly what I wanted:

Categories

Resources