Spire.Doc
Tuesday, 07 August 2012 06:39

Insert Page Break in Word in WPF

Written by support iceblue

Word Page Break is used to start with contents in a new page, which can be inserted anywhere in Word document. Generally speaking, page break can be generated automatically when one page is filled with contents, or users can specify where Microsoft Word positions automatic page break. Also, users can insert manual page breaks in document to keep some paragraphs together in a single page.

Spire.Doc for WPF, a professional WPF component on manipulating Word document, enables users to insert page break in Word with WPF. Users can invoke paragraph.Append(BreakType.PageBreak) method directly to insert page break in Word.

Spire.Doc presents an easy way to insert a page break. Just follow the simple steps below to insert a page break.

The following screenshot presents document before inserting page break.

Download and install Spire.Doc for WPF. Add button in MainWindow and double click this button to use the following code to insert page break with WPF in Word.

[C#]
using System.Windows;
using Spire.Doc;
using Spire.Doc.Documents;

namespace Doc_x_PageBreak
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\work\documents\Blues Introduction.docx");

            //Get Paragraph Position
            Section section = doc.Sections[0];
            Paragraph paragraph = section.Paragraphs[1];

            //Insert Page Break
            paragraph.AppendBreak(BreakType.PageBreak);

            //Save and Launch
            doc.SaveToFile("PageBreak.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("PageBreak.docx");
        }
    }
}
[VB.NET]
Imports System.Windows
Imports Spire.Doc
Imports Spire.Doc.Documents

Class MainWindow

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'Load Document
        Dim doc As New Document()
        doc.LoadFromFile("E:\work\documents\Blues Introduction.docx")

        'Get Paragraph Position
        Dim section As Section = doc.Sections(0)
        Dim paragraph As Paragraph = section.Paragraphs(1)

        'Insert Page Break
        paragraph.AppendBreak(BreakType.PageBreak)

        'Save and Launch
        doc.SaveToFile("PageBreak.docx", FileFormat.Docx)
        System.Diagnostics.Process.Start("PageBreak.docx")

    End Sub
End Class

Effective Screenshot:

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.

Tuesday, 31 July 2012 03:24

Insert Text Watermark to Word in WPF

Written by support iceblue

Word watermark can be text or image, which appears behind document contents and will not influence integrity of document body. It often adds interest or identifies document status, for example, marking document as private or important. This is the guide you are looking for about how to insert text watermark in Word with WPF.

Spire.Doc for WPF, a professional WPF component on manipulating Word document, enables users to insert text watermark in Word document and set format for this watermark. Comparing with “Insert Watermark” Command in Microsoft Word, Spire.Doc for WPF provides a Spire.Doc.TextWatermark class. Firstly initialize a new instance of Textwatermark with TextWatermark TXTWatermark = new TextWatermark() and then set text watermark as document watermark type by code:document.Watermark = TXTWatermark.

Besides, TextWatermark class includes several parameters for watermark formatting setting, including text, font style, layout etc. The following screenshot is the document without watermark. After the code below, you will find a result screenshot with text watermark being adding at the bottom of the page.

Word Text Watermark

Download Spire.Doc for WPF and install it on your system. After adding button in MainWindow, double click this button to use the following code to insert text watermark in Word with WPF.

[C#]
using System.Windows;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;

namespace Doc_x_Watermark
{
   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\work\Documents\New Zealand.docx");

            //Insert Text Watermark and Set Format
            TextWatermark TXTWatermark = new TextWatermark();
            TXTWatermark.Text = "NZ Brief Introduction ";
            TXTWatermark.FontSize = 45;
            TXTWatermark.FontName = "Broadway BT";
            TXTWatermark.Layout = WatermarkLayout.Diagonal;
            TXTWatermark.Color = Color.Purple;
            document.Watermark = TXTWatermark;

            //Save and Launch
            document.SaveToFile("TXTWatermark.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("TXTWatermark.docx");
        }
    }
}
[VB.NET]
Imports System.Windows
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents

Class MainWindow

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'Load Document
        Dim document As New Document()
        document.LoadFromFile("E:\work\Documents\New Zealand.docx")

        'Insert Text Watermark and Set Format
        Dim TXTWatermark As New TextWatermark()
        TXTWatermark.Text = "NZ Brief Introduction"
        TXTWatermark.FontSize = 45
        TXTWatermark.FontName = "Broadway BT"
        TXTWatermark.Layout = WatermarkLayout.Diagonal
        TXTWatermark.Color = Color.Purple
        document.Watermark = TXTWatermark

        'Save and Launch
        document.SaveToFile("TXTWatermark.docx", FileFormat.Docx)
        System.Diagnostics.Process.Start("TXTWatermark.docx")

    End Sub
End Class

After running, you can get the result as following:

Word Text Watermark

Spire.Doc is a Microsoft Word component which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF.NET and Silverlight.

Wednesday, 25 July 2012 08:05

Convert Word to HTML in WPF

Written by support iceblue

During software development, developers may need to convert Word to HTML. Different from many available ways on Internet, in this example, the solution for converting Word to HTML enables WPF developers load a predefined Doc, Docx, or RTF document, fill it with data, convert the document to HTML.

Spire.Doc for WPF is a professional component specializing in manipulating Word document for WPF. To convert a Word to HTML simply in WPF, developers need to invoke document.LoadFromFile(), which is used to load document and document.SaveToFile(), which is used to convert document.

The following screenshot shows parts of contents of original Word document. The target HTML is at the bottom after this coding. It is shown in Firefox, same as the original document.

Word to HTML

Download and install Spire.Doc for WPF on your system. Then, add a button in MainWindow and double click it to use the following code to convert Word to HTML in WPF

[C#]
//Load Document
Document document = new Document();
document.LoadFromFile(@"E:\work\Documents\Humor Them.docx");

//Convert to HTML
document.SaveToFile("ToHTML.html", FileFormat.Html);

//Launch Document
System.Diagnostics.Process.Start("ToHTML.html");
[VB.NET]
'Load Document
Dim document As New Document()
document.LoadFromFile("E:\work\Documents\Humor Them.docx")

'Convert to HTML
document.SaveToFile("ToHTML.html", FileFormat.Html)

'Launch Document
System.Diagnostics.Process.Start("ToHTML.html")

After running, you can get the result as following:

Word to HTML

Spire.Doc is an Microsoft Word component which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF.NET and Silverlight.