Thursday, 20 October 2011 09:26

Word to EPUB in C#, VB.NET

The sample demonstrates how to export doc document to Epub file.

Published in Convertors
Tuesday, 12 July 2011 06:48

Doc MailMerge Silverlight

The sample demonstrates how to work with MailMerge in Silverlight via Spire.Doc.

Download template doc file.

Download merged result file.

Published in Mail Merge

Spire.PDFConverter enables users to encrypt PDF documents when converting to PDF. Users can set own password and user password. Also, users can set individual security permissions, for example, print, edit and so on.

How to Encrypt PDF Document

Step 1: Register to Download Free Spire.PDFConverter and Run it.

Step 2: Choose a Document.

Click Add files, select the document you want to convert and encrypt.

Step 3: Encrypt PDF Document

Click Encryption button and then set password and permissions.

Set Own Password

Set User Password

Permissions

Step 4: Convert Document

Click Encryption to confirm. Save the document in a specific path by clicking browse. Then, Click Convert.

Now, the document has been converted to PDF and encrypted.

Published in Spire.PDFConverter
Wednesday, 18 May 2011 09:59

How to Convert HTML to PDF

Why Convert HTML to PDF?

PDF (Portable Document Format), which often used for printing document is an open standard for creating and sharing document. It is one of the most popular file formats because it retains the same format no matter what browser is used to view it and without any loss when transfer from one system to another. So, we usually convert different format files such as Doc, Text, CSV, XML and HTML to PDF. Here is one of the easiest and fastest solutions.

How to Convert HTML to PDF?

Only 3 simple steps, you can finish a whole process of HTML to PDF conversion by using Spire.PDFConverter.

Step 1: Install and Run Spire PDF Converter

Step 2: Add HTML files

Spire.PDFConverter enables user add single HTML file or multiple HTML files. And support add file folder.

Step 3: Choose output file folder and Run conversion process

Spire.PDFConverter is one of the fastest HTML to PDF converting solutions. By using Spire PDF Converter, you can encrypt or add watermark to output PDF files.

Published in Spire.PDFConverter
Monday, 16 May 2011 10:04

How to Convert Doc to PDF

Why Convert Doc to PDF?

PDF documents are not good for designing and editing content but without any information and appearance loss, they are very safe and easy to transfer from one system to another. On the other hand, Microsoft Word document (.doc file) is the most suitable document for designing and editing. So, the most popular way to create PDF documents is to design and create content in MS Word document and then convert the file from Doc to PDF.

How to Convert Doc to PDF?

Only 3 simple steps, you can finish a whole process of Doc to PDF conversion by using Spire.PDFConverter. Download Free Spire.PDFConverter Here

Step 1: Install and Run Spire.PDFConverter

Step 2: Choose Doc file

Click button "Add files" to select Doc files which you want to convert. Spire.PDFConverter supports batch conversion which means you can add multiple Doc files.

Step 3: Start Converting

Choose output file folder and click button "Convert"

Published in Spire.PDFConverter
Thursday, 20 January 2011 08:42

Create Word Table in C#, VB.NET

Word Table can save and display data to enable readers to get information more clearly. Users can insert table in Word document with specified rows, columns and format cells to have a good appearance. This guide introduces a solution to create Word table with data and format cells in C# and VB.NET via Spire.Doc for .NET. The screenshot below presents result after creating and formatting Word table.

Create Word Table

Spire.Doc for .NET, the professional .NET Word component to operate Word document, provides a Table class to perform tasks on table, for example, including rows, columns, cells and table layout operation. The following will show a specified example to create Word table step by step.

Download and install Spire.Doc for .NET at the beginning and follow steps.

  • Firstly, create a new Document class instance and add a new Section in this instance. Invoke Section.AddTable(bool ShowBorder) method to create a table with or without borders.
  • Secondly, initialize two String array instances, Header and data to fill table soon.
  • Thirdly, Invoke Table.ResetCells(int rowsNum, int columnsNum) method to reset rows and columns numbers.
  • Fourthly, fill and format data in table. Create header row at first. Initialize a TableRow instance FRow and set its IsHeader property as true, Height property as a float value and BackColor of RowFormat property as a specified color.
  • Use for loop to fill Header in this TableRow instance and format each cell. Set VerticalAlignment of CellFormat property of FRow.
  • Then, initialize a Paragraph instance p for Cells of FRow. Set HorizontalAlignment of Format property of p.
  • Next, Initialize a TextRange instance TR which stores String array Header.
  • Set CharacterFormat property, including FontName, FontSize, TextColor and Bold for TR.
  • Create data row now. Initialize another TableRow instance DataRow and set Height property.
  • Then, fill this instance with String array data and format cells as operating on FRow.
[C#]
using System;
using System.Data;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace WordTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create Table
            Document doc = new Document();
            Section s = doc.AddSection();
            Table table =s.AddTable(true);

            //Create Header and Data
            String[] Header ={"Item","Description", "Qty","Unit Price","Price"};  
            String[][] data = {
                                  new String[]{ "Spire.Doc for .NET",".NET Word Component","1","$799.00","$799.00"},
                                  new String[]{"Spire.XLS for .NET",".NET Excel Component","2","$799.00","$1,598.00"},
                                  new String[]{"Spire.Office for .NET",".NET Office Component","1","$1,899.00","$1,899.00"},
                                  new String[]{"Spire.PDF for .NET",".NET PDFComponent","2","$599.00","$1,198.00"},
                              };
            //Add Cells
            table.ResetCells(data.Length + 1, Header.Length);

            //Header Row
            TableRow FRow= table.Rows[0];
            FRow.IsHeader = true;
            //Row Height
            FRow.Height = 23;
            //Header Format
            FRow.RowFormat.BackColor = Color.AliceBlue;
            for (int i = 0; i < Header.Length; i++)
            {
                //Cell Alignment
                Paragraph p = FRow.Cells[i].AddParagraph();
                FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                p.Format.HorizontalAlignment = HorizontalAlignment.Center;
                //Data Format
                TextRange TR = p.AppendText(Header[i]);
                TR.CharacterFormat.FontName = "Calibri";
                TR.CharacterFormat.FontSize = 14;
                TR.CharacterFormat.TextColor = Color.Teal;
                TR.CharacterFormat.Bold = true;
            }

            //Data Row
            for (int r = 0; r < data.Length; r++)
            {
                TableRow DataRow = table.Rows[r + 1];

                //Row Height
                DataRow.Height = 20;

                //C Represents Column.
                for (int c = 0; c < data[r].Length; c++)
                {
                    //Cell Alignment
                    DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    //Fill Data in Rows
                    Paragraph p2 =DataRow.Cells[c].AddParagraph();
                    TextRange TR2=p2.AppendText(data[r][c]);
                    //Format Cells
                    p2.Format.HorizontalAlignment = HorizontalAlignment.Center;
                    TR2.CharacterFormat.FontName = "Calibri";
                    TR2.CharacterFormat.FontSize = 12;
                    TR2.CharacterFormat.TextColor = Color.Brown;
                }
            }

            //Save and Launch
            doc.SaveToFile("WordTable.docx",FileFormat.docx2013);
            System.Diagnostics.Process.Start("WordTable.docx");
        }
    }
}
[VB.NET]
Imports System
Imports System.Data
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace WordTable
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Create Table
            Dim doc As New Document()
            Dim s As Section = doc.AddSection()
            Dim table As Table = s.AddTable(True)

            'Create Header and Data
            Dim Header() As String = {"Item", "Description", "Qty", "Unit Price", "Price"}
            Dim data()() As String = {New String() {"Spire.Doc for .NET", ".NET Word Component", "1", "$799.00", "$799.00"},
                                      New String() {"Spire.XLS for .NET", ".NET Excel Component", "2", "$799.00", "$1,598.00"},
                                      New String() {"Spire.Office for .NET", ".NET Office Component", "1", "$1,899.00", "$1,899.00"},
                                      New String() {"Spire.PDF for .NET", ".NET PDFComponent", "2", "$599.00", "$1,198.00"}}
            'Add Cells
            table.ResetCells(data.Length + 1, Header.Length)

            'Header Row
            Dim FRow As TableRow = table.Rows(0)
            FRow.IsHeader = True
            'Row Height
            FRow.Height = 23
            'Header Format
            FRow.RowFormat.BackColor = Color.AliceBlue
            For i As Integer = 0 To Header.Length - 1
                'Cell Alignment
                Dim p As Paragraph = FRow.Cells(i).AddParagraph()
                FRow.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
                p.Format.HorizontalAlignment = HorizontalAlignment.Center
                'Data Format
                Dim TR As TextRange = p.AppendText(Header(i))
                TR.CharacterFormat.FontName = "Calibri"
                TR.CharacterFormat.FontSize = 14
                TR.CharacterFormat.TextColor = Color.Teal
                TR.CharacterFormat.Bold = True
            Next i

            'Data Row
            For r As Integer = 0 To data.Length - 1
                Dim DataRow As TableRow = table.Rows(r + 1)

                'Row Height
                DataRow.Height = 20

                'C Represents Column.
                For c As Integer = 0 To data(r).Length - 1
                    'Cell Alignment
                    DataRow.Cells(c).CellFormat.VerticalAlignment = VerticalAlignment.Middle
                    'Fill Data in Rows
                    Dim p2 As Paragraph = DataRow.Cells(c).AddParagraph()
                    Dim TR2 As TextRange = p2.AppendText(data(r)(c))
                    'Format Cells
                    p2.Format.HorizontalAlignment = HorizontalAlignment.Center
                    TR2.CharacterFormat.FontName = "Calibri"
                    TR2.CharacterFormat.FontSize = 12
                    TR2.CharacterFormat.TextColor = Color.Brown
                Next c
            Next r

            'Save and Launch
            doc.SaveToFile("WordTable.docx",FileFormat.docx2013);
            System.Diagnostics.Process.Start("WordTable.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, an easy-to-use component to operate Word document, allows developers to fast generate, write, edit and save Word (Word 97-2003, Word 2007, Word 2010) in C# and VB.NET for .NET, Silverlight and WPF.

Published in Table
Wednesday, 19 January 2011 06:38

Set Word Indent in C#, VB.NET

Word Indent, a kind of paragraph format, is used to adjust distance between paragraph body and page margins. It includes left indent, right indent, first line indent and hanging indent. Frist indent and right indent can be applied for all paragraph body, while first line indent just can be used for first line of one paragraph and hanging indent for paragraph body except the first line. This guide introduces a solution to set Word indent in C# and VB.NET via Spire.Doc for .NET. The following screenshot presents result after setting indents.

Word Paragraph Indent

Spire.Doc for .NET, powerful .NET Word component, provides a ParagraphFormat class to enables users to set format for specified paragraph and indents are format properties of ParagraphFormat class. Firstly, get specified paragraphs to set indents in document. Secondly, set LeftIndent, RightIndent, FirstLineIndent properties for these paragraphs. Please note that type of all indent properties is float. Download and install Spire.Doc for .NET and follow the code blow to set Word indents.

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

namespace WordIndent
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile(@"E:\Work\Documents\WordDocuments\Microsoft Word 2013 Preview.docx");

            Paragraph para1 = doc.Sections[0].Paragraphs[0];
            para1.Format.LeftIndent = 30;

            Paragraph para2 = doc.Sections[0].Paragraphs[2];
            para2.Format.FirstLineIndent = 30;

            Paragraph para3 = doc.Sections[0].Paragraphs[4];
            para3.Format.RightIndent = 80;

            doc.SaveToFile("Indent.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("Indent.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordIndent
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim doc As New Document()
            doc.LoadFromFile("E:\Work\Documents\WordDocuments\Microsoft Word 2013 Preview.docx")

            Dim para1 As Paragraph = doc.Sections(0).Paragraphs(0)
            para1.Format.LeftIndent = 30

            Dim para2 As Paragraph = doc.Sections(0).Paragraphs(2)
            para2.Format.FirstLineIndent = 30

            Dim para3 As Paragraph = doc.Sections(0).Paragraphs(4)
            para3.Format.RightIndent = 80

            doc.SaveToFile("Indent.docx", FileFormat.Docx2010)
            System.Diagnostics.Process.Start("Indent.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, specializing in manipulating Word document, enables users to generate, write, modify and save Word document (.doc/.docx) quickly and easily in .NET, Silverlight and WPF with C# and VB.NET.

Published in Paragraph

Word Page Break, a mark to present ending of one page and beginning of new page, can be inserted automatically when users fill one page with contents or manually at a specified location by users. This guide demonstrates an easy solution to insert page break to split one page contents into two pages in C#, VB.NET via Spire.Doc for .NET. The following screenshot shows result after inserting Word page break.

Word Page Breaks

Spire.Doc for .NET provides Paragraph.AppendBreak method with customers to insert break easily in Word. The overload, which should be passed to this method, is BreakType (enum-type). There are three break types offered by Spire.Doc for .NET, PageBreak, ColumnBreak and LineBreak. Download and install Spire.Doc for .NET and follow the code blow to insert Word page break behind the specified paragraph.

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

namespace WordBreak
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile(@"E:\Work\Documents\WordDocuments\.NET Framework.docx");

            document.Sections[0].Paragraphs[3].AppendBreak(BreakType.PageBreak);

            document.SaveToFile("PageBreak.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("PageBreak.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordBreak
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim document As New Document()
            document.LoadFromFile("E:\Work\Documents\WordDocuments\.NET Framework.docx")

            document.Sections(0).Paragraphs(3).AppendBreak(BreakType.PageBreak)

            document.SaveToFile("PageBreak.docx", FileFormat.Docx2010)
            System.Diagnostics.Process.Start("PageBreak.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, a professional Word component, enables developers/programmers perform a wide range of processing tasks, such as generate, write, modify and save for their customize .NET, Silverlight and WPF applications.

Published in Page Setup
Tuesday, 18 January 2011 04:01

Decrypt Word Document in C#, VB.NET

Word Decryption is a process to decode encrypted Word document. It requires a password or secret key. If readers want to open and read a protected Word, they need to decrypt this Word document firstly. This guide demonstrates an easy and convenient solution to decrypt Word in C# and VB.NET via Spire.Doc for .NET.

Spire.Doc for .NET, specially developed for programmers to manipulate Word without Word Automation, provides users a method Document.LoadFromFile(String fileName, FileFormat fileFormat, String password) of Document class to open encrypted Word document. It also provides another method Document.RemoveEncryption() to decrypt Word without any protection. Through these two methods, users can decrypt Word easily with Spire.Doc for .NET. Download and install Spire.Doc for .NET. Then follow the code to decrypt.

[C#]
using Spire.Doc;

namespace DecryptWord
{
    class Decryption
    {
        static void Main(string[] args)
        {
            //Load Encrypted Word
            Document document = new Document();
            document.LoadFromFile(@"E:\Work\Documents\Student Transcript.docx", FileFormat.Docx,"123456");

            //Decrypt
            document.RemoveEncryption();
            
            //Save and Launch
            document.SaveToFile("decryption.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("decryption.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace DecryptWord
    Friend Class Decryption
        Shared Sub Main(ByVal args() As String)
            'Load Encrypted Word
            Dim document As New Document()
            document.LoadFromFile("E:\Work\Documents\Student Transcript.docx", FileFormat.Docx, "123456")

            'Decrypt
            document.RemoveEncryption()

            'Save and Launch
            document.SaveToFile("decryption.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("decryption.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, professional Word component, is specially designed for developers to fast generate, write, modify and save Word documents in .NET, Silverlight and WPF with C# and VB.NET. Also, it supports conversion between Word and other popular formats, such as PDF, HTML, Image, Text and so on, in .NET and WPF platform.

Published in Security
Tuesday, 18 January 2011 02:22

How to Convert Word to PDF

This is an all-in-one solution to convert Word to PDF. Within this solution, you can either create a word from scratch or load a word template from folder, and then edit the document as you like; finally you can effortlessly convert word to PDF in C#, VB.NET. The conversion can be doc to PDF or docx to PDF.

Spire.Doc for .NET is a professional .NET library which enables users to directly manage word editing without Microsoft Word being installed, after the editing, you can convert the document to PDF in 2 steps.

Below is the an effective screenshot of the document which will be converted to PDF, at the end Of this post, you can find the target PDF.

Word to PDF

Now feel free to download Spire.Doc for .NET and convert word to PDF for personal use or evaluation. The whole process of converting word to PDF in C#, VB.NET can be described as 2 simple steps.

1. Declare a document and load document which you prepare by using ocument.LoadFromFile() method. The parameter passed to this method is file name string.

2. Save Word document as PDF by using document.SaveToFile() method. Parameters passed to this method is file name string and file format. The file format must be PDF.

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

namespace DoctoPDF
{
    class toPDF
    {
        static void Main(string[] args)
        {
            //Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\work\documents\TestSample.docx");

            //Convert Word to PDF
            document.SaveToFile("toPDF.PDF", FileFormat.PDF);

            //Launch Document
            System.Diagnostics.Process.Start("toPDF.PDF");
        }
    }
}
[VB.NET]
Imports System
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace DoctoPDF
    Friend Class toPDF
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim document As New Document()
            document.LoadFromFile("E:\work\documents\TestSample.docx")

            'Convert Word to PDF
            document.SaveToFile("toPDF.PDF", FileFormat.PDF)

            'Launch Document
            System.Diagnostics.Process.Start("toPDF.PDF")
        End Sub
    End Class
End Namespace

After running the demo, you may find a PDF document launched on your computer:

Word to PDF

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

More about This .NET Word component

Published in Conversion
Page 1 of 4