Spire.Doc for .NET (337)
Children categories
This article shows how to place a footnote in a paragraph using Spire.Doc for .NET, for example, after the word "Spire.Doc" in the following example:


Step 1: Load a word document, Sample.docx.
Document document1 = new Document();
document1.LoadFromFile("D:\\Sample.docx",FileFormat.Docx2010);
Step 2: Get the first paragraph of the first section of Sample.docx.
Paragraph paragraph1 = document1.Sections[0].Paragraphs[0];
Step 3: Add a footnote for paragraph1.
Footnote footnote1 = paragraph1.AppendFootnote(FootnoteType.Footnote);
Step 4: Find the word "Spire.Doc" and insert footnote1 after it.
DocumentObject obj=null;
for (int i = 0; i < paragraph1.ChildObjects.Count; i++)
{
obj=paragraph1.ChildObjects[i];
if (obj.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = obj as TextRange;
// Find the word "Spire.Doc" in paragraph1
if (textRange.Text == "Spire.Doc")
{
//Set bold format for the word "Spire.Doc"
textRange.CharacterFormat.Bold = true;
//Insert footnote1 after the word "Spire.Doc"
paragraph1.ChildObjects.Insert(i + 1, footnote1);
break;
}
}
}
Step 5: Type the footnote1 text and set the text's FontName, FontSize and Color.
TextRange text = footnote1.TextBody.AddParagraph().AppendText("Welcome to evaluate Spire.Doc");
text.CharacterFormat.FontName = "Arial Black";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.TextColor = Color.DarkGray;
Step 6: Set FontName, FontSize, Bold and Color for the footnote1 number.
footnote1.MarkerCharacterFormat.FontName = "Calibri"; footnote1.MarkerCharacterFormat.FontSize = 12; footnote1.MarkerCharacterFormat.Bold = true; footnote1.MarkerCharacterFormat.TextColor = Color.DarkGreen;
Step 7: Save Sample.docx to a new document, Footnote.docx.
document1.SaveToFile("D:\\ Footnote.docx"", FileFormat.Docx2010);
Full code:
Document document1 = new Document();
document1.LoadFromFile("D:\\Sample.docx" ,FileFormat.Docx2010);
Paragraph paragraph1= document1.Sections[0].Paragraphs[0];
Footnote footnote1 = paragraph1.AppendFootnote(FootnoteType.Footnote);
DocumentObject obj=null;
for (int i = 0; i < paragraph1.ChildObjects.Count; i++)
{
obj=paragraph1.ChildObjects[i];
if (obj.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = obj as TextRange;
// Find the word "Spire.Doc" in paragraph1
if (textRange.Text == "Spire.Doc")
{
//Set bold format for the word "Spire.Doc"
textRange.CharacterFormat.Bold = true;
//Insert footnote1 after the word "Spire.Doc"
paragraph1.ChildObjects.Insert(i + 1, footnote1);
break;
}
}
}
TextRange text = footnote1.TextBody.AddParagraph().AppendText("Welcome to evaluate Spire.Doc");
text.CharacterFormat.FontName = "Arial Black";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.TextColor = Color.DarkGray;
footnote1.MarkerCharacterFormat.FontName = "Calibri";
footnote1.MarkerCharacterFormat.FontSize = 12;
footnote1.MarkerCharacterFormat.Bold = true;
footnote1.MarkerCharacterFormat.TextColor = Color.DarkGreen;
document1.SaveToFile("Footnote.docx",FileFormat.Docx2010);
PDF/A is an ISO-standardized version of the Portable Document Format (PDF) specialized for the digital preservation of electronic documents. It is widely used for long term archiving for PDF format. This article mainly shows how to convert word document (doc and docx) to PDF/A in C# by using Spire.Doc.
Make sure Spire.Doc for .NET Version 5.0.26 (or above) has been installed correctly 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".
First, check the original word document that will be converted to PDF/A.
Here comes to the details of how developers convert word document to PDF/A directly by using Spire.Doc:
Step 1: Load a word document from the file.
Document document = new Document(); document.LoadFromFile(@"D:\test.docx",FileFormat.Docx);
Step 2: Sets the Pdf document's Conformance-level to PDF_A1B.
ToPdfParameterList toPdf = new ToPdfParameterList(); toPdf.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;
Step 3: Save word document to PDF
document.SaveToFile("result.Pdf",toPdf);
Please check the effective screenshot of the result PDF in PDF/A format.
When dealing with Word documents, sometimes developers need to merge multiple files into a single file. Spire.Doc, especially designed for developers enables you to manipulate doc files easily and flexibly.
There is already a document introducing how to merge doc files. Check it here:
.NET Merge Word - Merge Multiple Word Documents into One in C# and VB.NET
Using the method above, you have to copy sections one by one. But the new method just concatenates them. It has improved and is very easy to use
Step 1: Load the original word file "A Good Man.docx".
document.LoadFromFile("A Good Man.docx", FileFormat.Docx);
Step 2: Merge another word file "Original Word.docx" to the original one.
document.InsertTextFromFile("Original Word.docx", FileFormat.Docx);
Step 3: Save the file.
document.SaveToFile("MergedFile.docx", FileFormat.Docx);
Full code and screenshot:
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile("A Good Man.docx", FileFormat.Docx);
document.InsertTextFromFile("Original Word.docx", FileFormat.Docx);
document.SaveToFile("MergedFile.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("MergedFile.docx");
}
Full code and screenshot:
using Spire.Doc;
namespace MergeWord
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile("A Good Man.docx", FileFormat.Docx);
document.InsertTextFromFile("Original Word.docx", FileFormat.Docx);
document.SaveToFile("MergedFile.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("MergedFile.docx");
}
}
}
