.NET (1317)
Children categories
PDF margins are white spaces between body contents and page edge. Unlike Word, margins in PDF document are not easy to be modified as Adobe does not provide any functionality for users to manipulate margins freely. However, you can change the page scaling (enlarge/compress content) or crop page to get fitted margins. In this article, you will learn how to enlarge PDF margins by compressing content.
Step 1: Create a PdfDocument object to load the original PDF document.
PdfDocument origDoc = new PdfDocument();
origDoc.LoadFromFile("sample.pdf");
Step 2: Create another PdfDocument object.
PdfDocument destDoc = new PdfDocument();
Step 3: Set the increments that you want to add to the margins in the existing PDF document.
float top = 50; float bottom = 50; float left = 50; float right = 50;
Step 4: Transfer the compressed content from the original document to the new PDF document.
foreach (PdfPageBase page in origDoc.Pages)
{
PdfPageBase newPage = destDoc.Pages.Add(page.Size, new PdfMargins(0));
newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width,
(page.ActualSize.Height - top - bottom) / page.ActualSize.Height);
newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(left, top));
}
Step 5: Save to file.
destDoc.SaveToFile("result.pdf", FileFormat.PDF);
Original PDF:

Result:

Full Code:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace ChangeMargins
{
class Program
{
static void Main(string[] args)
{
PdfDocument origDoc = new PdfDocument();
origDoc.LoadFromFile("sample.pdf");
PdfDocument destDoc = new PdfDocument();
float top = 50;
float bottom = 50;
float left = 50;
float right = 50;
foreach (PdfPageBase page in origDoc.Pages)
{
PdfPageBase newPage = destDoc.Pages.Add(page.Size, new PdfMargins(0));
newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width,
(page.ActualSize.Height - top - bottom) / page.ActualSize.Height);
newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(left, top));
}
destDoc.SaveToFile("result.pdf", FileFormat.PDF);
}
}
}
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing
Namespace ChangeMargins
Class Program
Private Shared Sub Main(args As String())
Dim origDoc As New PdfDocument()
origDoc.LoadFromFile("sample.pdf")
Dim destDoc As New PdfDocument()
Dim top As Single = 50
Dim bottom As Single = 50
Dim left As Single = 50
Dim right As Single = 50
For Each page As PdfPageBase In origDoc.Pages
Dim newPage As PdfPageBase = destDoc.Pages.Add(page.Size, New PdfMargins(0))
newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width, (page.ActualSize.Height - top - bottom) / page.ActualSize.Height)
newPage.Canvas.DrawTemplate(page.CreateTemplate(), New PointF(left, top))
Next
destDoc.SaveToFile("result.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
Set the font and color for the text on PDF Combo Box field area
2015-11-25 07:33:44 Written by KoohjiWith the help of Spire.PDF, developers can easily add new text to the PDF; create form fields to both the new and existing PDF file. Spire.PDF also owns the ability to set the text formatting for the PDF fields' area. This article will show you how to set the font and color for PDF Combo Box field by the method of PdfComboBoxField.
Note: Before Start, please download the latest version of Spire.PDF and add Spire.PDF.dll in the bin folder as the reference of Visual Studio.
Here comes to the details:
Step 1: Create a new PDF document.
PdfDocument doc = new PdfDocument();
Step 2: Add a new page to the PDF document and set the page size for the page.
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins());
Step 3: Draw the text to the PDF page and set the location, font and color for the text.
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
RectangleF labelBounds = new RectangleF(20, 20, 40, font.Height);
page.Canvas.DrawString("My label", font, PdfBrushes.Black, labelBounds);
Step 4: Create a Combo Box and add value for it. Use comboBox.Font and comboBox.ForeColor to set the font and color for the text on Combo Box area.
PdfComboBoxField comboBox = new PdfComboBoxField(page, "cmb");
comboBox.Bounds = new RectangleF(80, 20, 80, font.Height);
comboBox.Font = font;
comboBox.ForeColor = Color.Blue;
comboBox.Items.Add(new PdfListFieldItem("value 1", "text 1"));
comboBox.Items.Add(new PdfListFieldItem("value 2", "text 2"));
comboBox.Items.Add(new PdfListFieldItem("value 3", "text 3"));
Step 5: Add the Combo Box to the PDF file.
doc.Form.Fields.Add(comboBox);
Step 6: Save the document to file and launch to preview it.
string file = string.Format("result.pdf", Guid.NewGuid().ToString());
doc.SaveToFile(file);
System.Diagnostics.Process.Start(file);
Effective screenshot after setting the font and color for text on the Combo Box area:

Full codes:
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;
using System;
using System.Drawing;
namespace SetFontColorInComboboxField
{
class Program
{
static void Main(string []args)
{
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins());
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
RectangleF labelBounds = new RectangleF(20, 20, 40, font.Height);
page.Canvas.DrawString("My label", font, PdfBrushes.Black, labelBounds);
PdfComboBoxField comboBox = new PdfComboBoxField(page, "cmb");
comboBox.Bounds = new RectangleF(80, 20, 80, font.Height);
comboBox.Font = font;
comboBox.ForeColor = Color.Blue;
comboBox.Items.Add(new PdfListFieldItem("value 1", "text 1"));
comboBox.Items.Add(new PdfListFieldItem("value 2", "text 2"));
comboBox.Items.Add(new PdfListFieldItem("value 3", "text 3"));
doc.Form.Fields.Add(comboBox);
string file = string.Format("result.pdf", Guid.NewGuid().ToString());
doc.SaveToFile(file);
System.Diagnostics.Process.Start(file);
}
}
}
Spire.PDFViewer for ASP.NET contains two controls: PDFViewer and PDFDocumentViewer. Generally, PDFDocumentViewer is used for loading and viewing PDF files on website. But actually, it can also achieve other features such as zoom, fit and page after a simple design.
We've introduced the usage of PDFViewer in the previous article, so this article will illustrate how to zoom PDF File via PDFDocumentViewer in ASP.NET.
Before start, download Spire.PDFViewer for ASP.NET and install it on your system.
Step 1: Create a new ASP.NET Empty Web Application in Visual Studio. Add a new web Form to the project.
Step 2: Add the .dll files from the bin folder as the references of this project.

Step 3: Add the PDFDocumentViewer control into toolbox and drag it into Deafault.aspx.

(Detail manipulations of step 1, 2, 3 refer to this article: How to use Spire.PDFViewer for ASP.NET)
Step 4: Zoom PDF file via Spire. PDFDocumentViewer. Zoom feature is divided into three types in this article:
- Zoom: choose the zoom percentage manually.
- Zoom in: Increase the display page page zoom factor by ten percent.
- Zoom out: decrease the display page page zoom factor by ten percent.
Main codes
Section 1: Call the LoadFromFile() method of PdfDocumentViewer to load a sample PDF file in Default.aspx.cs. Note that you have to add the following if statement and !IsPostBack property before loading the pdf file.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//load the sample PDF file
this.PdfDocumentViewer1.CacheInterval = 1000;
this.PdfDocumentViewer1.CacheTime = 1200;
this.PdfDocumentViewer1.CacheNumberImage = 1000;
this.PdfDocumentViewer1.ScrollInterval = 300;
this.PdfDocumentViewer1.ZoomFactor = 1f;
this.PdfDocumentViewer1.CustomErrorMessages = "";
this.PdfDocumentViewer1.LoadFromFile("files/PDFViewer.pdf");
}
}
Section 2: Design, Drag a DropDownList and two buttons from toolbox into Deafault.aspx, set the properties like "ID", "text" etc. as below.

Generated source code is shown here:
<select id="PdfDocumentViewer1_SelectCurrentZoomLevel" name="PdfDocumentViewer1_SelectCurrentZoomLevel" onchange="pdfdocumentviewer1.SelectDropdownBox(this.value)">
<option value="0.5">50%</option>
<option value="0.75">75%</option>
<option value="1" selected="selected">100%</option>
<option value="1.5">150%</option>
<option value="2">200%</option>
<option value="4">400%</option>
</select>
<input type="button" id="btnZoomIn" value="Zoom In" onclick="pdfdocumentviewer1.ZoomPage()" />
<input type="button" id="btnZoomOut" value="Zoom Out" onclick="pdfdocumentviewer1.NarrowPage()" />
Effect screenshot after designing:

Transferring content between Microsoft Word documents is a frequent need for many users. Whether you're consolidating information from multiple sources or reorganizing the structure of a document, being able to effectively copy and paste text, graphics, and formatting is crucial.
This article demonstrates how to copy content from one Word document to another using C# and Spire.Doc for .NET.
- Copy Specified Paragraphs from One Word Document to Another
- Copy a Section from One Word Document to Another
- Copy the Entire Document and Append it to Another
- Create a Copy of a Word Document
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Copy Specified Paragraphs from One Word Document to Another in C#
With Spire.Doc library for .NET, you can clone individual paragraphs using the Paragraph.Clone() method, and then add the cloned paragraphs to a different Word document using the ParagraphCollection.Add() method. This allows you to selectively copy and transfer content between documents.
To copy specified paragraphs from one Word document to another, follow these steps:
- Create a Document object to load the source file.
- Create another Document object to load the target file.
- Get the specified paragraphs from the source file.
- Clone these paragraphs using Paragraph.Clone() method.
- Add the cloned paragraphs to the target file using ParagraphCollection.Add() method.
- Save the target file to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
namespace CopyParagraphs
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document sourceDoc = new Document();
// Load the source file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx");
// Get the specified paragraphs from the source file
Paragraph p1 = sourceDoc.Sections[0].Paragraphs[8];
Paragraph p2 = sourceDoc.Sections[0].Paragraphs[9];
// Create another Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Get the last section
Section lastSection = targetDoc.LastSection;
// Add the paragraphs from the soure file to the target file
lastSection.Paragraphs.Add((Paragraph)p1.Clone());
lastSection.Paragraphs.Add((Paragraph)p2.Clone());
// Save the target file to a different Word file
targetDoc.SaveToFile("CopyParagraphs.docx", FileFormat.Docx2019);
// Dispose resources
sourceDoc.Dispose();
targetDoc.Dispose();
}
}
}

Copy a Section from One Word Document to Another in C#
A section in a Word document can contain not only paragraphs, but also other elements such as tables. To copy an entire section from one Word document to another, you need to iterate through all the child objects within the section and add them individually to a specified section in the target document.
The steps to copy a section between different Word documents are:
- Create Document objects to load the source file and the target file, respectively.
- Get the specified section from the source file.
- Iterate through the child objects in the section, and clone these objects using DocumentObject.Clone() method.
- Add the cloned child objects to a specified section of the target file using DocumentObjectCollection.Add() method.
- Save the updated target file to a new file.
- C#
using Spire.Doc;
namespace CopySection
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document sourceDoc = new Document();
// Load the source file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx");
// Get the specified section from the source file
Section section = sourceDoc.Sections[0];
// Create another Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Get the last section of the target file
Section lastSection = targetDoc.LastSection;
// Iterate through the child objects in the selected section
foreach (DocumentObject obj in section.Body.ChildObjects)
{
// Add the child object to the last section of the target file
lastSection.Body.ChildObjects.Add(obj.Clone());
}
// Save the target file to a different Word file
targetDoc.SaveToFile("CopySection.docx", FileFormat.Docx2019);
// Dispose resources
sourceDoc.Dispose();
targetDoc.Dispose();
}
}
}
Copy the Entire Document and Append it to Another in C#
To copy the full contents from one Word document into another, you can use the Document.InsertTextFromFile() method. This method appends the source document's contents to the target document, starting on a new page.
The steps to copy the entire document and append it to another are as follows:
- Create a Document object.
- Load a Word file (target file) from the given file path.
- Insert content of a different Word document to the target file using Document.InsertTextFromFile() method.
- Save the updated target file to a new Word document.
- C#
using Spire.Doc;
namespace CopyEntireDocument
{
class Program
{
static void Main(string[] args)
{
// Specify the path of the source document
String sourceFile = "C:\\Users\\Administrator\\Desktop\\source.docx";
// Create a Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Insert content of the source file to the target file
targetDoc.InsertTextFromFile(sourceFile, FileFormat.Docx);
// Save the target file to a different Word file
targetDoc.SaveToFile("CopyEntireDocuemnt.docx", FileFormat.Docx2019);
// Dispose resources
targetDoc.Dispose();
}
}
}
Create a Copy of a Word Document in C#
Using Spire.Doc library for .NET, you can leverage the Document.Clone() method to easily duplicate a Word document.
Here are the steps to create a copy of a Word document:
- Create a Document object.
- Load a Word file from the given file path.
- Clone the file using Document.Clone() method.
- Save the cloned document to a new Word file.
- C#
using Spire.Doc;
namespace CloneWordDocument
{
class Program
{
static void Main(string[] args)
{
// Create a new document object
Document sourceDoc = new Document();
// Load a Word file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");
// Clone the document
Document newDoc = sourceDoc.Clone();
// Save the cloned document as a docx file
newDoc.SaveToFile("Copy.docx", FileFormat.Docx);
// Dispose resources
sourceDoc.Dispose();
newDoc.Dispose();
}
}
}
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Developers can use PDF layer to set some content to be visible and others to be invisible in the same PDF file. It makes the PDF Layer widely be used to deal with related contents within the same PDF. Now developers can easily add page layers by using class PdfPageLayer offered by Spire.PDF. This article will focus on showing how to add layers to a PDF file in C# with the help of Spire.PDF.
Note: Before Start, please download the latest version of Spire.PDF and add Spire.PDF.dll in the bin folder as the reference of Visual Studio.
Here comes to the details:
Step 1: Create a new PDF document
PdfDocument pdfdoc = new PdfDocument();
Step 2: Add a new page to the PDF document.
PdfPageBase page = pdfdoc.Pages.Add();
Step 3: Add a layer named "red line" to the PDF page.
PdfLayer layer = doc.Layers.AddLayer("red line", PdfVisibility.On);
Step 4: Draw a red line to the added layer.
// Create a graphics context for drawing on the specified page's canvas using the created layer PdfCanvas pcA = layer.CreateGraphics(page.Canvas); // Draw a red line on the graphics context using a pen with thickness 2, starting from (100, 350) to (300, 350) pcA.DrawLine(new PdfPen(PdfBrushes.Red, 2), new PointF(100, 350), new PointF(300, 350));
Step 5: Use the same method above to add the other two layers to the PDF page.
layer = doc.Layers.AddLayer("blue line");
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
pcB.DrawLine(new PdfPen(PdfBrushes.Blue, 2), new PointF(100, 400), new PointF(300, 400));
layer = doc.Layers.AddLayer("green line");
PdfCanvas pcC = layer.CreateGraphics(doc.Pages[0].Canvas);
pcC.DrawLine(new PdfPen(PdfBrushes.Green, 2), new PointF(100, 450), new PointF(300, 450));
Step 6: Save the document to file.
pdfdoc.SaveToFile("AddLayers.pdf", FileFormat.PDF);
Effective screenshot:

Full codes:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddLayer
{
class Program
{
static void Main(string[] args)
{
// Create a new PdfDocument object
PdfDocument doc = new PdfDocument();
// Load an existing PDF document from the specified file path
doc.LoadFromFile(@"..\..\..\..\..\..\Data\AddLayers.pdf");
// Get the first page of the loaded document
PdfPageBase page = doc.Pages[0];
// Create a new layer named "red line" with visibility set to "On"
PdfLayer layer = doc.Layers.AddLayer("red line", PdfVisibility.On);
// Create a graphics context for drawing on the specified page's canvas using the created layer
PdfCanvas pcA = layer.CreateGraphics(page.Canvas);
// Draw a red line on the graphics context using a pen with thickness 2, starting from (100, 350) to (300, 350)
pcA.DrawLine(new PdfPen(PdfBrushes.Red, 2), new PointF(100, 350), new PointF(300, 350));
// Create a new layer named "blue line" without specifying visibility (default is "Off")
layer = doc.Layers.AddLayer("blue line");
// Create a graphics context for drawing on the first page's canvas using the newly created layer
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
// Draw a blue line on the graphics context using a pen with thickness 2, starting from (100, 400) to (300, 400)
pcB.DrawLine(new PdfPen(PdfBrushes.Blue, 2), new PointF(100, 400), new PointF(300, 400));
// Create a new layer named "green line" without specifying visibility (default is "Off")
layer = doc.Layers.AddLayer("green line");
// Create a graphics context for drawing on the first page's canvas using the newly created layer
PdfCanvas pcC = layer.CreateGraphics(doc.Pages[0].Canvas);
// Draw a green line on the graphics context using a pen with thickness 2, starting from (100, 450) to (300, 450)
pcC.DrawLine(new PdfPen(PdfBrushes.Green, 2), new PointF(100, 450), new PointF(300, 450));
// Specify the output file name for the modified PDF
string output = "AddLayers.pdf";
// Save the modified PDF document to the specified output file
doc.SaveToFile(output);
}
}
}
Spire.PDFViewer is a powerful and independent ASP.NET library, by which users can easily achieve functions such as load and view pdf files on website, switch to target page, fit page, page down/up, zoom in/out pdf files etc.
Then how to use Spire.PDFViewer for ASP.NET? This article will introduce the usage of Spire.PDFViewer for ASP.NET to you.
Before start, please download Spire.PDFViewer for ASP.NET and install it on your system.
Detail steps overview:
Step 1: Create a new ASP.NET Empty Web Application in Visual Studio.

Add a new web Form to Test1.


Then add the .dll files from the bin folder as the references of Test1.

Now the three .dll files have been added into the References.

Step 2: Add the PDFViewer control and the PDFDocumentViewer control into toolbox.
First, right-click toolbox, select add tab to add a new tab named SpirePDFViewer.

Second, add the PDFViewer control and the PDFDocumentViewer control into SpirePDFViewer.


Now all of the controls have been added into SpirePDFViewer.

Step 3: Right-click Default.aspx, select view designer, and then drag the PDFViewer control from toolbox into Deafault.aspx.

Step 4: Double-click Default.aspx.cs, add the code below to load a PDF file, Note that you have to add the following if statement and !IsPostBack property before loading the pdf file.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//load the sample PDF file
this.pdfViewer1.CacheInterval = 1000;
this.pdfViewer1.CacheTime = 1200;
this.pdfViewer1.CacheNumberImage = 1000;
this.pdfViewer1.ScrollInterval = 300;
this.pdfViewer1.ZoomFactor = 1f;
this.pdfViewer1.CustomErrorMessages = "";
this.pdfViewer1.LoadFromFile("PDF file/Test.pdf");
}
}
Effect screenshot:

Footnotes are notes placed at the bottom of a page. In MS Word, you can use footnotes to cite references, give explanations, or make comments without affecting the main text. In this article, you will learn how to insert or delete footnotes in a Word document using Spire.Doc for .NET.
- Insert a Footnote after a Specific Paragraph in Word in C# and VB.NET
- Insert a Footnote after a Specific Text in Word in C# and VB.NET
- Remove Footnotes in a Word Document in C# and VB.NET
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Insert a Footnote after a Specific Paragraph in Word in C# and VB.NET
The Paragraph.AppendFootnote(FootnoteType.Footnote) method provided by Spire.Doc for .NET allows you to insert a footnote after a specified paragraph. The following are the detailed steps.
- Create a Document instance
- Load a sample Word document using Document.LoadFromFile() method.
- Get the first section and then get a specified paragraph in the section.
- Add a footnote at the end of the paragraph using Paragraph.AppendFootnote(FootnoteType.Footnote) method.
- Set the text content, font and color of the footnote, and then set the format of the footnote superscript number.
- Save the result document using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace AddFootnote
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.LoadFromFile("Sample.docx");
//Get the first section
Section section = document.Sections[0];
//Get a specified paragraph in the section
Paragraph paragraph = section.Paragraphs[3];
//Add a footnote at the end of the paragraph
Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
//Set the text content of the footnote
TextRange text = footnote.TextBody.AddParagraph().AppendText("Algorithms can be simple or complex depending on what you want to achieve.");
//Set the text font and color
text.CharacterFormat.FontName = "Arial";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkBlue;
//Set the format of the footnote superscript number
footnote.MarkerCharacterFormat.FontName = "Calibri";
footnote.MarkerCharacterFormat.FontSize = 15;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;
//Save the result document
document.SaveToFile("AddFootnote.docx", FileFormat.Docx);
}
}
}

Insert a Footnote after a Specific Text in Word in C# and VB.NET
With Spire.Doc for .NET, a footnote can also be inserted after a specified text located anywhere in the document. The following are the detailed steps.
- Create a Document instance.
- Load a Word document using Document.LoadFromFile() method.
- Find a specified text using Document.FindString() method.
- Get the text range of the specified text using TextSelection.GetAsOneRange() method.
- Get the paragraph where the text range is located using TextRange.OwnerParagraph property.
- Get the position index of the text range in the paragraph using Paragraph.ChildObjects.IndexOf() method.
- Add a footnote using Paragraph.AppendFootnote(FootnoteType.Footnote) method, and then insert the footnote after the specified text using Paragraph.ChildObjects.Insert() method
- Set the text content, font and color of the footnote, and then set the format of the footnote superscript number.
- Save the result document using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertFootnote
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.LoadFromFile("Sample.docx");
//Find a specified text string
TextSelection selection = document.FindString("big O notation", false, true);
//Get the text range of the specified text
TextRange textRange = selection.GetAsOneRange();
//Get the paragraph where the text range is located
Paragraph paragraph = textRange.OwnerParagraph;
//Get the position index of the text range in the paragraph
int index = paragraph.ChildObjects.IndexOf(textRange);
//Add a footnote
Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
//Insert the footnote after the specified paragraph
paragraph.ChildObjects.Insert(index + 1, footnote);
//Set the text content of the footnote
TextRange text = footnote.TextBody.AddParagraph().AppendText("It gives the worst-case complexity of an algorithm.");
//Set the text font and color
text.CharacterFormat.FontName = "Arial";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.DarkBlue;
//Set the format of the footnote superscript number
footnote.MarkerCharacterFormat.FontName = "Calibri";
footnote.MarkerCharacterFormat.FontSize = 15;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;
//Save the result document
document.SaveToFile("InsertFootnote.docx", FileFormat.Docx);
}
}
}

Remove Footnotes in a Word Document in C# and VB.NET
It takes time and effort to search and delete the existing footnotes in your document manually. The following are the steps to remove all footnotes at once programmatically.
- Create a Document instance.
- Load a Word document using Document.LoadFromFile() method.
- Get a specified section using Document.Sections property.
- Traverse through each paragraph in the section to find the footnote.
- Remove the footnote using Paragraph.ChildObjects.RemoveAt() method.
- Save the result document using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace RemoveFootnote
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.LoadFromFile("AddFootnote.docx");
//Get the first section
Section section = document.Sections[0];
//Traverse through each paragraph in the section to find the footnote
foreach (Paragraph para in section.Paragraphs)
{
int index = -1;
for (int i = 0, cnt = para.ChildObjects.Count; i < cnt; i++)
{
ParagraphBase pBase = para.ChildObjects[i] as ParagraphBase;
if (pBase is Footnote)
{
index = i;
break;
}
}
if (index > -1)
//Remove the footnote
para.ChildObjects.RemoveAt(index);
}
//Save the result document
document.SaveToFile("RemoveFootnote.docx", FileFormat.Docx);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
When you create several Word documents that are closely related, you may want the header or footer of one document to be used as the header or footer of other documents. For example, you're creating internal documents with your company logo or name or other material been placed in header, you only have to create the header once and copy the header to other places.
In this article, I'll introduce you a simple and efficient solution to copy the entire header (including text and graphic) from one Word document and insert it to another.
Source Document:

Detail Steps:
Step 1: Create a new instance of Document class and load the source file.
Document doc1 = new Document();
doc1.LoadFromFile("test1.docx");
Step 2: Get the header section from the source document.
HeaderFooter header = doc1.Sections[0].HeadersFooters.Header;
Step 3: Initialize a new instance of Document and load another file that you want to insert header.
Document doc2 = new Document("test2.docx");
Step 4: Call DocuentObject.Clone() method to copy each object in the header of source file, then call DocumentObjectCollection.Add() method to insert copied object into the header of destination file.
foreach (Section section in doc2.Sections)
{
foreach (DocumentObject obj in header.ChildObjects)
{
section.HeadersFooters.Header.ChildObjects.Add(obj.Clone());
}
}
Step 5: Save the changes and launch the file.
doc2.SaveToFile("test2.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("test2.docx");
Destination Document:

Full Code:
Document doc1 = new Document();
doc1.LoadFromFile("test1.docx");
HeaderFooter header = doc1.Sections[0].HeadersFooters.Header;
Document doc2 = new Document("test2.docx");
foreach (Section section in doc2.Sections)
{
foreach (DocumentObject obj in header.ChildObjects)
{
section.HeadersFooters.Header.ChildObjects.Add(obj.Clone());
}
}
doc2.SaveToFile("test2.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("test2.docx");
Dim doc1 As New Document()
doc1.LoadFromFile("test1.docx")
Dim header As HeaderFooter = doc1.Sections(0).HeadersFooters.Header
Dim doc2 As New Document("test2.docx")
For Each section As Section In doc2.Sections
For Each obj As DocumentObject In header.ChildObjects
section.HeadersFooters.Header.ChildObjects.Add(obj.Clone())
Next
Next
doc2.SaveToFile("test2.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("test2.docx")
Sometimes, we need to copy the data with formatting from one cell range (a row or a column) to another. It is an extremely easy work in MS Excel, because we can select the source range and then use Copy and Paste function to insert the same data in destination cells.
In fact, Spire.XLS has provided two methods Worksheet.Copy(CellRange sourceRange, CellRange destRange, bool copyStyle) and Worksheet.Copy(CellRange sourceRange, Worksheet worksheet, int destRow, int destColumn, bool copyStyle) that allow programmers to copy rows and columns within or between workbooks. This article will present how to duplicate a row within a workbook using Spire.XLS.
Test File:

Code Snippet:
Step 1: Create a new instance of Workbook class and load the sample file.
Workbook book = new Workbook();
book.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
Step 2: Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
Step 3: Call Worksheet.Copy(CellRange sourceRange, CellRange destRange, bool copyStyle) method to copy data from source range (A1:G1) to destination range (A4:G4) and maintain the formatting.
sheet.Copy(sheet.Range["A1:G1"], sheet.Range["A4:G4"],true);
Step 4: Save and launch the file.
book.SaveToFile("result.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("result.xlsx");
Output:

Full Code:
using Spire.Xls;
namespace DuplicateRowExcel
{
class Program
{
static void Main(string[] args)
{
Workbook book = new Workbook();
book.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
Worksheet sheet = book.Worksheets[0];
sheet.Copy(sheet.Range["A1:G1"], sheet.Range["A4:G4"], true);
book.SaveToFile("result.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("result.xlsx");
}
}
}
Imports Spire.Xls
Namespace DuplicateRowExcel
Class Program
Private Shared Sub Main(args As String())
Dim book As New Workbook()
book.LoadFromFile("sample.xlsx", ExcelVersion.Version2010)
Dim sheet As Worksheet = book.Worksheets(0)
sheet.Copy(sheet.Range("A1:G1"), sheet.Range("A4:G4"), True)
book.SaveToFile("result.xlsx", ExcelVersion.Version2010)
System.Diagnostics.Process.Start("result.xlsx")
End Sub
End Class
End Namespace
With the help of Spire.Presentation for .NET, we can easily save PowerPoint slides as image in C# and VB.NET. Sometimes, we need to use the resulted images for other purpose and the image size becomes very important. To ensure the image is easy and beautiful to use, we need to set the image with specified size beforehand. This example will demonstrate how to save a particular presentation slide as image with specified size by using Spire.Presentation for your .NET applications.
Note: Before Start, please download the latest version of Spire.Presentation and add Spire.Presentation.dll in the bin folder as the reference of Visual Studio.
Step 1: Create a presentation document and load the document from file.
Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");
Step 2: Save the first slide to Image and set the image size to 600*400.
Image img = presentation.Slides[0].SaveAsImage(600, 400);
Step 3: Save image to file.
img.Save("result.png",System.Drawing.Imaging.ImageFormat.Png);
Effective screenshot of the resulted image with specified size:

Full codes:
using Spire.Presentation;
using System.Drawing;
namespace SavePowerPointSlideasImage
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");
Image img = presentation.Slides[0].SaveAsImage(600, 400);
img.Save("result.png", System.Drawing.Imaging.ImageFormat.Png);
}
}