public ForceTotalsRow(Page page, Shape forceTotalsShape) : base(page, false) { Shape = forceTotalsShape; UsedSizingPolicy |= SizingPolicy.ShrinkYIfNeeded | SizingPolicy.ExpandXIfNeeded; LayoutManager = new InlineLayout(this); MarginBottom = 0.4; Array ident = forceTotalsShape.ContainerProperties.GetMemberShapes((int)VisContainerFlags.visContainerFlagsExcludeNested); List <Shape> shapes = new List <int>((int[])ident).Select(i => page.Shapes.ItemFromID[i]).ToList(); if (Children.Count == 0) { foreach (Shape shape in shapes) { if (ForceTotalComponent.IsForceTotalComponent(shape.Name)) { Children.Add(new ForceTotalComponent(page, shape)); } else if (shape.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists) { VisioShape toAdd = new VisioShape(page) { Shape = shape }; Children.Add(toAdd); } } } }
/// <summary> /// Find Text and replace it with a Picture using ContentRange. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/find-replace-content-net-csharp-vb.php /// </remarks> public static void FindTextAndReplaceImage() { // Path to a loadable document. string loadPath = @"..\..\Critique_signature.docx"; string pictPath = @"..\..\Smile.png"; // Load a document intoDocumentCore. DocumentCore dc = DocumentCore.Load(loadPath); //Find "<signature>" Text and Replace everywhere with the "Smile.png" // Please note, Reverse() makes sure that action replace not affects to Find(). Regex regex = new Regex(@"<signature>", RegexOptions.IgnoreCase); Picture picture = new Picture(dc, InlineLayout.Inline(new Size(50, 50)), pictPath); foreach (ContentRange item in dc.Content.Find(regex).Reverse()) { item.Replace(picture.Content); } // Save our document into PDF format. string savePath = @"..\..\Replaced_signature.pdf"; dc.Save(savePath, new PdfSaveOptions()); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(loadPath) { UseShellExecute = true }); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true }); }
private void InitStyle() { UsedSizingPolicy |= SizingPolicy.ExpandXIfNeeded | SizingPolicy.ShrinkYIfNeeded; if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing) { Shape.ContainerProperties.ResizeAsNeeded = 0; ContainerPadding = 0; } LayoutManager = new InlineLayout(this); }
/// <summary> /// Inserting a Rich text content control. /// </summary> /// <remarks> /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/content-controls-insert-rich-text-net-csharp-vb.php /// </remarks> static void InsertRichText() { // Let's create a simple document. DocumentCore dc = new DocumentCore(); // Create a rich text content control. BlockContentControl rt = new BlockContentControl(dc, ContentControlType.RichText); dc.Sections.Add(new Section(dc, rt)); // Add the content control properties. rt.Properties.Title = "Rich text content control."; rt.Properties.Color = Color.Blue; rt.Properties.LockDeleting = true; rt.Properties.LockEditing = true; rt.Document.DefaultCharacterFormat.FontColor = Color.Orange; // Add new paragraphs with formatted text. rt.Blocks.Add(new Paragraph(dc, "Line 1")); rt.Blocks.Add(new Paragraph(dc, "Line 2")); rt.Blocks.Add(new Paragraph(dc, "Line 3")); // Add a picture and shape to the block. string pictPath = @"..\..\banner_sautinsoft.jpg"; Picture pict = new Picture(dc, InlineLayout.Inline(new Size(400, 100)), pictPath); Shape shp = new Shape(dc, Layout.Inline(new Size(4, 1, LengthUnit.Centimeter))); Paragraph im = new Paragraph(dc); rt.Blocks.Add(im); im.Inlines.Add(pict); Paragraph sh = new Paragraph(dc); rt.Blocks.Add(sh); sh.Inlines.Add(shp); rt.Blocks.Add(new Paragraph(dc, "Line 4")); // Save our document into DOCX format. string resultPath = @"result.docx"; dc.Save(resultPath, new DocxSaveOptions()); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true }); }
public ForceContainer(Page page, Shape forceContainer) : base(page, false) { Shape = forceContainer; Array ident = forceContainer.ContainerProperties.GetMemberShapes((int)VisContainerFlags.visContainerFlagsExcludeNested); List <Shape> shapes = new List <int>((int[])ident).Select(i => page.Shapes.ItemFromID[i]).ToList(); string concern = null; string description = null; Dictionary <int, string> forceValuesDictionary = new Dictionary <int, string>(); if (Children.Count == 0) { foreach (Shape shape in shapes) { if (ForceConcernComponent.IsForceConcern(shape.Name)) { Children.Add(new ForceConcernComponent(page, shape)); concern = shape.Text; } else if (ForceDescriptionComponent.IsForceDescription(shape.Name)) { Children.Add(new ForceDescriptionComponent(page, shape)); description = shape.Text; } else if (ForceValueComponent.IsForceValue(shape.Name)) { ForceValueComponent comp = new ForceValueComponent(page, shape); Children.Add(comp); forceValuesDictionary.Add(comp.ForceAlternativeId, comp.Text); } } if ((concern != null) && (description != null)) { Force correspondingForce = new Force(concern, description, forceValuesDictionary, Id); if (Index <= Globals.RationallyAddIn.Model.Forces.Count) { Globals.RationallyAddIn.Model.Forces.Insert(Index, correspondingForce); } else { Globals.RationallyAddIn.Model.Forces.Add(correspondingForce); } } } UsedSizingPolicy |= SizingPolicy.ExpandXIfNeeded | SizingPolicy.ShrinkYIfNeeded; LayoutManager = new InlineLayout(this); }
/// <summary> /// How to add pictures into a document. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-pictures.php /// </remarks> public static void AddPictures() { string documentPath = @"Pictures.docx"; string pictPath = @"..\..\image1.jpg"; // Let's create a simple document. DocumentCore dc = new DocumentCore(); // Add a new section. Section s = new Section(dc); dc.Sections.Add(s); // 1. Picture with InlineLayout: // Create a new paragraph with picture. Paragraph par = new Paragraph(dc); s.Blocks.Add(par); par.ParagraphFormat.Alignment = HorizontalAlignment.Left; // Add some text content. par.Content.End.Insert("Shrek and Donkey ", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black }); // Our picture has InlineLayout - it doesn't have positioning by coordinates // and located as flowing content together with text (Run and other Inline elements). Picture pict1 = new Picture(dc, InlineLayout.Inline(new Size(100, 100)), pictPath); // Add picture to the paragraph. par.Inlines.Add(pict1); // Add some text content. par.Content.End.Insert(" arrive at Farquaad's palace in Duloc, where they end up in a tournament.", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black }); // 2. Picture with FloatingLayout: // Floating layout means that the Picture (or Shape) is positioned by coordinates. Picture pict2 = new Picture(dc, pictPath); pict2.Layout = FloatingLayout.Floating( new HorizontalPosition(50, LengthUnit.Millimeter, HorizontalPositionAnchor.Page), new VerticalPosition(70, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), new Size(LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point), LengthUnitConverter.Convert(10, LengthUnit.Centimeter, LengthUnit.Point)) ); // Set the wrapping style. (pict2.Layout as FloatingLayout).WrappingStyle = WrappingStyle.Square; // Add our picture into the section. s.Content.End.Insert(pict2.Content); // Save our document into DOCX format. dc.Save(documentPath, new DocxSaveOptions()); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true }); }