In order to have a much better layout, users may pay attention on Word page setting, such as page setup and page background. In this post, I want to talk something about page borders, which is one kind of settings in page background.
Page borders are applied for whole page. All the contents will be put in a box which is formed with borders. Because of borders, contents can be presented more obviously. Also, users can set different types and colors for page border to make the appearance more wonderful.
Then, I will introduce a method about how to add Word page borders with Silverlight. In this example, I use the Silverlight Word component, Spire.Doc for Silverlight, so I have added its dll file in my project.
Document without Borders
Step 1. Declare SaveFileDialog
Declare a SaveFileDialog for save document. Then, set filter for this SaveFileDialog and I set the filter document format as .docx.
Step 2. Load Document
Right click project name to add existing item (Word document). After adding, change its Build Action as Embedded Resource.
Add a run button in UserControl. Double click the button and write code. Declare document and assembly. Use foreach sentence to get name string from assembly. If the name is the same as embedded resource name, load this embedded resource.
Step 3. Add Word Page Borders
Get the section of document and then add borders for this section. Firstly, set the border type and color. Secondly, for confirming contents are all put in box formed with borders, set right and left space between contents and borders.
Step 4. Save Document
Judge if the SaveFileDialog which is declared in first step can pop up. If the result is true, use document.SaveToStrem() method to save this document via SaveFileDialog.
public partial class MainPage : UserControl
private SaveFileDialog saveFileDialog = new SaveFileDialog();
this.saveFileDialog.Filter = “Word Document (*.docx)|*.docx”;
private void button1_Click(object sender, RoutedEventArgs e)
Document document = new Document();
Assembly assembly = this.GetType().Assembly;
foreach (String name in assembly.GetManifestResourceNames())
if (name.EndsWith(“Humor Them.docx”))
using (Stream docStream = assembly.GetManifestResourceStream(name))
document = new Document(docStream, FileFormat.Docx);
Section section = document.Sections;
section.PageSetup.Borders.BorderType = BorderStyle.Engrave3D;
section.PageSetup.Borders.Color = Color.AliceBlue;
section.PageSetup.Borders.Left.Space = 50;
section.PageSetup.Borders.Right.Space = 50;
bool? result = this.saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
using (Stream stream = this.saveFileDialog.OpenFile())
Freely Download Spire.Doc for Silverlight