C# word operate conclusion

Posted in Uncategorized

For the recent project requirements, we need to do some processing on the word document. We doing a lot of search online, and found that most of them are incomplete and repeated. Few of complete guides for word component are not free. Finally I am lucky to find a free C# word library to meet all my requirements. In order to prepare others to use it later, I make a conclution as below. Wish it helps.

How to get it?

This free word component is listed on the Codeplex, you can get the msi file directly from there. It also offers some source code.

Operate word document conclusion.

 1. Open an existing word document. This is the basic and must step to process the word document. And it offers 3 different ways.

Solution1: Initialize a new instance of Document class from the specified existing document.

Document document = new Document(@"..\..\Sample.docx");

Solution2: Load a word document from the file.

Document document = new Document();

Solution3: Load word document from Stream

Stream stream = File.OpenRead(@"..\..\Sample.docx");
Document document = new Document(stream);

2. How to create Table:

Document document = new Document();
Section section = document.AddSection();
Table table = section.AddTable(true);
table.ResetCells(2, 3);
 TableRow row = table.Rows[0];
row.IsHeader = true;
Paragraph para = row.Cells[0].AddParagraph();
TextRange TR = para.AppendText("Item");
para = row.Cells[1].AddParagraph();
TR = para.AppendText("Description");
para = row.Cells[2].AddParagraph();
TR = para.AppendText("Qty");

We can also set the rows and cells board and height.

Extract image from pdf

3. How to insert hyperlinks. You can insert two types of hyperlinks, Email link and webmail link.

Document document = new Document();
Section section = document.AddSection();
//Insert URL hyperlink
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("Home page");
paragraph = section.AddParagraph();
paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink);
//Insert email address hyperlink
paragraph = section.AddParagraph();
paragraph.AppendText("Contact US");
paragraph = section.AddParagraph();
paragraph.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-iceblue.com", HyperlinkType.EMailLink);

Extract image from pdf
4. How to add comments.

Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("Home Page of ");
TextRange textRange = paragraph.AppendText("e-iceblue");
Comment comment1 = paragraph.AppendComment("www.e-iceblue.com");
comment1.Format.Author = "Harry Hu";
comment1.Format.Initial = "HH";


Extract image from pdf
5. How to add bookmarks:


Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("This is a simple book mark.");

Extract image from pdf
6. MailMerge


Document document = new Document();
string[] filedNames = new string[] { "Contact Name", "Fax", "Date" };
string[] filedValues = new string[] { "John Smith", "+1 (69) 123456", System.DateTime.Now.Date.ToString() };
document.MailMerge.Execute(filedNames, filedValues);
document.SaveToFile("MailMerge.doc", FileFormat.Doc);

Extract image from pdf
7. FormField. This part contains create and fill formfield.

Create FormField:
//Add new section to document
Section section = document.AddSection();
//Add Form to section
private void AddForm(Section section)
//add text input field
TextFormField field
= fieldParagraph.AppendField(fieldId, FieldType.FieldFormTextInput) as TextFormField;
//add dropdown field
DropDownFormField list
= fieldParagraph.AppendField(fieldId, FieldType.FieldFormDropDown) as DropDownFormField;
//add checkbox field
fieldParagraph.AppendField(fieldId, FieldType.FieldFormCheckBox);

Extract image from pdf

Fill FormField:
//Fill data from XML file
using (Stream stream = File.OpenRead(@"..\..\..\Data\User.xml"))
    XPathDocument xpathDoc = new XPathDocument(stream);
XPathNavigator user = xpathDoc.CreateNavigator().SelectSingleNode("/user");
Fill data:
foreach (FormField field in document.Sections[0].Body.FormFields)
     String path = String.Format("{0}/text()", field.Name);
     XPathNavigator propertyNode = user.SelectSingleNode(path);
     if (propertyNode != null)
         switch (field.Type)
             case FieldType.FieldFormTextInput:
                  field.Text = propertyNode.Value;
             case FieldType.FieldFormDropDown:
                  DropDownFormField combox = field as DropDownFormField;
                  for(int i = 0; i < combox.DropDownItems.Count; i++)
                      if (combox.DropDownItems[i].Text == propertyNode.Value)
                         combox.DropDownSelectedIndex = i;
                      if (field.Name == "country" && combox.DropDownItems[i].Text == "Others")
                         combox.DropDownSelectedIndex = i;
             case FieldType.FieldFormCheckBox:
                  if (Convert.ToBoolean(propertyNode.Value))
                      CheckBoxFormField checkBox = field as CheckBoxFormField;
                      checkBox.Checked = true;

Extract image from pdf
8. Merge word document.

//Load two documents
//Load Document1 and Document2
Document DocOne = new Document();
DocOne.LoadFromFile(@"E:\Work\Document\welcome.docx", FileFormat.Docx);
Document DocTwo = new Document();
DocTwo.LoadFromFile(@"E:\Work\Document\New Zealand.docx", FileFormat.Docx);
foreach (Section sec in DocTwo.Sections)
//Save and Launch
DocOne.SaveToFile("Merge.docx", FileFormat.Docx);

9. Protect document. You can set password or add watermarks to the word document to protect the document. Both text and image watermarks supported.


//Protect with password
//Add Text watermark:
TextWatermark txtWatermark = new TextWatermark();
txtWatermark.Text = "Microsoft";
txtWatermark.FontSize = 90;
txtWatermark.Layout = WatermarkLayout.Diagonal;
document.Watermark = txtWatermark;
//Add Image watermark:
PictureWatermark picture = new PictureWatermark();
picture.Picture = System.Drawing.Image.FromFile(@"..\imagess.jpeg");
picture.Scaling = 250;
document.Watermark = picture;

10. Conversion function is the most popular requirements for processing word documents. With the help of free Spire.Doc for .net, conversion becomes very simple and easy. Only three same lines code is involved and you can convert word document to often used formats, such as PDF, HTML and Image.

Convert word document to PDF

document.SaveToFile("Target PDF.PDF", FileFormat.PDF);

Extract image from pdf

Convert word document to Image

Image image = document.SaveToImages(0, ImageType.Bitmap);
image.Save("Sample.tiff", ImageFormat.Tiff);

Extract image from pdf
Convert word document to HTML:

document.SaveToFile("Target HTML.html", FileFormat.Html);
WordDocViewer(""Target HTML.html");

Extract image from pdf
Conclusion: This is a powerful and free C# word component without Word automation and any other third party add-ins.

Success belongs to the persevering.

Posted in Uncategorized

When your heart is full of strength, keep on doing one thing is not as difficult as image. Just insist on it, you will get to the success. The following tips will help you.

1.Don’t force yourself.

This isn’t about discipline or the torture of making something you hate happen by brute force. It’s about doing something you want to do. So instead of forcing yourself, frame it in a way that makes it something you enjoy doing. A run can be painful drudgery, or a lovely time clearing your head and enjoying the outdoors. Learning Spanish can be a chore you dread, or a way to enjoy great music, learn about a distant culture, discover new films. Trust me: you won’t get very far doing anything if you have to force yourself every day.

2.Gradually increase.

Throwing yourself full force into something might work for a little while, but it also makes it hard to keep showing up every day. Start small, and each day, just show up. Gradually increase what you do, so that each step along the way it still feels easy and fun.

3.Use momentum.
Once you’ve gotten going, use the inertial force to keep going. This again is a matter of how you frame things. Each day, showing up can be like trudging up a hill with weight on your back, or it can be like falling forward down a hill. When I run down a hill, it’s almost like I’m falling, except that I keep my feet under me so that I’m falling upright.

4.Remind yourself of what you want.
You’re doing the activity (exercise, language learning, meditation) presumably because you want to do it. When we stop doing something, it’s because we’ve forgotten that we wanted it. We start to fear it for some reason, and try not to think about it. Instead, think about it, but remind yourself of why you started doing it in the first place. That might mean reading some motivational articles, watching some videos that motivate you, looking at some pics that motivate you, referring to a vision
in your head. Or just bookmark this article and come back to it every day.

5.Play some music.
When I don’t feel like working out, I’ll play a song. Yesterday it was Eminem’s “Lose It”. I became so instantly pumped up that I went to the rowing machine and shredded it for 3 minutes and exhausted myself. So maybe that was a bit of overkill. But there’s no doubt that it helped me to show up.

6.Stop with the doubts.
Everyone has doubts sometimes, but they can either be overcome, or they can stop us from showing up. Do you doubt that you can stick to something for a long time? Forget about the doubt, and just do it. Be sure that you’re going to do it at least one more time. When you prove yourself right, make a note of that, and then be sure that you’re going to do it one more time. Don’t even allow yourself to imagine that you won’t.

You might have been a three-day monk in the past — that’s in the past. Today, you are reborn, and from this day on all you’re going to do is show up. Can I get an Amen?

Never Underestimate an Idol’s Strength —Jay Chou’s Influence in Asia

Posted in Uncategorized

Have you ever watched The Green Hornet ? Have you got impressed by the role of kato? Isn’t it a hero? He is Jay Chou, the role actor of kato. Compared with his actor role ,more influence work in fact is his Music .


There must be a reason why Asian people appreciate jay’s music .Since the first album titled < jay> was released, his creative music storm was boiled in people’s mind . Combining Chinese and Western music styles, he produces songs that fuse R&B, rock, and pop genres. Because of this unique combination, he makes distinction between himself and other musicians by leading a “China Wind” in Asian music history.. He is really hard –working with talent creating skills because he composes all his songs ,as well as songs for other singers. According To statistics, he composed over 400 songs, and the lyric of each song is classic. For more than 12 years since his first foot in music in 2000,he dominated all the popular elements in China including cloths style ,gesture manner and so on .


There is a common sense in jay’s fans that once you fall love in jay , you will become more excellent and good-heart person.no harm to society. Unlike other singers whose songs only focus love stories, Jay prefer creating songs about family, history ,and positive power besides his classical love songs. His song like “Snail” and “Listen To Mother’s Words”, which educate students to be ambitious, at the same time ,never forget to esteem their families .In real society ,Jay Chou is obedient to his families and kindly treated to his friends. He wrote some songs for his mother, grandmother and father, also , he invited all his good friends to his MV.


People can learn a lot from him, not only his world value , but the success of his marketing strategies ,and creative thoughts of his Western-Chinese musical combination and the musical elements involved in his works. As far as marketing strategies, he insists on his own style, and make sure that there is an special element in each of his concert compared with others. He is good at using “Jay Chou ”brand ,which is representing forefront of the times and unique visual. Of course ,he earned a lot .As time goes by ,he will become old gradually one day .In order to continue his “Chou Style “,he is planning to write songs to the younger singers ,wish his songs’ style will be transferred to generations. Image this ,now ,he has wrote more than 400 hundreds songs and direct 2 movies in the past ten years, how many songs and movies he will contributed to people in the next ten years?


It is difficult to caculate the amount of his fans in the world ,but the crucial point is that his good influence on people will be continued from time to time .As long as there is music ,there is Jay Chou .People once listen to his music ,he/she will never choose to leave his world .Because Jay Chou is like a book ,if you are carefulness to read it ,you will miss its beauty ,but if you careful to read it ,it will make you moved to cry .Deep inside to read it ,you will find he is so charming man ,who always brings you new story ,and new feelings .


Recommend songs:

 “Rice Fragrance” “Popular Imitation” “Besieged From All Sides” “Sand Painting” “Coral Sea”


Recommend movies:

Initial D II

The Green Hornet

The Rooftop



How to print PDF Document in C#?

Posted in PDF Articles, Uncategorized


This technical tip shows how to print a PDF document in program. Spire.Pdf allows you to print PDF document for your requirement at runtime with.NET. By using  Spire.PDF for .NET ,which is suitable for Console platform, WinForm ,and Asp.net ,you can easily load Pdf into these programs and print out this PDF document with the help of printDialog object. The printing mode of this component support background printing mode without intervention and interaction. According to Spire.pdf, you can freely switch printer, select print page, and set relative properties while printing PDF files in C#

In this blog , I will take console platform as an example to share my tips about how to print a PDF document in C#. Here we go :


 Step1: For printing a PDF document, firstly I created a new project in VS .Then set its target framework to be .NET framework 2.0.

 Step2: I instantiated an Spire.Pdf. PdfDocument object and load PDF document by calling its method LoadFromFile:


                // Instantiate an object of PdfDocument

                PdfDocument doc = new PdfDocument();

                string pdfFile = “sample.pdf”;

                //load PDF document


                //Default printing mode without interaction (default printer to print all pages of the document)

Step3:  After what I mentioned above, it’s time for calling the method of PdfDocumen.PrintDocument.Print(). By using default printer, printing this PDF document of all pages can be realized without interaction. Besides printing PDF , i am happy to tell you that this printing mode is also suitable for Web printing in C# :



                //Interaction printing mode(page range,printer,and properties of printing can be freely to selected and set)


Step4 :  The final step to finish printing PDF was a little complicated in C#, because i need instantiate an object of printDialog and set its relative printing properties before calling its method.   Besides ,  at the same time,set Spire.Pdf.pdfDocument relative printing properties as well. Here,the key point to print PDF ,which is what I extremely want to emphasize, is the necessity of combination between printDialog object and PdfDocument.PrintDocument while in this process. Without printDialog object, to print PDF is in vain . At last i just can call method PdfDocument.PrintDocument.print to start print PDF document:

                PrintDialog dialogPrint = new PrintDialog();

                dialogPrint.AllowPrintToFile = true;

                dialogPrint.AllowSomePages = true;

                dialogPrint.PrinterSettings.MinimumPage = 1;

                dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;

                dialogPrint.PrinterSettings.FromPage = 1;

                dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

The Entire Code Snippet:

Please take a look over the following code snippet for this approach:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing.Printing;

using Spire.Pdf;

namespace PdfPrint


class Program



static void Main(string[] args)


// Instantiate an object of PdfDocument

PdfDocument doc = new PdfDocument();

string pdfFile = “sample.pdf”;

//load PDF document


//Default printing mode without interaction (default printer to print all pages of the document)


//Interaction printing mode(page range,printer,and properties of printing can be freely to selected and set)

PrintDialog dialogPrint = new PrintDialog();

dialogPrint.AllowPrintToFile = true;

dialogPrint.AllowSomePages = true;

dialogPrint.PrinterSettings.MinimumPage = 1;

dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;

dialogPrint.PrinterSettings.FromPage = 1;

dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

if (dialogPrint.ShowDialog() == DialogResult.OK)


//the startpage was selected to be printed

doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;

//the endpage was selected to be printed

doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;

//Choose printer to print pdf document

doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

PrintDocument printDoc = doc.PrintDocument;

dialogPrint.Document = printDoc;

//Realize printing






Homepage of Spire.PDF for .NET

Download Spire.PDF for .NET

More Technical Tips by Spire.PDF for .NET

List of 50 Films to Increase Your Programming Interest

Posted in Uncategorized

Lost interest in programming ?

The following list of 50 movies may helps you be enthusiastic about programming again .Take a rest and have a look!

 1.Tron (1982)

2.The Good Wife (TVSeries 2009-)

3.War Games(1993)

4.Eagle Eye(2008)

5.Sneakers (1992)

6.The Bourne Ultimatum (2007)

7.Live Free or Die Hard (2007)

8.Real Genius (1985)


9.Paycheck (2003)

 10.The Net (1995)

11.Pirates of Silicon Valley (1999)

12.The Matrix (1999)

13.We Live in Public2009

 14.Hackers Wanted2008


15.In the Realm of Hackers(2003)

16.Revolution OS(2001)

17.Office Space (1999)


18.We Are Legion (2012)

19.Minority Report (2002)

20.Untraceable (2008)

21.Bill & Ted’s Excellent Adventure (1989)

22.Takedown (2000)

23.A Beautiful Mind (2001)

24.The IT Crowd (TV Series 2006-)

25.Hacking Democracy (2006)

26.Hackers (1995)

27.Code Rush

28.The Social Network(2010)

 29.3 Idiots(2009)


30.Enemy of the State (1998)


31.The First $20 Million is Always the Hardest (2002)


32.Antitrust (2001)

33.The Italian Job (2003)


34.Foolproof (2003)


35.Firewall (2006)


36.Gamer (2009)


38.Colossus – The Forbin Project(1970)



41.Grandma’s Boy2006


43.The King of Kong(2007)

44.The KGB,the Computer and ME(TV 1990)

45.Micro Men(TV 2009)

Micro Men.png

46.The Big Bang Theory(2007)


47.The Code (2001)

48.Catch Me If You Can(2002)

Image of Catch Me If You Can


Image of VIPs

50.Hackers: Outlaws and Angels(2002)

—-From E-iceblue