page 233

In our tutorials, there are articles introducing the method to insert, remove, position text box and extract text from text box. This article is going to give the documentation of how to set the internal margin for textbox with the position and line style settings included using Spire.Doc.

Note: before start, please download the latest version of Spire.Doc and add the .dll in the bin folder as the reference of Visual Studio.

Step 1: Create a Word document and add a section.

Document document = new Document();
Section sec = document.AddSection();

Step 2: Add a text box and append sample text.

TextBox TB = document.Sections[0].AddParagraph().AppendTextBox(310, 90);
Paragraph para = TB.Body.AddParagraph();
TextRange TR = para.AppendText("Using Spire.Doc, developers will find a simple and effective method to endow their applications with rich MS Word features. ");
TR.CharacterFormat.FontName = "Cambria ";
TR.CharacterFormat.FontSize = 13;

Step 3: Set exact position for the text box.

TB.Format.HorizontalOrigin = HorizontalOrigin.Page;
TB.Format.HorizontalPosition = 80;
TB.Format.VerticalOrigin = VerticalOrigin.Page;
TB.Format.VerticalPosition = 100;

Step 4: Set line style for the text box.

TB.Format.LineStyle = TextBoxLineStyle.Double;
TB.Format.LineColor = Color.CornflowerBlue;
TB.Format.LineDashing = LineDashing.DashDotDot;
TB.Format.LineWidth = 5;

Step 5: Set internal margin for the text box:

TB.Format.InternalMargin.Top = 15;
TB.Format.InternalMargin.Bottom = 10;
TB.Format.InternalMargin.Left = 12;
TB.Format.InternalMargin.Right = 10;

Step 6: Save the document and launch to see effects.

document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");

Effects:

How to set internal margin for Word text box in C#

Full Codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {

            Document document = new Document();
            Section sec = document.AddSection();

            TextBox TB = document.Sections[0].AddParagraph().AppendTextBox(310, 90);
            Paragraph para = TB.Body.AddParagraph();
            TextRange TR = para.AppendText("Using Spire.Doc, developers will find a simple and effective method to endow their applications with rich MS Word features. ");
            TR.CharacterFormat.FontName = "Cambria ";
            TR.CharacterFormat.FontSize = 13;

            TB.Format.HorizontalOrigin = HorizontalOrigin.Page;
            TB.Format.HorizontalPosition = 80;
            TB.Format.VerticalOrigin = VerticalOrigin.Page;
            TB.Format.VerticalPosition = 100;

            TB.Format.LineStyle = TextBoxLineStyle.Double;
            TB.Format.LineColor = Color.CornflowerBlue;
            TB.Format.LineDashing = LineDashing.DashDotDot;
            TB.Format.LineWidth = 5;

            TB.Format.InternalMargin.Top = 15;
            TB.Format.InternalMargin.Bottom = 10;
            TB.Format.InternalMargin.Left = 12;
            TB.Format.InternalMargin.Right = 10;

            document.SaveToFile("result.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}

Format axis for Excel chart in C#

2015-09-23 07:41:46 Written by Koohji

By default, Excel sets the axis properties automatically for charts. These properties include axis options like maximum & minimum value, major & minor unit, major & minor tick mark type, axis labels position, axis across value and whether values in reverse order. Sometimes we need to set those properties manually to beautify and perfect the charts. This article is going to introduce the method to customize axis setting for Excel chart in C# using Spire.XLS.

Note: before start, please download the latest version of Spire.XLS and add the .dll in the bin folder as the reference of Visual Studio.

Step 1: Create a workbook and add a sheet filled with some sample data.

            Workbook workbook = new Workbook();
            workbook.CreateEmptySheets(1);
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Demo";
            sheet.Range["A1"].Value = "Month";
            sheet.Range["A2"].Value = "Jan";
            sheet.Range["A3"].Value = "Feb";
            sheet.Range["A4"].Value = "Mar";
            sheet.Range["A5"].Value = "Apr";
            sheet.Range["A6"].Value = "May";
            sheet.Range["A7"].Value = "Jun";
            sheet.Range["A8"].Value = "Jul";
            sheet.Range["A9"].Value = "Aug";
            sheet.Range["B1"].Value = "Planned";
            sheet.Range["B2"].NumberValue = 38;
            sheet.Range["B3"].NumberValue = 47;
            sheet.Range["B4"].NumberValue = 39;
            sheet.Range["B5"].NumberValue = 36;
            sheet.Range["B6"].NumberValue = 27;
            sheet.Range["B7"].NumberValue = 25;
            sheet.Range["B8"].NumberValue = 36;
            sheet.Range["B9"].NumberValue = 48;

Step 2: Create a column clustered chart based on the sample data.

            Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = sheet.Range["B1:B9"];
            chart.SeriesDataFromRange = false;
            chart.PlotArea.Visible = false;
            chart.TopRow = 6;
            chart.BottomRow = 25;
            chart.LeftColumn = 2;
            chart.RightColumn = 9;
            chart.ChartTitle = "Chart with Customized Axis";
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 12;
            Spire.Xls.Charts.ChartSerie cs1 = chart.Series[0];      
            cs1.CategoryLabels = sheet.Range["A2:A9"];

Step 3: Set the customized axis properties for the chart.

            chart.PrimaryValueAxis.MajorUnit = 8;
            chart.PrimaryValueAxis.MinorUnit = 2;
            chart.PrimaryValueAxis.MaxValue = 50;
            chart.PrimaryValueAxis.MinValue = 0;
            chart.PrimaryValueAxis.IsReverseOrder = false;
            chart.PrimaryValueAxis.MajorTickMark = TickMarkType.TickMarkOutside;
            chart.PrimaryValueAxis.MinorTickMark = TickMarkType.TickMarkInside;
            chart.PrimaryValueAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionNextToAxis;
            chart.PrimaryValueAxis.CrossesAt = 0;

Step 4: Save the document and launch to see effects.

            workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Result.xlsx");

Effects:

How to format axis for Excel chart in C#

Full codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
using System.Drawing;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.CreateEmptySheets(1);
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Demo";
            sheet.Range["A1"].Value = "Month";
            sheet.Range["A2"].Value = "Jan";
            sheet.Range["A3"].Value = "Feb";
            sheet.Range["A4"].Value = "Mar";
            sheet.Range["A5"].Value = "Apr";
            sheet.Range["A6"].Value = "May";
            sheet.Range["A7"].Value = "Jun";
            sheet.Range["A8"].Value = "Jul";
            sheet.Range["A9"].Value = "Aug";
            sheet.Range["B1"].Value = "Planned";
            sheet.Range["B2"].NumberValue = 38;
            sheet.Range["B3"].NumberValue = 47;
            sheet.Range["B4"].NumberValue = 39;
            sheet.Range["B5"].NumberValue = 36;
            sheet.Range["B6"].NumberValue = 27;
            sheet.Range["B7"].NumberValue = 25;
            sheet.Range["B8"].NumberValue = 36;
            sheet.Range["B9"].NumberValue = 48;
          
            Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = sheet.Range["B1:B9"];
            chart.SeriesDataFromRange = false;
            chart.PlotArea.Visible = false;
            chart.TopRow = 6;
            chart.BottomRow = 25;
            chart.LeftColumn = 2;
            chart.RightColumn = 9;
            chart.ChartTitle = "Chart with Customized Axis";
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 12;
            Spire.Xls.Charts.ChartSerie cs1 = chart.Series[0];      
            cs1.CategoryLabels = sheet.Range["A2:A9"];

            chart.PrimaryValueAxis.MajorUnit = 8;
            chart.PrimaryValueAxis.MinorUnit = 2;
            chart.PrimaryValueAxis.MaxValue = 50;
            chart.PrimaryValueAxis.MinValue = 0;
            chart.PrimaryValueAxis.IsReverseOrder = false;
            chart.PrimaryValueAxis.MajorTickMark = TickMarkType.TickMarkOutside;
            chart.PrimaryValueAxis.MinorTickMark = TickMarkType.TickMarkInside;
            chart.PrimaryValueAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionNextToAxis;
            chart.PrimaryValueAxis.CrossesAt = 0;

            workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Result.xlsx");
        }
    }
}

Universal 3D (U3D) is a compressed file format for 3D computer graphic data. 3D modules in U3D format can be inserted into PDF documents and interactively visualized by Acrobat Reader. This article presents how to embed a pre-created U3D file into a PDF document using Spire.PDF in C#, VB.NET.

Main Steps:

Step 1: Initialize a new object of PdfDocuemnt, and add a blank page to the PDF document.

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Step 2: Draw a rectangle on the page to define the canvas area for the 3D file.

Rectangle rt = new Rectangle(0, 80, 200, 200);

Step 3: Initialize a new object of Pdf3DAnnotation, load the .u3d file as 3D annotation.

Pdf3DAnnotation annotation = new Pdf3DAnnotation(rt, "teapot.u3d");
annotation.Activation = new Pdf3DActivation();
annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen;

Step 4: Define a 3D view mode.

Pdf3DView View= new Pdf3DView();
View.Background = new Pdf3DBackground(new PdfRGBColor(Color.Purple
));
View.ViewNodeName = "test";
View.RenderMode = new Pdf3DRendermode(Pdf3DRenderStyle.Solid);
View.InternalName = "test";
View.LightingScheme = new Pdf3DLighting();
View.LightingScheme.Style = Pdf3DLightingStyle.Day;

Step 5: Set the 3D view mode for the annotation.

annotation.Views.Add(View);

Step 6: Add the annotation to PDF.

page.Annotations.Add(annotation);

Step 7: Save the file.

doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF);

Output:

How to Embed 3D Interactive Graphics into PDF Document in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Annotations;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace Embed3DInteractiveGraphics
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            Rectangle rt = new Rectangle(0, 80, 200, 200); 
            Pdf3DAnnotation annotation = new Pdf3DAnnotation(rt, "teapot.u3d");
            annotation.Activation = new Pdf3DActivation();
            annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen; 
            Pdf3DView View= new Pdf3DView();
            View.Background = new Pdf3DBackground(new PdfRGBColor(Color.Purple));
            View.ViewNodeName = "test";
            View.RenderMode = new Pdf3DRendermode(Pdf3DRenderStyle.Solid);
            View.InternalName = "test";
            View.LightingScheme = new Pdf3DLighting();
            View.LightingScheme.Style = Pdf3DLightingStyle.Day;
            annotation.Views.Add(View);

            page.Annotations.Add(annotation);
            doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Annotations
Imports Spire.Pdf.Graphics
Imports System.Drawing

Namespace Embed3DInteractiveGraphics
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			Dim page As PdfPageBase = doc.Pages.Add()

			Dim rt As New Rectangle(0, 80, 200, 200)
			Dim annotation As New Pdf3DAnnotation(rt, "teapot.u3d")
			annotation.Activation = New Pdf3DActivation()
			annotation.Activation.ActivationMode = Pdf3DActivationMode.PageOpen
			Dim View As New Pdf3DView()
			View.Background = New Pdf3DBackground(New PdfRGBColor(Color.Purple))
			View.ViewNodeName = "test"
			View.RenderMode = New Pdf3DRendermode(Pdf3DRenderStyle.Solid)
			View.InternalName = "test"
			View.LightingScheme = New Pdf3DLighting()
			View.LightingScheme.Style = Pdf3DLightingStyle.Day
			annotation.Views.Add(View)

			page.AnnotationsWidget.Add(annotation)
			doc.SaveToFile("Create3DPdf.pdf", FileFormat.PDF)
		End Sub
	End Class
End Namespace
page 233