Spire.Doc for .NET

To emphasize and beautify a set of characters or sentence, applying a border around the characters or sentence is a good option. Spire.Doc enables developers to achieve this feature in C#. And there are plenty of built-in border styles available, such as: Wave, Hairline, DotDash, DashSmallGap, DashLargeGap, DoubleWave, DashDotStroker, Emboss3D, Engrave3D, TwistedLines1 and so on. The following codes show how to achieve character border with some border styles mentioned above:

Note: Before start, please make sure that Visual Studio and Spire.Doc have been installed properly. We will use Spire.Doc .dll as reference.

Step 1: Load word document

Document doc = new Document();
Section section = doc.AddSection();

Step 2: Add the characters needed to apply a border and set the border style

//DashSmallGap Border
Paragraph para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange tr = para.AppendText("Spire.Doc for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
tr.CharacterFormat.Border.Color = Color.Green;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.DarkKhaki; 
para.AppendBreak(BreakType.LineBreak);

//Wave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.PDF for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
tr.CharacterFormat.Border.Color = Color.Aqua;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.BurlyWood;
para.AppendBreak(BreakType.LineBreak);

//Emboss3D Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.XLS for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
tr.CharacterFormat.FontSize = 24;
para.AppendBreak(BreakType.LineBreak);

//DashDotStroker Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Office for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
tr.CharacterFormat.Border.Color = Color.Olive;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Olive;
para.AppendBreak(BreakType.LineBreak);

//DoubleWave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Presentation for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
tr.CharacterFormat.Border.Color = Color.Blue;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Blue;
para.AppendBreak(BreakType.LineBreak);

Step 3: Save and launch word document

doc.SaveToFile("S1.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("S1.docx");

Effect of screenshot:

How to apply a border around characters or sentence in word document

Full Code:

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 ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            Section section = doc.AddSection();

            //DashSmallGap Border
            Paragraph para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            TextRange tr = para.AppendText("Spire.Doc for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
            tr.CharacterFormat.Border.Color = Color.Green;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.DarkKhaki; 
            para.AppendBreak(BreakType.LineBreak);

            //Wave Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.PDF for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
            tr.CharacterFormat.Border.Color = Color.Aqua;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.BurlyWood;
            para.AppendBreak(BreakType.LineBreak);

            //Emboss3D Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.XLS for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
            tr.CharacterFormat.FontSize = 24;
            para.AppendBreak(BreakType.LineBreak);

            //DashDotStroker Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.Office for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
            tr.CharacterFormat.Border.Color = Color.Olive;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.Olive;
            para.AppendBreak(BreakType.LineBreak);

            //DoubleWave Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.Presentation for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
            tr.CharacterFormat.Border.Color = Color.Blue;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.Blue;
            para.AppendBreak(BreakType.LineBreak);

            doc.SaveToFile("S1.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("S1.docx");

        }
    }
}

Sometimes in word files, we type another language rather than default, and need spellers and other proofing tools adjust to the language we typed.

This article is talking about how to alter language dictionary as non-default language via Spire.Doc. Here take English as default language and alter to Spanish in Peru as an example.

As for more language information, refer this Link to Microsoft Locale ID Values.

Here are the steps:

Step 1: Create a new word document.

Document document = new Document();

Step 2: Add new section and paragraph to the document.

Section sec = document.AddSection();
Paragraph para = sec.AddParagraph();

Step 3: Add a textRange for the paragraph and append some Peru Spanish words.

TextRange txtRange = para.AppendText("corrige según diccionario en inglés");
txtRange.CharacterFormat.LocaleIdASCII = 10250;

Step 4: Save and review.

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

Here is the result screenshot.

How to alter Language dictionary via Spire.Doc

Full Code:

using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace AlterLang
{

    class Program
    {

        static void Main(string[] args)
        {
            Document document = new Document();
            Section sec = document.AddSection();
            Paragraph para = sec.AddParagraph();
            TextRange txtRange = para.AppendText("corrige según diccionario en inglés");
            txtRange.CharacterFormat.LocaleIdASCII = 10250;
            document.SaveToFile("result.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}

Spire.Doc has a powerful ability to operate RTF file formats in C# and VB.NET. By using Spire.Doc, developers can convert RTF to PDF, HTML and word documents in .doc, .docx. This article will show you how to convert RTF into image and then reset the image resolution.

Download and install Spire.Doc for .NET and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to convert RTF into PNG and reset image resolution in C#.

Step 1: Create a new document and load from file.

Document doc = new Document();
doc.LoadFromFile("sample.rtf", FileFormat.Rtf);

Step 2: Save the RTF to image

Image[] images = doc.SaveToImages(Spire.Doc.Documents.ImageType.Metafile);

Step 3: Traverse the elements in the list of images and save them into .Png format.

for (int i = 0; i < images.Length; i++)
{
    Metafile mf = images[i] as Metafile;
    Image newimage = ResetResolution(mf, 200);
    string outputfile = String.Format("image-{0}.png", i);
    newimage.Save(outputfile, System.Drawing.Imaging.ImageFormat.Png);
}

Step 4: Set the image resolution call the method: ResetResolution.

public static Image ResetResolution(Metafile mf, float resolution)
{
    int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
    int height = (int)(mf.Height * resolution / mf.VerticalResolution);
    Bitmap bmp = new Bitmap(width, height);
    bmp.SetResolution(resolution, resolution);
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.DrawImage(mf, Point.Empty);
    }
    return bmp;
}

Effective screenshot of the image before reset the image resolution:

How to convert RTF to Image and reset image resolution

The image after reset the image resolution:

How to convert RTF to Image and reset image resolution

Full codes:

using Spire.Doc;
using System.Drawing;
using System.Drawing.Imaging;

namespace RTFtoImage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new document and load from file.
            Document doc = new Document();
            doc.LoadFromFile("sample.rtf", FileFormat.Rtf);
            // save the RTF to image 
            Image[] images = doc.SaveToImages(Spire.Doc.Documents.ImageType.Metafile);
            for (int i = 0; i < images.Length; i++)
            {
                Metafile mf = images[i] as Metafile;
                Image newimage = ResetResolution(mf, 200);
                string outputfile = String.Format("image-{0}.png", i);
                newimage.Save(outputfile, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
        //set the image resolution by the ResetResolution() method
        public static Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }
            return bmp;
        }
    }
}
page 31