The summer is finally here and so is DocX version 1.0.0.9. I would like to say sorry once again for the long wait but I simply couldn’t allow DocX to effect my final year college exams.
I received lots of feature requests over the past few months. I intend to implement as many of these features as possible over the next few releases. I have decided to make many small releases instead of one large release.
So what's new in this release?
1) Hyperlinks
DocX now supports hyperlinks.
The Document class now contains AddHyperlink(string, Uri)
The Paragraph class now contains AppendHyperlink(Hyperlink);
Example
- // Create a document.
- using (DocX document = DocX.Create(@"Test.docx"))
- {
- // Add a hyperlink to this document.
- Hyperlink h = document.AddHyperlink
- ("Google", new Uri("http://www.google.com"));
- // Add a new Paragraph to this document.
- Paragraph p = document.InsertParagraph();
- p.Append("My favourite search engine is ");
- p.AppendHyperlink(h);
- p.Append(", I think it's great.");
- // Save all changes made to this document.
- document.Save();
- }
Output
2) Content Direction
The Paragraph class now contains a property called Direction which can be either LeftToRight or RightToLeft. This property has both a getter and setter function.
To accommodate Paragraph Direction
- The Document class now contains SetDirection(Direction)
- The Table class now contains SetDirection(Direction)
- The Row class now contains SetDirection(Direction)
- The Cell class now contains SetDirection(Direction)
Where Direction is an enum with the choices LeftToRight and RightToLeft.
Example
- // Create a new document.
- using (DocX document = DocX.Create("Test.docx"))
- {
- // Create a new Paragraph with the text "Hello World".
- Paragraph p = document.InsertParagraph("Hello World.");
- // Make this Paragraph flow right to left. Default is left to right.
- p.Direction = Direction.RightToLeft;
- // Save all changes made to this document.
- document.Save();
- }
Output
3) Indentation
The Paragraph class now contains four properties for setting Indentation.
- IndentationFirstLine(float) which indents only the first line of a paragraph.
- IndentationHanging(float) which indents all but the first line of a paragraph.
- IndentationBefore(float) which indents before content.
- IndentationAfter(float) which indents after content.
Example
- // Create a new document.
- using (DocX document = DocX.Create("Test.docx"))
- {
- // Create a new Paragraph.
- Paragraph p = document.InsertParagraph("Line 1\nLine 2\nLine 3");
- // Indent only the first line of the Paragraph.
- p.IndentationFirstLine = 1.0f;
- // Save all changes made to this document.
- document.Save();
- }
Output
4) Pictures
The Image class now contains a CreatePicture() function and the Paragraph class contains a AppendPicture(Picture) function. The below example should explain how these updates enable easier Paragraph building.
Example
- using (DocX document = DocX.Create("Test.docx"))
- {
- // Add an image to the document.
- Image i = document.AddImage(@"Image.jpg");
- // Create a picture i.e. (A custom view of an image)
- Picture p = i.CreatePicture();
- p.FlipHorizontal = true;
- p.Rotation = 10;
- // Create a new Paragraph.
- Paragraph par = document.InsertParagraph();
- // Append content to the Paragraph.
- par.Append("Here is a cool picture")
- .AppendPicture(p)
- .Append(" don't you think so?");
- // Save all changes made to this document.
- document.Save();
- }
Output
Future
As always, I offer this code to you for free. I am however a student and if you would like to help me pay of some of my student debt , you can make a donation to DocX via paypal.

I love it,Excellent article.I am decide to put this into use one of these days.Thank you for sharing this.To Your Success!
ReplyDelete_____________________________________________________________________________
Rc Helicopter Parts|Rc Helicopter|Mini Rc Helicopter