Close





 
Watermark is one kind of digital information which is inserted in document. It can be semitransparent text or image and will not influence contents in document. Generally speaking, people add watermark in document in order to protect copyright or showing document properties, for example, people may add company name as text watermark in document.

Spire.PDF enables users to add watermark in PDF document, including image watermark and text watermark. This program guide focuses on how to add watermark in PDF document by using C#/VB.NET.

Step 1 Load Document

Declare a new PDF document and then use document.LoadFromFile() method to load document which you want to add watermark. Finally, declare page as page in this existed PDF document.
[C#]
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"E:\work\A Thousand Suns.pdf");
            PdfPageBase page = document.Pages[0];
[Visual Basic]
            Dim document As New PdfDocument()
            document.LoadFromFile("E:\work\A Thousand Suns.pdf")
            Dim page As PdfPageBase = document.Pages(0)
          

Step 2 Add Background Image

Declare an image. Use Image.FormFile() method to get this image. File name string should be passed to this method. Then, set the declared image as background image of page.
[C#]
            Image img = Image.FromFile(@"E:\work\Documents\heaven&hell.jpg");
            page.BackgroundImage = img;
[Visual Basic]
            Dim img As Image = Image.FromFile("E:\work\Documents\heaven&hell.jpg")
            page.BackgroundImage = img
          

Step 3 Add Text Watermark

Firstly, Text Watermark Style
Declare a new PdfTilingBrush to set brush size. Then, use brush.Graphics.SetTransparency(), brush.Graphics.TranslatesTransform() and brush.Graphics.RotateTransform() method to set transparency, location and rotation.
[C#]
            PdfTilingBrush brush
    = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 2));
            brush.Graphics.SetTransparency(0.5f);
            brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
            brush.Graphics.RotateTransform(-45);
[Visual Basic]
            Dim brush As New PdfTilingBrush(New SizeF(page.Canvas.ClientSize.Width \ 2, page.Canvas.ClientSize.Height \ 2))
            brush.Graphics.SetTransparency(0.5F)
            brush.Graphics.TranslateTransform(brush.Size.Width \ 2, brush.Size.Height \ 2)
            brush.Graphics.RotateTransform(-45)
          
Secondly,Text Watermark Content
Declare a PdfTrueTypeFont to set font style and size. Then, use brush.Graphics.DrawString() method to draw text watermark. Three methods should be passed to this method, string, font, brush, location(x, y) and alignment. Finally, draw rectangle on page.
[C#]
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Calibri", 24f,FontStyle.Bold));
            brush.Graphics.DrawString("A Thousand Suns",
                font1, PdfBrushes.DarkOrange, 0, 0,
                new PdfStringFormat(PdfTextAlignment.Center));
            page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
[Visual Basic]
            Dim font1 As New PdfTrueTypeFont(New Font("Calibri", 24.0F, FontStyle.Bold))
            brush.Graphics.DrawString("A Thousand Suns", font1, PdfBrushes.DarkOrange, 0, 0, New PdfStringFormat(PdfTextAlignment.Center))
            page.Canvas.DrawRectangle(brush, New RectangleF(New PointF(0, 0), page.Canvas.ClientSize))
          

Step 4 Save and Launch

Save this document by using document.SavetoFile() method with a new name. The parameter passed to this method is file name string. Then, close this document. Finally, launch this file.
[C#]
            document.SaveToFile("Watermark.pdf");
            document.Close();
            System.Diagnostics.Process.Start("Watermark.pdf");
[Visual Basic]
            document.SaveToFile("Watermark.pdf")
            document.Close()
            System.Diagnostics.Process.Start("Watermark.pdf")
          

Effective Screeshot


Spire.PDF is a PDF document creation component that enables your .NET applications to read, write and manipulate PDF documents without using Adobe Acrobat. Now, the new version added Silverlight platform which makes it more powerful.


Pivot table is one kind of interactive table, which can be used to calculate data, such as get sum or count data. Also, users can change pivot table layout for analyzing data with different ways or reassign row/column label. Every time users change layout, data will be recalculated in pivot table. Also, pivot table can be updated if the source data is changed.

This program guide focuses on introducing how to create Pivot Table in Excel by using C#/VB.NET via Spire.XLS.

In this guide, there is an Excel file which includes a worksheet with data information. What we will do is to add a new worksheet and create pivot table in this worksheet. Data source of pivot table is from the original worksheet.

Step 1 Load Excel File

Declare a new Excel workbook and then load file by using workbook.LoadFromFile() method. Then, initialize worksheet and name the current worksheet. Because we need to create pivot table in another worksheet, so create a new worksheet and name it.
[C#]
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"E:\work\Documents\PartSalesInfo.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Data Source";
            Worksheet sheet2 = workbook.CreateEmptySheet();
            sheet2.Name = "Pivot Table";
[Visual Basic]
            Dim workbook As New Workbook()
            workbook.LoadFromFile("E:\work\Documents\PartSalesInfo.xlsx")
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.Name = "Data Source"
            Dim sheet2 As Worksheet = workbook.CreateEmptySheet()
            sheet2.Name = "Pivot Table"
          

Step 2 Create Pivot Table

At first, add pivot table. Select data source range which is from the original worksheet. Create a PivotCache to save the data information. Next, create a pivot table in the new worksheet. Assign value for pivot table by using sheet2.PivotTables.Add() method. Three parameters passed to this method, name string, table location and pivot cache.

[C#]
CellRange dataRange = sheet.Range["A1:G17"];
            PivotCache cache = workbook.PivotCaches.Add(dataRange);
            PivotTable pt = sheet2.PivotTables.Add("Pivot Table", sheet.Range["A1"], cache);
[Visual Basic]
Dim dataRange As CellRange = sheet.Range("A1:G17")
            Dim cache As PivotCache = workbook.PivotCaches.Add(dataRange)
            Dim pt As PivotTable = sheet2.PivotTables.Add("Pivot Table", sheet.Range("A1"), cache)
          
Secondly, define row labels. We can set some data information as row label to assign data information. Get PivotField of the first row label we will set and then set its AxisType as row. After that, set header name. Next, set the second row label as setting the first one but without header name.
[C#]
            var r1 = pt.PivotFields["Vendor No"];
            r1.Axis = AxisTypes.Row;
            pt.Options.RowHeaderCaption = "Vendor No";

            var r2 = pt.PivotFields["Description"];
            r2.Axis = AxisTypes.Row;
[Visual Basic]
            Dim r1 = pt.PivotFields("Vendor No")
            r1.Axis = AxisTypes.Row
            pt.Options.RowHeaderCaption = "Vendor No"

            Dim r2 = pt.PivotFields("Description")
            r2.Axis = AxisTypes.Row
          
Thirdly, add new data fields and set format. Besides the original data information, we can add more fields to calculate data by using pt.DataFileds.Add() method. There are three parameters passed to this method, Pivot Field, name string and subtotal type. The fields we will add include SUM of OnHand, SUM of OnOrder and Average of ListPrice. Finally, set built-in style for table.
[C#]
pt.DataFields.Add(pt.PivotFields["OnHand"], "SUM of OnHand", SubtotalTypes.Sum);
            pt.DataFields.Add(pt.PivotFields["OnOrder"], "SUM of OnOrder", SubtotalTypes.Sum);
            pt.DataFields.Add(pt.PivotFields["ListPrice"], "Average of ListPrice", SubtotalTypes.Average);

            pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12;
[Visual Basic]
pt.DataFields.Add(pt.PivotFields("OnHand"), "SUM of OnHand", SubtotalTypes.Sum)
            pt.DataFields.Add(pt.PivotFields("OnOrder"), "SUM of OnOrder", SubtotalTypes.Sum)
            pt.DataFields.Add(pt.PivotFields("ListPrice"), "Average of ListPrice", SubtotalTypes.Average)

            pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12
          

Step 3 Save and Launch

Save this Excel file which has been added pivot table by using workbook.SaveToFile() method. There are two parameters passed to this method, file name string and Excel version. In this example, Excel version is set as Version2010. Then, launch it for viewing.

[C#]
            workbook.SaveToFile("PivotTable.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("PivotTable.xlsx");
[Visual Basic]
            workbook.SaveToFile("PivotTable.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("PivotTable.xlsx")
          

Effective Screeshot

Data Source



Pivot Table:


Related Articles

Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.


Tuesday, 15 May 2012 02:07

Privacy Policy

This web site is maintained by E-iceblue Ltd. By accessing or using www.e-iceblue.com, you need to agree to terms of E-iceblue Online Privacy Policy, as outlined below. If you do not agree to these terms, please do not access or use this site.

Overview

E-iceblue has established this Onine Privacy Policy to help you understand how we intend to treat your Personal Information.

E-iceblue is committed to protecting your privacy. For accessing service from E-iceblue, we may ask for personal identification information (“Personal Information”), including your name (first and last), your e-mail address or some other contact information. The personal information can be provided by yourself or any other party. In general, you may visit our website without disclosing to us who you are and without revealing any Personal Information about yourself.

Also, you should be aware though, that if you choose to provide us with Personal Information, we may transfer such information, within E-iceblue or E-iceblue’s third party service providers, across borders and from your country or jurisdiction to other countries or jurisdictions around the world, subject to the limitations of this Privacy Policy.

E-iceblue Strives to comply with all applicable laws around the globe that are designed to protect your privacy. Although legal requirements may vary from country to country, E-iceblue intends to adhere to the principles set forth in this Online Privacy Policy.

Cookies and Other Tracking Technologies

When you visit www.e-iceblue.com, you may surf the site anonymously and access important information without revealing your identity. In order to analyze and improve our site, we use “cookies” to track your visit. A cookie is small amount of data that is transferred to your browser by a Web server and can only be read by the server that give it to you. “Cookies” cannot be executed as code or deliver viruses.

Most browsers are initially set to accept cookies. You can set your browser to notify you when you receive a cookie, therefore allowing you to decide whether or not to accept it. (For some Web pages that require an authorization, cookies are not optional. Users choosing not to accept cookies will not be able to access such pages.)

While E-iceblue uses cookies to track your visit to www.e-iceblue.com, and our Web servers automatically log the IP/Internet address of your computer. This information does not identify you personally and you remain anonymous unless you have otherwise provided e-iceblue with Personal Information.

Principles

The following principles we adopted to protect your privacy.

Choice

You may choose whether or not to provide Personal Information to E-iceblue. However, when you engage in certain activities on this site, such as ordering products, downloading software, or entering contests, E-iceblue may require that you provide certain information about yourself by filling out and submitting an online form. It is entirely optional for you to engage in these activities. If you elect to engage in these activities, E-iceblue may require that you provide certain personal information, such as your name, mailing address, e-mail address, and other personal identifying information.

Security

Wherever your Personal Information may be held by E-iceblue or a third party on E-iceblue’s behalf, reasonable and appropriate precautions, such as encryption, firewalls and like technologies, are and will be implemented to protect such Personal Information from loss, misuse or unauthorized access.

Access/Accuracy

To the extent that you do provide us with Personal Information, E-iceblue wishes to maintain it accurately and updated. Where we collect Personal Information from you, our goal is to provide a means of contacting E-iceblue should you need to access, update or correct that Information. If for any reason you desire to review such information, please contact us and we will make reasonable efforts to promptly provide you with such information. Further, if you notify us that such information is incorrect, or you wish to have such information removed, we will correct, amend, or delete your Personal Information as soon as practicable.

Third Party Services

In the interest of providing better service to its customers, E-iceblue is represented in the United States and in some foreign countries by authorized distributors and resellers who provide marketing, sales, and support services to E-iceblue customers. When you submit personal information to E-iceblue, you understand and agree that E-iceblue may allow E-iceblue’s authorized distributors and resellers access to your customer profile for the exclusive purpose of providing you with marketing, sales, and support services for E-iceblue products.

Your personal information will not be leased, sold, rented or otherwise made available to any other third party except to the extent necessary to comply with applicable laws, police investigations, or in legal proceedings where such information is relevant. Occasionally, E-iceblue allows access to database information to bonded mailing houses only for the purpose of allowing for the printing of mailing labels that are used for E-iceblue 's own direct mail and promotional purposes. In those instances, the third party is strictly bound by these terms.

Notwithstanding the foregoing, you hereby agree that E-iceblue may assign, sell, license, or otherwise transfer to a third party, your name, address, email address, member name and any other personal information in connection with an assignment, sale, joint venture, or other transfer or disposition of a material portion or essentially all of the assets or stock of E-iceblue or its affiliated entities.

Children's Privacy

www.e-iceblue.com is not designed nor structured to attract children. Accordingly, we do not intend to collect Personal Information from anyone we know to be under 13 years of age. If we are made aware that information is or has been submitted by or collected from a child under the age of thirteen, we will promptly delete this information.

Sensitive Information

We do not collect Sensitive Information such as medical, health, racial, ethnic, political, religious, philosophic, union membership or sexual orientation information. If we are made aware that we have received such information, we will promptly proceed to its deletion.

Notice

E-iceblue collects Personal Information on its Web site in order to record and support your participation in the activities you select. If you order a product, for example, the information is used to register your license and rights, if any, to ensure your eligibility to receive technical support, upgrade discounts, or other benefits that may be made available to registered users. If you enter a contest, information is collected to qualify the entry and contact you regarding the contest or prize awards. E-iceblue also uses information that you provide as part of our effort to keep you informed about the status of your subscription, product upgrades, special offers, and other E-iceblue products and services.

We will only collect Personal Information where it is relevant for the purposes for which we are collecting it. We will not process any Personal Information for any purposes that are incompatible with the purposes for which it has been collected or subsequently authorized by you.

Commitment

We, at E-iceblue, are committed to your right to privacy and we support current industry initiatives to preserve the integrity of individual privacy rights on the Internet. Protecting your privacy on-line is a rapidly evolving area, and E-iceblue's Web sites are continually evolving to meet these demands.

Your Consent

By using this Web site, you consent to the terms of our Online Privacy Policy and to E-iceblue's processing of Personal Information for the purposes outlined above. Should the Online Privacy Policy change, we will take reasonable steps to ensure that these changes are brought to your attention by posting all changes prominently on our Web site for a reasonable period of time.

Contact

If you have any comments or questions regarding our Online Privacy Policy, please contact us at comments@e-iceblue.com.

Tuesday, 15 May 2012 01:52

Renew Policy

Why Renew Subscription?

When you purchase a license from E-iceblue, you will get a full 1 year’s subscription software updates. We will send you an email to remind you if your subscription nears its subscription. However, without a subscription you can still use the product and get FREE support, but you are not allowed to get new features of hot fixes. If you have a problem that requires a hot fix but do not have a current subscription, you will have to renew before you can benefit from the fix.

When Should I Renew Subscription?

You can renew your subscription before its expiry date or after that. If your first time purchase is on September 12, the expiry date is on September 11 in the next year. We will send you an email to remind you around August 11.

What Does a Subscription Cost?

Renewing an existing subscription is cheaper than renewing an expired subscription. While your subscription is still running, adding a year to the subscription costs 80% of the current product price. To re-activate an expired subscription costs 70% of the current product price. Renewal adds twelve months to your subscription from the expiry date. However, if your expiry date is September 11, and you renew your license on October 10, then, the expiry data will be changed to October 9 in the next year.

How to Renew Subscription?

Log in to the purchase system with your account information. You can find the renewal discount coupon code in the purchase page. Use the coupon code to purchase the renewal. Leave a Note to offer us your registered license information including your email address, register name so that our technical support can send you renewal correctly.


If you bought the product from one of our resellers you can contact them when you need to renew your subscription. Our resellers can help you purchase a new subscription.

Contact Our Sales Team for other questions

Tuesday, 15 May 2012 01:34

License Upgrade

If you purchased the license of Spire.Doc Developer Subscription and a few days later you found you need Spire.Doc Developer OEM Subscription, you can ask to Upgrade Your License.

When Can I Upgrade License?

After you purchase our product and receive license, you can only upgrade your license during the first 3 months. After 3 months, you need purchase what you want. However, you can get 10% OFF discount as a return customer.

How Much I Should Pay?

When you upgrade license, you just need pay the price difference. For example, if you purchased Spire.Doc Pro Edition Developer Subscription ($499) on May 1, 2012 and you want to upgrade to Spire.Office Developer Subscription ($999) on May 10, 2012, you just need pay $500. And the register data will be May 10, 2012.

Can I Upgrade My Spire.PDF to Spire.Doc?

No, you can’t. You can convert Spire.PDF to Spire.Office. Or you can convert Spire.PDF Developer Subscription to Spire.PDF OEM Subscription, Spire.PDF Site Enterprise or Spire.PDF Site OEM.

How to Upgrade?

When you found you need upgrade your license, please send email to sales@e-iceblue.com. You need offer us the old license information (Product Name, License Registered Name, Purchasing Date, Purchasing email address and what product license you want to upgrade to). Then, we will generate upgrade coupon code for you.


If you need more help, please contact our sales team.

Page Border in Microsoft Word is very popular, as a lovely page border makes a page more attractive to look at. Here's a solution to use C#/VB.NET to insert page border in word document. Here we will use Spire.Doc for .NET. As a professional and powerful Word component, Spire.Doc doesn't need Microsoft Office Word Automation but also allows user to directly operate Word document, format and style and insert content to Word document. Now download Spire.Doc for .NET and install on your system, then follow the program guide to insert page border in Word document.

Friendly Reminder: Make sure Spire.Doc and Visual Studio are correctly installed on system.

Step 1 Create a Project

Create a C#/VB.NET project in Visual Studio. Add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.

Step 2 Insert Page Border in Word Document

We can use Spire.Doc to create a new Word document and use it to insert page borders.
[C#]
Document doc = new Document();
            Section section = doc.AddSection();

            // add text
            section.AddParagraph().AppendText("This is a simple test by E-iceblue Co.,Ltd");
            section.AddParagraph().AppendText("E-iceblue Co., Ltd. provides professional .NET components for .NET applications and Microsoft Visual Studio. \n");
            section.AddParagraph().AppendText("The goal of e-iceblue is always to offer high-quality components for reading and writing office file formats. E-iceblue components have been widely-used by most of the Fortune 500 corporations\n");
            section.AddParagraph().AppendText("The key developers of e-iceblue have over 10 years of combined experience developing high-performance, high-quality .net component technology\n");

            //insert page border
            section.PageSetup.Borders.BorderType = Spire.Doc.Documents.BorderStyle.ThinThickLargeGap;
          
[VB.NET]
Dim doc As New Document()
Dim section As Section = doc.AddSection()
' add text
section.AddParagraph().AppendText("This is a simple test by E-iceblue Co.,Ltd")
section.AddParagraph().AppendText("E-iceblue Co., Ltd. provides professional .NET components for .NET applications and Microsoft Visual Studio. " & vbLf)
section.AddParagraph().AppendText("The goal of e-iceblue is always to offer high-quality components for reading and writing office file formats. e-iceblue components have been widely-used by most of the Fortune 500 corporations" & vbLf)
section.AddParagraph().AppendText("The key developers of e-iceblue have over 10 years of combined experience developing high-performance, high-quality .net component technology" & vbLf)
          

Step 3 Save and Preview

[C#]
            doc.SaveToFile("test.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("test.docx");
          
[VB.NET]
doc.SaveToFile("test.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("test.docx")
          
Now, the whole process is finished. Press F5 and click the button to run the project. Check the effect.
Effective Screenshot:


As a professional and powerful Word component, Spire.Doc doesn't need Microsoft Office Word Automation but also allows user to directly operate Word document, format and style and insert content to Word document.Click to learn more feature functions of Spire.Doc



Download Spire.Doc
Purchase Spire.Doc
Thursday, 26 April 2012 06:44

How to Remove Word Sections with C#/VB.NET

A Word section break is a mark you add to show the end of a section. In Microsoft Word, we can split Word document into sections by inserting section breaks in the places where we want to start new sections. Furthermore, Word section break can be used to change the layout or formatting of a page or pages in your document. Microsoft offers easy solution to add Word section break. Click here to learn how to add section break in Word document via Spire.Doc.

However, sometimes users may want to remove some unwanted sections. By using Spire.Doc, users can also easily remove Word sections. Download and install Spire.Doc on system. Follow the simple guide below to remove Word sections with C#/VB.NET.

Friendly Reminder: Make Sure Spire.Doc and Visual Studio are correctly installed on system.

Step 1 Create a Project

Create a C# project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project. Here we will use Spire.Doc.Collections.
[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Collections;
          
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Collections
          

Step 2 Load Word Document

Use the following code to load Word document which we want to extract text from.
[C#]
            //load Word document
            Document document = new Document();
            document.LoadFromFile(@"D:\Sample.doc");
          
[VB.NET]
'load Word document
Dim document As New Document()
document.LoadFromFile("D:\Sample.doc")
          

Step 3 Remove Sections

Remove Word sections easily by using the code below.
[C#]
            //remove sections
            document.Sections.RemoveAt(0);
          
[VB.NET]
'remove sections
document.Sections.RemoveAt(0)
          

Step 4 Save

After we removed the sections, save the file as popular file formats at will.
[C#]
            //Save file
            document.SaveToFile("sample.doc", FileFormat.Doc);
          
[VB.NET]
'Save file
document.SaveToFile("sample.doc", FileFormat.Doc)
          

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. Click to learn more feature functions of Spire.Doc

 


Download Spire.Doc
Purchase Spire.Doc
Wednesday, 25 April 2012 06:12

How to Generate PDF Table in C#/VB.NET

It is easy to generate word table in C#/VB.NET with the help of Spire.Doc. It is also easy to generate PDF table in C#/VB.NET using Spire.PDF. The following section will demonstrate how to generate PDF table in C#/VB.NET. Before we can generate PDF tables in C#/VB.NET, we have to download Spire.PDF and install it on system first.

Now follow the steps to generate PDF table in your C#/VB.NET.

Step 1 Create project and add reference

Create a project in Visual Studion and add Spire.PDF dll as reference in your new project. The default folder of Spire.PDF.dll is "C:\Program Files\e-iceblue\Spire.Doc\Bin".

Step 2 Import namespace

[C#]
           using Spire.Pdf;
           using Spire.Pdf.Graphics;
           using Spire.Pdf.Tables;
[Visual Basic]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Tables
          

Step 3 Create PDF and make setting

[C#]
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
//margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter,             PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter,             PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
float y = 10;
            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;
[Visual Basic]
'Create a pdf document.
Dim doc As New PdfDocument()
'margin
Dim unitCvtr As New PdfUnitConvertor()
Dim margin As New PdfMargins()
margin.Top = unitCvtr.ConvertUnits(2.54F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point)
margin.Bottom = margin.Top
margin.Left = unitCvtr.ConvertUnits(3.17F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point)
margin.Right = margin.Left
' Create new page
Dim page As PdfPageBase = doc.Pages.Add(PdfPageSize.A4, margin)
Dim y As Single = 10
'title
Dim brush1 As PdfBrush = PdfBrushes.Black
Dim font1 As New PdfTrueTypeFont(New Font("Arial", 16F, FontStyle.Bold))
Dim format1 As New PdfStringFormat(PdfTextAlignment.Center)
page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1)
y = y + font1.MeasureString("Country List", format1).Height
y = y + 5
          

Step 4 Set PDF table’s data source

Spire.PDF enables users to generate PDF table from database and other sources. Here we take string for example.
[C#]
            String[] data
                = {
                    "Name;Capital;Continent;Area;Population",
                    "Argentina;Buenos Aires;South America;2777815;32300003",
                    "Bolivia;La Paz;South America;1098575;7300000",
                    "Brazil;Brasilia;South America;8511196;150400000",
                    "Canada;Ottawa;North America;9976147;26500000",
                    };
            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }
[Visual Basic]
Dim data As [String]() = {"Name;Capital;Continent;Area;Population", "Argentina;Buenos Aires;South America;2777815;32300003", "Bolivia;La Paz;South America;1098575;7300000", "Brazil;Brasilia;South America;8511196;150400000", "Canada;Ottawa;North America;9976147;26500000"}
Dim dataSource As [String]()() = New [String](data.Length - 1)() {}
For i As Integer = 0 To data.Length - 1
	dataSource(i) = data(i).Split(";"C)
Next
          

Step 5 Create PDF table in C#/VB.NET and set its formats

[C#]
 PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;
            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString(String.Format("* {0} countries in the list.", data.Length - 1), font2, brush2, 5, y);
[Visual Basic]
Dim table As New PdfTable()
table.Style.CellPadding = 2
table.Style.HeaderSource = PdfHeaderSource.Rows
table.Style.HeaderRowCount = 1
table.Style.ShowHeader = True
table.DataSource = dataSource
Dim result As PdfLayoutResult = table.Draw(page, New PointF(0, y))
y = y + result.Bounds.Height + 5
Dim brush2 As PdfBrush = PdfBrushes.Gray
Dim font2 As New PdfTrueTypeFont(New Font("Arial", 9F))
page.Canvas.DrawString([String].Format("* {0} countries in the list.", data.Length - 1), font2, brush2, 5, y)
          

Step 6 Save and preview

[C#]
            //Save pdf file.
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("SimpleTable.pdf");
[Visual Basic]
'Save pdf file.
doc.SaveToFile("SimpleTable.pdf")
doc.Close()
System.Diagnostics.Process.Start("SimpleTable.pdf")
          
Now Press F5 button to generate PDF table in C#.NET. Below is an effect screenshot.

Effective Screeshot


Spire.PDF is a PDF document creation component that enables your .NET applications to read, write and manipulate PDF documents without using Adobe Acrobat. Now, the new version added Silverlight platform which makes it more powerful.


Wednesday, 25 April 2012 03:48

How to Extract Text from Word Document

Sometimes we may have requirements to extract text from Word document. Get text content from Word document can be very easy if the whole content of that Word document is only paragraph text content. We can easily save Word to Text and all the text content will be extracted from Word. However, most of Word documents contain different contents which include text content such as comments, header, footer, table content, etc. If we use document.SaveToFile method to save Word to Text, we would extract all of them.

If we want to only extract paragraph text from Word document, we can also use Spire.Doc. Follow the simple guide below, we can do that job effortlessly.

Friendly Reminder: Make Sure Spire.Doc and Visual Studio are correctly installed on system.

Step 1 Create a Project

Create a C# project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
[C#]
using System;
using System.IO;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;

namespace ExtractText
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
          
[VB.NET]
Imports System.IO
Imports System.Text
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace ExtractText
	Class Program
		Private Shared Sub Main(args As String())
		End Sub
	End Class
End Namespace
          

Step 2 Load Word Document

Use the following code to load Word document which we want to extract text from.
[C#]
Document doc = new Document();
            doc.LoadFromFile(@"..\..\Test.doc",FileFormat.Doc);
          
[VB.NET]
Dim doc As New Document()
doc.LoadFromFile("..\..\Test.doc", FileFormat.Doc)
          

Step 3 Extract Text from Word Document

Here we need new a StringBuilder to extract text from Word document.
[C#]
            //new a stringBuilder to extract text from word document
            StringBuilder sb = new StringBuilder();

            //extract text from word document
            foreach (Section section in doc.Sections)
            {
                foreach (Paragraph paragraph in section.Paragraphs)
                {
                    sb.AppendLine(paragraph.Text);
                }
            }
          
[VB.NET]
'new a stringBuilder to extract text from word document
Dim sb As New StringBuilder()

'extract text from word document
For Each section As Section In doc.Sections
	For Each paragraph As Paragraph In section.Paragraphs
		sb.AppendLine(paragraph.Text)
	Next
Next
          

Step 4 Save and Preview

[C#]
            //write the text of word document into a txt file
            File.WriteAllText(@"..\..\result.txt", sb.ToString());

            //launch the text file
            System.Diagnostics.Process.Start(@"..\..\result.txt");
          
[VB.NET]
'write the text of word document into a txt file
File.WriteAllText("..\..\result.txt", sb.ToString())

'launch the text file
System.Diagnostics.Process.Start("..\..\result.txt")
          
After launch the text file, we will find only paragraph Text are extracted from Word document.

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. Click to learn more feature functions of Spire.Doc

 

Related Articles:

Download Spire.Doc
Purchase Spire.Doc
Excel page break is used to separate one worksheet into several pages for the convenience of printing. Because Excel is formed with rows and column, so users need to confirm row or column location before adding page break. Also, users can set view mode as Page Break Preview to make sure if the result satisfys you.

This guide focuses on how to insert page break in Excel and then set view mode and Page Break Preview mode by using C#/VB.NET via Spire.XLS.

Make sure Spire.XLS and Visual Studio are correctly installed. And then follow steps.

Step 1 Load Excel File

Declare a new workbook. Then load the Excel file which you want to insert page break by using workbook.LoadFromFile() method. There is one parameter passed to this method, file name string. Also, you can pass Excel version as parameter to this method. Finally, initialize worksheet.
[C#]
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"E:\work\Documents\PartSalesInfo.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
[Visual Basic]
            Dim workbook As New Workbook()
            workbook.LoadFromFile("E:\work\Documents\PartSalesInfo.xlsx")
            Dim sheet As Worksheet = workbook.Worksheets(0)
          

Step 2 Insert Page Break

There are two kinds of page break. One is horizontal page break and the other is vertical page break. Add page break by using workbook.Worksheets[0].HPageBreaks/VPageBreaks.Add() method. One parameter is passed to this method, cell range which is the beginning location which you want to insert page break.

[C#]
            workbook.Worksheets[0].HPageBreaks.Add(sheet.Range["A10"]);
            workbook.Worksheets[0].VPageBreaks.Add(sheet.Range["G1"]);
[Visual Basic]
            workbook.Worksheets(0).HPageBreaks.Add(sheet.Range("A10"))
            workbook.Worksheets(0).VPageBreaks.Add(sheet.Range("G1"))
          

Step 3 Set View Mode

In order to make sure that that page break has been added, set view mode as Page Break Preview. There are three view modes Spire.XLS provided, Layout, Normal and Preview. Assign value as ViewMode.Preview to workbook.Worksheets[0].ViewMode.

[C#]
            workbook.Worksheets[0].ViewMode = ViewMode.Preview;
[Visual Basic]
            workbook.Worksheets(0).ViewMode = ViewMode.Preview
          

Step 4 Save and Launch

Save the workbook which has been inserted page break with a new name by using workbook.SavetoFile() method. Two parameters are passed to this method, string file name and Excel version. Then, launch this file.

[C#]
            workbook.SaveToFile("ExcelPageBreak.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("ExcelPageBreak.xlsx");
[Visual Basic]
            workbook.SaveToFile("ExcelPageBreak.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("ExcelPageBreak.xlsx")
          

Effective Screeshot

Original Workbook:



After Insert Page Break:


Related Articles

Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.


<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>
Page 1 of 17