Spire.Doc

Now Spire.Doc support using uninstalled font when converting Doc to PDF to diversity text content. In this article, we'll talk about how to realize this function:

Step 1: Download a font uninstalled in system.

How to use uninstalled font when converting Doc to PDF via Spire.Doc

Step 2: Create a new blank Word document.

Document document = new Document();

Step 3: Add a section and create a new paragraph.

Section section = document.AddSection();
Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();

Step 4: Append text for a txtRange.

TextRange txtRange = paragraph.AppendText(text);

Step 5: Create an example for class ToPdfParameterList named to pdf, and create a new PrivateFontPathlist for property PrivateFontPaths, instantiate one PrivateFontPath with name and path of downloaded font.

ToPdfParameterList toPdf = new ToPdfParameterList()
{
    PrivateFontPaths = new List()
        {
          new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
        }
};

Step 6: Set the new font for the txtaRange.

txtRange.CharacterFormat.FontName = "DeeDeeFlowers";

Step 7: Convert the Doc to PDF.

document.SaveToFile("result.pdf", toPdf);

Step 8: Review converted PDF files.

System.Diagnostics.Process.Start("result.pdf");

Result screenshot:

How to use uninstalled font when converting Doc to PDF via Spire.Doc

Full Code Below:

Document document = new Document();
           
//Add the first secition
Section section = document.AddSection();
//Create a new paragraph and get the first paragraph
Paragraph paragraph
    = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();

//Append Text
String text
    = "This paragraph is demo of text font and color. "
    + "The font name of this paragraph is Tahoma. "
    + "The font size of this paragraph is 20. "
    + "The under line style of this paragraph is DotDot. "
    + "The color of this paragraph is Blue. ";
 TextRange txtRange = paragraph.AppendText(text);

//Import the font
 ToPdfParameterList toPdf = new ToPdfParameterList()
 {
     PrivateFontPaths = new List<PrivateFontPath>()
         {
          new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
         }
};
//Make use of the font.
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";

document.SaveToFile("result.pdf", toPdf);

System.Diagnostics.Process.Start("result.pdf");

Plain text format (TXT) is a basic format with the advantage of small size and it is compatible with almost all applications. With Spire.Doc for .NET, developers can convert word document into TXT easily. This article will show you how to load a plain text files and convert it to word documents.

Spire.Doc allows developers to import plain text file the same way as other document formats, by using the class Spire.Doc.Document. The whole process only need you three lines of codes. Firstly, please check the original plain text file as below:

How to load a plain text (txt) files and save it as word document

Here comes to the steps of how to save txt document into .docx.

Step 1: Create document instance and load the plain text file.

Document doc = new Document();
doc.LoadText("Sample.txt");

Step 2: Save the file as word document in .docx by using the code below

doc.SaveToFile("Result.docx", FileFormat.Docx2010);

Below is an effective screenshot of the result word document.

How to load a plain text (txt) files and save it as word document

Full codes:

namespace txttoword
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadText("Sample.txt");
            doc.SaveToFile("Result.docx", FileFormat.Docx2010);
        }
    }
}

Multi-level list numbering allows you to format and organize text with nested numbers. The most common form of multi-level list is Heading Numbering, which summarizes the whole article with an outline list, frequently appearing in technical, academic and business documents. In this article, you’ll learn how to generate multi-level list numbering using Spire.Doc in C#, VB.NET.

Detailed Steps:

Step 1: Create a new Word document, add one section.

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

Step 2: Define a new multi-level list style. Set its name as levelstyle, set ListType as Numbered, set parameters of level property. This list level operates independently of the style and controls the number formatting.

ListStyle listStyle = new ListStyle(document, ListType.Numbered);
listStyle.Name = "levelstyle";
listStyle.Levels[0].PatternType = ListPatternType.Arabic;
listStyle.Levels[1].NumberPrefix = "\x0000.";
listStyle.Levels[1].PatternType = ListPatternType.Arabic;
listStyle.Levels[2].NumberPrefix = "\x0000.\x0001.";
listStyle.Levels[2].PatternType = ListPatternType.Arabic;
document.ListStyles.Add(listStyle);

Step 3: Create a paragraph, append text to paragraph and apply the paragraph style with Heading1. Apply the defined list style ‘levelstyle’ to this paragraph.

Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("The first item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

Step 4: Repeat step 3 to add more paragraphs to this document. Here, you need to set different ListLevelNumber as 1 or 2 to make sure the sub-paragraph and sub-sub-paragraph will be assigned to deferent list templates.

paragraph = section.AddParagraph();
paragraph.AppendText("The second item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The first sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ListLevelNumber = 1;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The second sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ContinueListNumbering();
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("A sub-sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading5);
paragraph.ListFormat.ListLevelNumber = 2;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The third item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

Step 5: Save the file.

document.SaveToFile(@"result.docx", FileFormat.Docx);

Result:

How to Create Multi-level List Numbering in Word in C#, VB.NET

Full Code:

[C#]
Document document = new Document();
Section section = document.AddSection();

ListStyle listStyle = new ListStyle(document, ListType.Numbered);
listStyle.Name = "levelstyle";
listStyle.Levels[0].PatternType = ListPatternType.Arabic;
listStyle.Levels[1].NumberPrefix = "\x0000.";
listStyle.Levels[1].PatternType = ListPatternType.Arabic;
listStyle.Levels[2].NumberPrefix = "\x0000.\x0001.";
listStyle.Levels[2].PatternType = ListPatternType.Arabic;
document.ListStyles.Add(listStyle);

Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("The first item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The second item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The first sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ListLevelNumber = 1;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The second sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ContinueListNumbering();
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("A sub-sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading5);
paragraph.ListFormat.ListLevelNumber = 2;
paragraph.ListFormat.ApplyStyle("levelstyle");

paragraph = section.AddParagraph();
paragraph.AppendText("The third item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ApplyStyle("levelstyle");

document.SaveToFile(@"result.docx", FileFormat.Docx);
[VB.NET]
Dim document As New Document()
Dim section As Section = document.AddSection()

Dim listStyle As New ListStyle(document, ListType.Numbered)
listStyle.Name = "levelstyle"
listStyle.Levels(0).PatternType = ListPatternType.Arabic
listStyle.Levels(1).NumberPrefix = vbNullChar & "."
listStyle.Levels(1).PatternType = ListPatternType.Arabic
listStyle.Levels(2).NumberPrefix = vbNullChar & "." & ChrW(1) & "."
listStyle.Levels(2).PatternType = ListPatternType.Arabic
document.ListStyles.Add(listStyle)

Dim paragraph As Paragraph = section.AddParagraph()
paragraph.AppendText("The first item")
paragraph.ApplyStyle(BuiltinStyle.Heading1)
paragraph.ListFormat.ApplyStyle("levelstyle")

paragraph = section.AddParagraph()
paragraph.AppendText("The second item")
paragraph.ApplyStyle(BuiltinStyle.Heading1)
paragraph.ListFormat.ApplyStyle("levelstyle")

paragraph = section.AddParagraph()
paragraph.AppendText("The first sub-item")
paragraph.ApplyStyle(BuiltinStyle.Heading2)
paragraph.ListFormat.ListLevelNumber = 1
paragraph.ListFormat.ApplyStyle("levelstyle")

paragraph = section.AddParagraph()
paragraph.AppendText("The second sub-item")
paragraph.ApplyStyle(BuiltinStyle.Heading2)
paragraph.ListFormat.ContinueListNumbering()
paragraph.ListFormat.ApplyStyle("levelstyle")

paragraph = section.AddParagraph()
paragraph.AppendText("A sub-sub-item")
paragraph.ApplyStyle(BuiltinStyle.Heading5)
paragraph.ListFormat.ListLevelNumber = 2
paragraph.ListFormat.ApplyStyle("levelstyle")

paragraph = section.AddParagraph()
paragraph.AppendText("The third item")
paragraph.ApplyStyle(BuiltinStyle.Heading1)
paragraph.ListFormat.ApplyStyle("levelstyle")

document.SaveToFile("result.docx", FileFormat.Docx)
Page 1 of 28