本文整理汇总了C#中Shape.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.AppendChild方法的具体用法?C# Shape.AppendChild怎么用?C# Shape.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shape
的用法示例。
在下文中一共展示了Shape.AppendChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddImageToPage
/// <summary>
/// Adds an image to a page using the supplied paragraph.
/// </summary>
/// <param name="para">The paragraph to an an image to.</param>
/// <param name="page">The page number the paragraph appears on.</param>
public static void AddImageToPage(Paragraph para, int page)
{
Document doc = (Document)para.Document;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(para);
// Add a logo to the top left of the page. The image is placed infront of all other text.
Shape shape = builder.InsertImage(gDataDir + "Aspose Logo.png", RelativeHorizontalPosition.Page, 60,
RelativeVerticalPosition.Page, 60, -1, -1, WrapType.None);
// Add a textbox next to the image which contains some text consisting of the page number.
Shape textBox = new Shape(doc, ShapeType.TextBox);
// We want a floating shape relative to the page.
textBox.WrapType = WrapType.None;
textBox.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
textBox.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// Set the textbox position.
textBox.Height = 30;
textBox.Width = 200;
textBox.Left = 150;
textBox.Top = 80;
// Add the textbox and set text.
textBox.AppendChild(new Paragraph(doc));
builder.InsertNode(textBox);
builder.MoveTo(textBox.FirstChild);
builder.Writeln("This is a custom note for page " + page);
}
示例2: CreateTemplateDocumentForReportingEngine
/// <summary>
/// Create new document with textbox shape and some query
/// </summary>
internal static Document CreateTemplateDocumentForReportingEngine(string templateText)
{
Document doc = new Document();
//ToDo: Maybe in future add shape(object) as parameter
// Create textbox shape.
Shape textbox = new Shape(doc, ShapeType.TextBox);
textbox.Width = 431.5;
textbox.Height = 346.35;
Paragraph paragraph = new Paragraph(doc);
paragraph.AppendChild(new Run(doc, templateText));
// Insert paragraph into the textbox.
textbox.AppendChild(paragraph);
// Insert textbox into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(textbox);
return doc;
}
示例3: RenderNode
//ExStart
//ExId:RenderNode
//ExSummary:Shows how to render a node independent of the document by building on the functionality provided by ShapeRenderer class.
/// <summary>
/// Renders any node in a document to the path specified using the image save options.
/// </summary>
/// <param name="node">The node to render.</param>
/// <param name="path">The path to save the rendered image to.</param>
/// <param name="imageOptions">The image options to use during rendering. This can be null.</param>
public static void RenderNode(Node node, string filePath, ImageSaveOptions imageOptions)
{
// Run some argument checks.
if (node == null)
throw new ArgumentException("Node cannot be null");
// If no image options are supplied, create default options.
if (imageOptions == null)
imageOptions = new ImageSaveOptions(FileFormatUtil.ExtensionToSaveFormat(Path.GetExtension(filePath)));
// Store the paper color to be used on the final image and change to transparent.
// This will cause any content around the rendered node to be removed later on.
Color savePaperColor = imageOptions.PaperColor;
imageOptions.PaperColor = Color.Transparent;
// There a bug which affects the cache of a cloned node. To avoid this we instead clone the entire document including all nodes,
// find the matching node in the cloned document and render that instead.
Document doc = (Document)node.Document.Clone(true);
node = doc.GetChild(NodeType.Any, node.Document.GetChildNodes(NodeType.Any, true).IndexOf(node), true);
// Create a temporary shape to store the target node in. This shape will be rendered to retrieve
// the rendered content of the node.
Shape shape = new Shape(doc, ShapeType.TextBox);
Section parentSection = (Section)node.GetAncestor(NodeType.Section);
// Assume that the node cannot be larger than the page in size.
shape.Width = parentSection.PageSetup.PageWidth;
shape.Height = parentSection.PageSetup.PageHeight;
shape.FillColor = Color.Transparent; // We must make the shape and paper color transparent.
// Don't draw a surronding line on the shape.
shape.Stroked = false;
// Move up through the DOM until we find node which is suitable to insert into a Shape (a node with a parent can contain paragraph, tables the same as a shape).
// Each parent node is cloned on the way up so even a descendant node passed to this method can be rendered.
// Since we are working with the actual nodes of the document we need to clone the target node into the temporary shape.
Node currentNode = node;
while (!(currentNode.ParentNode is InlineStory || currentNode.ParentNode is Story || currentNode.ParentNode is ShapeBase))
{
CompositeNode parent = (CompositeNode)currentNode.ParentNode.Clone(false);
currentNode = currentNode.ParentNode;
parent.AppendChild(node.Clone(true));
node = parent; // Store this new node to be inserted into the shape.
}
// We must add the shape to the document tree to have it rendered.
shape.AppendChild(node.Clone(true));
parentSection.Body.FirstParagraph.AppendChild(shape);
// Render the shape to stream so we can take advantage of the effects of the ImageSaveOptions class.
// Retrieve the rendered image and remove the shape from the document.
MemoryStream stream = new MemoryStream();
shape.GetShapeRenderer().Save(stream, imageOptions);
shape.Remove();
// Load the image into a new bitmap.
using (Bitmap renderedImage = new Bitmap(stream))
{
// Extract the actual content of the image by cropping transparent space around
// the rendered shape.
Rectangle cropRectangle = FindBoundingBoxAroundNode(renderedImage);
Bitmap croppedImage = new Bitmap(cropRectangle.Width, cropRectangle.Height);
croppedImage.SetResolution(imageOptions.Resolution, imageOptions.Resolution);
// Create the final image with the proper background color.
using (Graphics g = Graphics.FromImage(croppedImage))
{
g.Clear(savePaperColor);
g.DrawImage(renderedImage, new Rectangle(0, 0, croppedImage.Width, croppedImage.Height), cropRectangle.X, cropRectangle.Y, cropRectangle.Width, cropRectangle.Height, GraphicsUnit.Pixel);
croppedImage.Save(filePath);
}
}
}
示例4: CreateTemplateDocumentWithDrawObjects
/// <summary>
/// Create new document with textbox shape and some query
/// </summary>
internal static Document CreateTemplateDocumentWithDrawObjects(string templateText, ShapeType shapeType)
{
Document doc = new Document();
// Create textbox shape.
Shape shape = new Shape(doc, shapeType);
shape.Width = 431.5;
shape.Height = 346.35;
Paragraph paragraph = new Paragraph(doc);
paragraph.AppendChild(new Run(doc, templateText));
// Insert paragraph into the textbox.
shape.AppendChild(paragraph);
// Insert textbox into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(shape);
return doc;
}
示例5: CreateTextBox
public void CreateTextBox()
{
//ExStart
//ExFor:Shape.#ctor(DocumentBase, ShapeType)
//ExFor:ShapeBase.ZOrder
//ExFor:Story.FirstParagraph
//ExFor:Shape.FirstParagraph
//ExFor:ShapeBase.WrapType
//ExSummary:Creates a textbox with some text and different formatting options in a new document.
// Create a blank document.
Document doc = new Document();
// Create a new shape of type TextBox
Shape textBox = new Shape(doc, ShapeType.TextBox);
// Set some settings of the textbox itself.
// Set the wrap of the textbox to inline
textBox.WrapType = WrapType.None;
// Set the horizontal and vertical alignment of the text inside the shape.
textBox.HorizontalAlignment = HorizontalAlignment.Center;
textBox.VerticalAlignment = VerticalAlignment.Top;
// Set the textbox height and width.
textBox.Height = 50;
textBox.Width = 200;
// Set the textbox in front of other shapes with a lower ZOrder
textBox.ZOrder = 2;
// Let's create a new paragraph for the textbox manually and align it in the center. Make sure we add the new nodes to the textbox as well.
textBox.AppendChild(new Paragraph(doc));
Paragraph para = textBox.FirstParagraph;
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// Add some text to the paragraph.
Run run = new Run(doc);
run.Text = "Content in textbox";
para.AppendChild(run);
// Append the textbox to the first paragraph in the body.
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
// Save the output
doc.Save(MyDir + @"\Artifacts\Shape.CreateTextBox.doc");
//ExEnd
}
示例6: GetShapeAltTextTitle
public void GetShapeAltTextTitle()
{
//ExStart
//ExFor:Shape.Title
//ExSummary:Shows how to get or set alt text title for shape object
Document doc = new Document();
// Create textbox shape.
Shape shape = new Shape(doc, ShapeType.Cube);
shape.Width = 431.5;
shape.Height = 346.35;
shape.Title = "Alt Text Title";
Paragraph paragraph = new Paragraph(doc);
paragraph.AppendChild(new Run(doc, "Test"));
// Insert paragraph into the textbox.
shape.AppendChild(paragraph);
// Insert textbox into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(shape);
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Docx);
Node[] shapes = doc.GetChildNodes(NodeType.Shape, true).ToArray();
shape = (Shape)shapes[0];
Assert.AreEqual("Alt Text Title", shape.Title);
//ExEnd
}