As its read only characteristic, PDF enjoys great popularity among business field. Especially, when sign contracts or send invoices, almost all the business contacts and invoices must be printed. Thus, printing PDF document pages becomes an unavoidable process, which requires a well knowledge of how to print PDF document in a quick way.

This program guide aims at introducing a method to print PDF document by a PDF Viewer component Spire.PDFViewer with C#, VB.NET.

This method enables you not only to print PDF document pages but also to open any PDF document on system via Spire.PDFViewer. That is to say, one method can open and print many PDF files. Please look at the procedure below.

Step1. Create a new project.

1.      Create a new project in Visual Studio. Please note that this project needs a Form.

2.      Set the Target Framework of This project to be .NET Framework 2 or above in Properties.

Step2. Add reference and Set up the Form.


1.      Add Spire.PDFViewer Form Dll as reference from your downloaded Spire.PDFViewer.

2.      Add a toolScript  and pdfDocumentViewer in the default Form “ Form1”.

3.      Add two buttons and a ComboBox  in Form1 from toolScript dropdown list

4.      Set the “Name”, “Display Style”, “Text” and “ToolTipText” of button1 in Properties to be “btnOpen”, “Text”, “Open” and “Open PDF document” and button2 to be “btnPrint”, “Text”,”Print” and “Print PDF document”.

5.      Set the Dock property of pdfDocumentViewer in order to view PDF file page in a enough space.

Step3. Print PDF Document Pages by PDF Viewer

1.      Add below namespaces at the top of the method.

C# Code:
using System.IO;
using Spire.PdfViewer.Forms;

VB.NET Code:
Imports System.IO
Imports Spire.PdfViewer.Forms

2.      Load a PDF document from system

C# Code:
        private void Form1_Load(object sender, EventArgs e)
        {
            string pdfDoc = @"D:\michelle\e-iceblue\Spire.PDFViewer\Demos\Data\Spire.Office.pdf";
            if (File.Exists(pdfDoc))
            {
                this.pdfDocumentViewer1.LoadFromFile(pdfDoc);
            }
        }
 
VB.NET Code:
         Private Sub Form1_Load(sender As Object, e As EventArgs)
         Dim pdfDoc As String = "D:\michelle\e-iceblue\Spire.PDFViewer\Demos\Data\Spire.Office.pdf"
                 If File.Exists(pdfDoc) Then
                     Me.pdfDocumentViewer1.LoadFromFile(pdfDoc)
                 End If
         End Sub

3.      Open the PDF document

C# Code:
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "PDF document (*.pdf)|*.pdf";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string pdfFile = dialog.FileName;
                this.pdfDocumentViewer1.LoadFromFile(pdfFile);
            }
        }
 
VB.NET Code:
         Private Sub btnOpen_Click(sender As Object, e As EventArgs)
                 Dim dialog As New OpenFileDialog()
                 dialog.Filter = "PDF document (*.pdf)|*.pdf"
                 Dim result As DialogResult = dialog.ShowDialog()
                  If result = DialogResult.OK Then
                 Dim pdfFile As String = dialog.FileName
                 Me.pdfDocumentViewer1.LoadFromFile(pdfFile)
                 End If
         End Sub

4.      Print PDF document pages by PDF Viewer

C# Code:
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                this.pdfDocumentViewer1.Print();
            }
        }
        private void pdfDocumentViewer1_PdfLoaded(object sender, EventArgs args)
        {
            this.comBoxPages.Items.Clear();
            int totalPage = this.pdfDocumentViewer1.PageCount;
            for (int i = 1; i <= totalPage; i++)
            {
                this.comBoxPages.Items.Add(i.ToString());
            }
            this.comBoxPages.SelectedIndex = 0;
        }
        private void pdfDocumentViewer1_PageNumberChanged(object sender, EventArgs args)
        {
            if (this.comBoxPages.Items.Count <= 0)
                return;
            if (this.pdfDocumentViewer1.CurrentPageNumber != this.comBoxPages.SelectedIndex + 1)
            {
                this.comBoxPages.SelectedIndex = this.pdfDocumentViewer1.CurrentPageNumber - 1;
            }
        }
        private void comBoxPages_SelectedIndexChanged(object sender, EventArgs e)
        {
            int soucePage = this.pdfDocumentViewer1.CurrentPageNumber;
            int targetPage = this.comBoxPages.SelectedIndex + 1;
            if (soucePage != targetPage)
            {
                this.pdfDocumentViewer1.GoToPage(targetPage);
            }
        }

VB.NET Code:

         Private Sub btnPrint_Click(sender As Object, e As EventArgs)
                 If Me.pdfDocumentViewer1.PageCount > 0 Then
                          Me.pdfDocumentViewer1.Print()
                 End If
         End Sub
         Private Sub pdfDocumentViewer1_PdfLoaded(sender As Object, args As EventArgs)
                  Me.comBoxPages.Items.Clear()
                 Dim totalPage As Integer = Me.pdfDocumentViewer1.PageCount
                 For i As Integer = 1 To totalPage
                          Me.comBoxPages.Items.Add(i.ToString())
                 Next
                 Me.comBoxPages.SelectedIndex = 0
                 End Sub
         Private Sub pdfDocumentViewer1_PageNumberChanged(sender As Object, args As EventArgs)
                 If Me.comBoxPages.Items.Count <= 0 Then
                         Return
                 End If
                 If Me.pdfDocumentViewer1.CurrentPageNumber <> Me.comBoxPages.SelectedIndex + 1 Then
                          Me.comBoxPages.SelectedIndex = Me.pdfDocumentViewer1.CurrentPageNumber - 1
                 End If
         End Sub
         Private Sub comBoxPages_SelectedIndexChanged(sender As Object, e As EventArgs)
                 Dim soucePage As Integer = Me.pdfDocumentViewer1.CurrentPageNumber
                 Dim targetPage As Integer = Me.comBoxPages.SelectedIndex + 1
                 If soucePage <> targetPage Then
                          Me.pdfDocumentViewer1.GoToPage(targetPage)
                 End If
         End Sub

Step4. Press F5 to launch the file.

After debugging, you can preview the effect.

Picture
The First Page
Picture
The Fourth Page
When you click the “Open” button, there will be a dialog box appears and then you can open another PDF document from system. Also, you can select any page in the dropdown list of the ComboBox and choose “Print” button to print it. Click to know more…

More Related Articles

Methods to Zoom PDF File by PDF Viewer 
 
 
An Excel pivot table is a table that can miraculously aggregate your table information and show the information in a new perspective. Pivot table enables you to move rows to columns or vice versa. Of course, the most important function of excel pivot table is to provide convenience for analyzing excel data. But the problem is that people always think that excel pivot table is difficult to create. Actually, it is not hard at all, if you do not believe it, please see the below method.

Before my method, I want to introduce an Excel component Spire.XLS to help me finish the task quickly. Spire. XLS supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.  You can Freely Install Spire.XLS on system.


How to create excel pivot table with C#, VB.NET

The whole procedure can be following steps:

Step1. Create a new project.

1.      Create a new project in Visual Studio.

2.      Set the Target Framework to be .NET Framework 2 or above in Properties.

3.      Add Spire.XLS Dll as reference.

Step2. Create excel pivot table

1.     Load an Excel file from system.

In this step, you need to create a new Excel workbook and load an excel file. There are two worksheets needed, one is for the current worksheet, the other is for pivot table worksheet, so an empty worksheet should be created. Then, name them to be “Data Source” and “Pivot Table”.

C# Code:

            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\michelle\e-iceblue\Spire.XLS\Demos\Data\DatatableSample.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Data Source";
            Worksheet sheet2 = workbook.CreateEmptySheet();
            sheet2.Name = "Pivot Table";

VB.NET Code:

         Dim workbook As New Workbook()
         workbook.LoadFromFile("D:\michelle\e-iceblue\Spire.XLS\Demos\Data\DatatableSample.xlsx")
         Dim sheet As Worksheet = workbook.Worksheets(0)
         sheet.Name = "Data Source"
         Dim sheet2 As Worksheet = workbook.CreateEmptySheet()
         sheet2.Name = "Pivot Table"

2.     Create excel pivot table

First, you should set table range according to the original data source and create a PivotCahce to save data information. Then, create a pivot table in “Pivot Table” worksheet. Finally, using sheet2.PivotTables.Add() method to assign value for excel pivot table. Three parameters passed to this method:  name string, table location and pivot cache.

C# Code:

            CellRange dataRange = sheet.Range["A1:G19"];
            PivotCache cache = workbook.PivotCaches.Add(dataRange);
            PivotTable pt = sheet2.PivotTables.Add("Pivot Table", sheet.Range["A1"], cache);

VB.NET Code:

           Dim dataRange As CellRange = sheet.Range("A1:G19")
           Dim cache As PivotCache = workbook.PivotCaches.Add(dataRange)
           Dim pt As PivotTable = sheet2.PivotTables.Add("Pivot Table", sheet.Range("A1"), cache)

Second, define row labels. You can get some data information as row labels to assign data. 

C# Code:

            var r1 = pt.PivotFields["Vendor No"];
            r1.Axis = AxisTypes.Row;
            pt.Options.RowHeaderCaption = "Vendor No";
            var r2 = pt.PivotFields["Name"];
            r2.Axis = AxisTypes.Row;
VB.NET Code:

         Dim r1 = pt.PivotFields("Vendor No")
         r1.Axis = AxisTypes.Row
         pt.Options.RowHeaderCaption = "Vendor No"
         Dim r2 = pt.PivotFields("Name")
         r2.Axis = AxisTypes.Row

Finally, add data fields and set format. Besides the fields I add in the method, you also can add some other fields in need to calculate by using pt.DataFileds.Add() method.

C# Code:

            pt.DataFields.Add(pt.PivotFields["Sales"], "Average of Sales", SubtotalTypes.Average);
            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["Population"], "Averrage of Population", SubtotalTypes.Average);
            pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12;

VB.NET Code:

           pt.DataFields.Add(pt.PivotFields("Sales"), "Average of Sales", SubtotalTypes.Average)
           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("Population"), "Averrage of Population", SubtotalTypes.Average)
           pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12


Step3. Save and launch the file

C# Code:

            workbook.SaveToFile("PivotTable.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("PivotTable.xlsx");

VB.NET Code:

            workbook.SaveToFile("PivotTable.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("PivotTable.xlsx")

Preview

Picture
Data Source
Picture
Pivot Table

More About Spire.XLS

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 allows user to operate Excel document directly such as save to stream, save as web response, copy, lock/unlock worksheet, set up workbook properties, etc. More Excel Functions

Relatd Articles:

Excel Property Setting
 
 
Conversion between different files always enjoys great popularity among people. It is also a hot and permanent topic talked about. Especially for PDF document conversion, as a most popular file format, PDF has so many advantages. So “Convert to PDF” is most concerned by people. I have talked about how to convert HTML, XML, Image, Text, Word, Excel to PDF. Now it is time to show how to save RTF file as PDF document with C#, VB.NET.

The method is the easiest way to save RTF file as PDF if you use Spire.Doc, which is an MS Word creation component and supports .NET and Silverlight. Please look at the whole procedure.

Step1. Create a new project.

1.      Create a new project in Visual Studio.

2.      Set the project Properties .Target Framework to be .NET Framework 2 or above.

3.      Add Spire.Doc dll and System.Drawing as reference in Project.

Step2. Save RTF file as PDF document.

1.       Create a new document.

2.       Load a RTF file from system.

3.       Save the RTF file as PDF document

C# Code:

            Document doc = new Document();
            doc.LoadFromFile(@"D:\michelle\JaneEyre.rtf", FileFormat.Rtf);
            doc.SaveToFile("test.pdf", FileFormat.PDF);
            System.Diagnostics.Process.Start("test.pdf");

VB.NET Code:

            Dim doc As New Document()
            doc.LoadFromFile("D:\michelle\JaneEyre.rtf", FileFormat.Rtf)
            doc.SaveToFile("test.pdf", FileFormat.PDF)
            System.Diagnostics.Process.Start("test.pdf")


Preview

Isn’t it the easiest way to convert RTF to PDF? Why not take this method  to try? You can

Freely Install Spire.Doc 

Related Article

Convert Text to PDF 
 
 
Zoom function in PDF file can help people change the text size of PDF document page according to their view preference or need. When you want to increase the percentage of the PDF file text, you can click the button of zoom out or choose the percentage number directly as well as scroll down your mouse. And if you want to zoom back to the original text size, you can click the Actual Size button. Actually, you can completely control the text percentage of the PDF document, which is much more convenient than the zoom of Excel and Word files. Now it is time to learn how to zoom PDF file by PDF Viewer with C#, VB.NET.

How to zoom PDF document by PDF Viewer with C#, VB.NET

In this article, I will introduce seven kinds of zoom functions to control PDF file text size by using a PDF Viewer component for .NET and WPF Spire.PDFViewer.  It does NOT require Adobe Reader or any other 3rd party software/library installed on system. You can have a Freely Trial of Spire.PDFViewer. The whole procedure can be finished by below steps.

Step1.  Create a new project.

1.     Create a new project in Windows Forms Application.

2.     Set the Target Framework to be .NET Framework 2 or above in Properties.

3.      Add a toolScript and pdfDocumentViewer in Form1 from Toolbox. Then, add seven buttons, two ComboBoxes and a label from the toolScript dropdown list in Form1.

4.      Set the Properties of the tools respectively. Such as the “Name”, “Display Style”, “Text” and “ ToolTipText” of buttons, ComboBoxes and label. You can set the Dock property of pdfDocumentViewer in its Properties in order to view the PDF in enough space.

Step2. Methods to zoom PDF file by Spire.PDFViewer

1.      Add Spire. PDFViewer.Forms dll as reference.

2.      Add below namespace at the top of the method.

C# Code:

using System.IO;
using System.Windows.Forms;
using Spire.PdfViewer.Forms;

3.      Zoom PDF file. In this step, I have seven kinds of zoom fuctions to control the PDF text size. They are:

Zoom: Manually choose the percentage.
Zoom Out: Increase the PDF text size.
Zoom In: Decrease the PDF text size.
Zoom Dynamic: Scroll down/up the mouse directly to change the text size. A second click can cancel zoom dynamic.
Actual Size: When you click it, the document changes to the original size.
Fit Page: Fit page control the PDF page not going across the PDF page height and margin.
Fit Width: When you click the Fit Width button, you cannot see the margin of PDF document and only see the PDF text content.

Please look at the main code:

C# Code:

namespace pdfzoom
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //private bool _isZoomout = true;
        private int _zoom = 100;
        private bool _isZoomDynamic = false;
        private void Form1_Load(object sender, EventArgs e)
        {
            string pdfDoc = @"D:\michelle\PDFViewer.pdf";
            if (File.Exists(pdfDoc))
            {
                this.pdfDocumentViewer1.LoadFromFile(pdfDoc);
            }

            //add zoom values to comboBox
            int[] intZooms = new Int32[] { 25, 50, 75, 100, 125, 150, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
            foreach (int zoom in intZooms)
            {
                this.comBoxZoom.Items.Add(zoom.ToString());
            }
            this.comBoxZoom.SelectedIndex = 3;

            //pdfDocumentViewer mouseWheel event
            this.pdfDocumentViewer1.MouseWheel += new MouseEventHandler(this.pdfDocumentViewer1_MouseWheel);
            this.pdfDocumentViewer1.LostFocus += new EventHandler(this.pdfDocumentViewer_LostFocus);
        }
        private void pdfDocumentViewer_LostFocus(Object sender, EventArgs args)
        {
            this._isZoomDynamic = false;
            this._zoom = 100;
        }
        private void pdfDocumentViewer1_MouseWheel(Object sender, MouseEventArgs args)
        {
            if (this._isZoomDynamic)
            {
                int wheelValue = (Int32)args.Delta / 24;
                this._zoom += wheelValue;
                if (this._zoom < 0)
                    this._zoom = 0;
                this.pdfDocumentViewer1.ZoomTo(this._zoom);
            }
        }
        private void btnOPen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "PDF document (*.pdf)|*.pdf";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                try
                {
                    string pdfFile = dialog.FileName;
                    this.pdfDocumentViewer1.LoadFromFile(pdfFile);
                }
                catch (Exception exe)
                {
                    MessageBox.Show(exe.Message, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void comBoxZoom_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                int zoomValue = Int32.Parse(this.comBoxZoom.SelectedItem.ToString());
                this.pdfDocumentViewer1.ZoomTo(zoomValue);
            }
        }
        private void btnZoomOut_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                int delta = 10;
                this._zoom += delta;
                this.pdfDocumentViewer1.ZoomTo(this._zoom);
            }
        }
        private void btnZoonIn_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                int delta = 5;
                this._zoom -= delta;
                if (this._zoom < 0)
                    this._zoom = 0;
                this.pdfDocumentViewer1.ZoomTo(this._zoom);
            }
        }
        private void btnActural_Click(object sender, EventArgs e)
        {
            this._zoom = 100;
            this._isZoomDynamic = false;
            this.btnDynamic.Text = "Zoom Dynamic";
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                this.pdfDocumentViewer1.ZoomTo(100);
                this.comBoxZoom.SelectedIndex = 3;
            }
        }
        private void btnFitPage_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                this.pdfDocumentViewer1.ZoomTo(ZoomMode.FitPage);
            }
        }
        private void btnFitWidth_Click(object sender, EventArgs e)
        {
            if (this.pdfDocumentViewer1.PageCount > 0)
            {
                this.pdfDocumentViewer1.ZoomTo(ZoomMode.FitWidth);
            }
        }
        private void btnDynamic_Click(object sender, EventArgs e)
        {
            this._isZoomDynamic = !this._isZoomDynamic;
            if (this._isZoomDynamic)
            {
                this.btnDynamic.Text = "Cancel dynamic zoom";
                this.btnDynamic.ToolTipText = "Cancel dynamic zoom";
            }
            else
            {
                this.btnDynamic.Text = "Zoom dynamic";
                this.btnDynamic.ToolTipText = "Zoom dynamic";
            }
        }

        private void pdfDocumentViewer1_PdfLoaded(object sender, EventArgs args)
        {
            this.btnDynamic.Enabled = true;
            this.comBoxPages.Items.Clear();
            int totalPage = this.pdfDocumentViewer1.PageCount;
            for (int i = 1; i <= totalPage; i++)
            {
                this.comBoxPages.Items.Add(i.ToString());
            }
            this.comBoxPages.SelectedIndex = 0;
        }
        private void pdfDocumentViewer1_PageNumberChanged(object sender, EventArgs args)
        {
            if (this.comBoxPages.Items.Count <= 0)
                return;
            if (this.pdfDocumentViewer1.CurrentPageNumber != this.comBoxPages.SelectedIndex + 1)
            {
                this.comBoxPages.SelectedIndex = this.pdfDocumentViewer1.CurrentPageNumber - 1;
            }
        }
        private void comBoxPages_SelectedIndexChanged(object sender, EventArgs e)
        {
            int soucePage = this.pdfDocumentViewer1.CurrentPageNumber;
            int targetPage = this.comBoxPages.SelectedIndex + 1;
            if (soucePage != targetPage)
            {
                this.pdfDocumentViewer1.GoToPage(targetPage);
            }
        }
        private void comBoxPages_Click(object sender, EventArgs e)
        {
        }
    }
}

Note: 1. If you click the buttons and they cannot operate the zoom functions, please check the click event of each button.

            2. When the ComboBox cannot show page number in the dropdown list, pleae check the SelectedIndexChanged event of it.

Preview

Picture
Form1
Picture
Zoom Percentage
Picture
Dynamic Zoom
Picture
Fit Width
As above picture, you can easily control the whole PDF document pages by the methods that I introduced by using Spire.PDF Viewer. Spire.PDFViewer not only enables you to open a PDF document that you load from system in the code, but also allows you to open any other PDF file by clicking the Open button in Form1, and then, choose it from a dialog box. You also can choose which page you want to view or read in the dropdown list. Why not give it a try?

Spire.PDFViewer for WPF
 
 
On May 11, 2012, a new professional and all-in-one PDF Viewer component for WPF was published by E-iceblue Co., Ltd. E-iceblue is a vendor of .NET, Silverlight and WPF components. The goal of e-iceblue is always to offer high-quality components for reading and writing different formats of office files.

Two months ago, E-iceblue published a .NET PDF Viewer component which enables developers to load and view different PDF documents from file, stream and byte array. Compare with the .NET edition, Spire.PDFViewer for WPF can also do that jobs perfectly but only for WPF platform. Spire.PDFViewer for WPF is another standalone component developed by e-iceblue. It’s a totally independent WPF library and does NOT require Adobe Reader or any other 3rd party software/library installed on system.

As a professional and powerful WPF PDF Viewer, Spire.PDFViewer for WPF allows developers to display PDF documents with their WPF applications without Adobe Acrobat. It’s available to load and view encrypted PDF documents and all standard PDF/A-1B, PDF/X1A files from stream, file and byte array with support for printing, zooming, etc. This WPF PDF Viewer component supports multiple printing orientation including landscape, portrait and automatic. It enables WPF applications to export PDF to images and save as popular formats like .bmp, .png and .jpeg. When users view PDF documents through this PDF Viewer component, they can set display as fit page, page down/up, zoom in/out, etc.

All in all, Spire.PDFViewer for WPF includes most of normal daily used PDF viewing functions. It’s new in the market with a lower price compare with other similar components. It’s worth to give a shot or at least a free trial. 

Free Trial Download 

Main Features:

1.         Load PDF from file, stream and byte array

2.         Support PDF/A-1B, PDF/X1A

3.         Enable to open and read encrypted PDF files

4.         Support multiple printing orientations: landscape, portrait, automatic

5.         Export PDFs to Image format as .bmp, .png, .jpeg

6.         Set PDF page (page down/up, zoom in/out, display as fit page)

7.         Support most PDF font including TrueType, Type0, Type1, Type3, OpenType and CJK font

8.         Support Filled text, Clipped Text, Stroked Text, and support lines, curve and table in PDF

9.         Support hyperlink and DeviceN color space in PDF

10.     Support JPEG2000, DCT, CCITT Fax Image format in PDF

 

More about Spire.PDFViewer for WPF


About e-iceblue

E-iceblue Co., Ltd. is a vendor of .NET, Silverlight and WPF components. The goal of e-iceblue is always to offer high-quality components for reading and writing different formats of office files. E-iceblue components have been widely-used by most of the Fortune 500 corporations. The key developers of e-iceblue have over 10 years of combined experience developing high-performance, high-quality .net component technology. Everyday, e-iceblue products help a large number of developers from large/small companies in more than sixty countries to easier, better, faster and to be more productive develop and deliver reliable applications to their customers.


Contact Us

Address: Room 811, Soar International Building, No. 130, 1st Ring Road West Section 1, Chengdu, Sichuan, China

Contact via email:

Sales@e-iceblue.com

Support@e-iceblue.com

 
 
Page border is just like our photo frame if we compare the word document to a photo. A lovely photo frame can beautify the outward appearance of a photo. By the same token, attractive page border can embellish the word document in a different way. Do you still remember your diploma in university? The border of your degree certificate looks dignified and distinctive. Different page border can be used in different cases. That is the effect of page border. Now let us look at how to insert page border in Word document with C#, VB.NET.


How to insert page border in word document with C#, VB.NET

When I operate my word document, Spire.Doc always gives me best help to finish the task in minutes. It is an MS Word component, which supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. Why not give it a try to Freely Install Spire.Doc on system?

Step1. Create a new project.

1.     Create a new project in Visual Studio.

2.     Set the Target Framework to be .NET Framework 4 in Properties.

3.     Add Spire.Doc DLL as reference in Project.


Step2. Insert page border in word document.

1.     Create a word document and add section in it.

C# Code:

            //create a new document
            Document doc = new Document();
            Section section = doc.AddSection();

VB.NET Code:

          'create a new document
           Dim doc As New Document()
           Dim section As Section = doc.AddSection()

2.     Add text in Word document

C# Code:

            // 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");

VB.NET Code:

          ' 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)

3.     Insert page border in word

C# Code:

            //insert page border
            section.PageSetup.Borders.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;

VB.NET Code:
           'insert page border
            section.PageSetup.Borders.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave


Step3. Save and launch the file.

C# Code:

            //save and luanch
            doc.SaveToFile("test.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("test.docx");

VB.NET Code:

           'save and luanch
            doc.SaveToFile("test.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("test.docx")


Preview


The page border can be changed according to your own need, the page border in above picture is only one. So why not try?

More Word Functions


Popular Word Posts:

Convert Html to Word
 
 
Find and replace function in Word gains great popularity when people want to replace a certain word or phrase in a long document. If there is no word find and replace function, it may cost hours for people to find and replace word content without making mistakes. But time will be limited to minutes if you find and replace words or phrases by using C#, VB.NET. Now let us look at how to find and replace word content with C#, VB.NET.


How to find and replace word content with C#, VB.NET

Before I start, I have to introduce my best hand Spire.Doc, which is a professional MS Word component, to help me finish this task. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. You can have a free trial of Spire.Doc and no time limit. Using Spire.Doc, I need three steps to realize the whole task.

Step1: Create a new project

1.      Create a new project in Visual Studio.

2.      Set the Target Framework in Properties to be .NET Framework 2 or above.

3.      Add Spire.Doc Dll as reference.


Step2. Find and Replace word content with C#, VB.NET

1.    Load a word document from system.

C# Code:

            //Create word document
            Document document = new Document();

            //Load a file
            document.LoadFromFile(@"D:\michelle\JaneEyre.doc");
 

VB.NET Code:

        'Create word document
        Dim document As New Document()
        'Load file
        document.LoadFromFile(@"D:\michelle\JaneEyre.doc")

2.     Find and replace word text 

C# Code:

            //Replace text
            document.Replace("Jane Eyre", "Jane Eyre Novel", true, true);
            document.Replace("character", "characteristic", true, true);
VB.NET Code:

           'Replace text
            document.Replace("Jane Eyre", "Jane Eyre Novel", true, true)
            document.Replace("character", "characteristic", true, true)
Step3. Save and launch the file.

 C# Code:

            //Save doc file.
            document.SaveToFile("Sample.doc", FileFormat.Doc);
            //Launching the MS Word file.
            System.Diagnostics.Process.Start("Sample.doc");

VB.NET Code:

                'Save doc file.
                 document.SaveToFile("Sample.doc", FileFormat.Doc)

               'Launch the file.
                System.Diagnostics.Process.Start("Sample.doc")

Preview

Picture
Original Document
Picture
Find and Replace Word Content
From the two pictures above, you obviously find that ”Jane Eyre” has been replaced by “ Jane Eyre Novel” and “character” has been replaced by “ characteristic”. The whole procedure can be very easy. Use the document.Replace("the word you want to replace", "the final word you want", true, true) method, you can replace any word or phrase in the text according to your need.

More Word Functions

You May be also interested in:

How to Find and Highlight Word Information 
 
 
I have talked about the way to export data table from database to PDF and set table format long ago. Of course, when we already have tables in our database, it is unnecessary to draw PDF tables in that exporting table directly to PDF file is very convenient. But if we do not have a table in PDF document, we have to draw tables in PDF file. So this article aims at recommending another method to draw PDF table with C#, VB.NET.

How to draw PDF simple table with C#, VB.NET

I use a .net PDF creation component Spire.PDF to help me realize this task as usual. It supports .NET and Silverlight. In order to be convenient, you can Freely Install Spire.PDF in your system. This component has no time limit in use. Using it, I can draw a simple PDF table in the following three steps.

Step1. Create a new project.

1.      Create a new project in Visual Studio and set its Target Framework to be .NET Framework4.

2.       Add Spire.PDF DLL and System Drawing as references.

3.      Import namespace as below:

C# Code:
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Tables;

VB.NET Code:

Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Tables

Step2. Generate PDF simple table

1.      Create a PDF document and draw table title as well as title format.
C# Code:

            //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;

VB.NET Code:

'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


2.      Set PDF table’s data Source

C# Code:

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(';');
            }

VB.NET Code:

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

3.      Draw PDF table and set table format.

C# Code:

            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);

VB.NET Code:

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)

Step3. Save and launch the file

C# Code:
            //Save pdf file.
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("SimpleTable.pdf");

VB.NET Code:

'Save pdf file.
doc.SaveToFile("SimpleTable.pdf")
doc.Close()
System.Diagnostics.Process.Start("SimpleTable.pdf")


Preview


The above method is a way to generate a simple PDF table with C#, VB.NET. If you want to create FormField in PDF or insert other objectives, that is OK. I think you can find them in below webpage.

More functions of Spire.PDF


Related Articles

Attach Word, Excel, Text, TTF Files and Images in PDF
 
 
An Excel document may contain multiple worksheets. Sometimes in order to be convenient, we need to merge two or more Excel files into one Excel document. Since a single Excel file is easy to save and read. Imagine that you have five Excel files. You have to open five windows in order to get the information of each, which is very likely to mix and make mistakes. But things become different if you merge these files into one Excel document. Now, let us look at how to merge Excel files with C#, VB.NET.

In my method, I merge three Excel files into one. The Excel component that I use is Spire.XLS. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. If necessary, you can Freely Install Spire.XLS on your system.


How to merge multiple Excel files into one document with C#, VB.NET

Using Spire.XLS, I only need three simple steps to realize the whole task in minutes. Please look at the below procedure.

Step1. Create a new project

1.      Create a new project in Visual Studio.

2.      Set the Target Framework in Property to be .NET Framework 2 or above.

3.      Add Spire.XLS DLL as reference.

Step2. Merge multiple Excel files into one document

1.      Load Excel files from system

C# Code:

            //load the first workbook
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"E:\Data\parts.xls", ExcelVersion.Version97to2003);

            //load the second workbook
            Workbook workbook2 = new Workbook();
            workbook2.LoadFromFile(@"E:\Data\country.xls", ExcelVersion.Version97to2003);

            //load the third workbook
            Workbook workbook3 = new Workbook();
            workbook3.LoadFromFile(@"E:\Data\excel.xls", ExcelVersion.Version97to2003);

VB.NET Code:

           'load the first workbook
            Dim workbook As New Workbook()
            workbook.LoadFromFile("E:\Data\parts.xls", ExcelVersion.Version97to2003)

            'load the second workbook
            Dim workbook2 As New Workbook()
            workbook2.LoadFromFile("E:\Data\country.xls", ExcelVersion.Version97to2003)

            'load the third workbook

             Dim workbook3 As New Workbook()
             workbook3.LoadFromFile("E:\Data\excel.xls", ExcelVersion.Version97to2003)

2.      Merge three Excel files loaded from system into one document

C# Code:

            //insert the second workbook's worksheet into the first workbook using dataTable
            Worksheet sheet2 = workbook2.Worksheets[0];
            DataTable dataTable = sheet2.ExportDataTable();
            Worksheet sheetAdd = workbook.CreateEmptySheet("Country");
            sheetAdd.InsertDataTable(dataTable, true, 1, 1);

            //insert the third workbook's worksheet into the first workbook using dataTable2
            Worksheet sheet3 = workbook3.Worksheets[0];
            DataTable dataTable2 = sheet3.ExportDataTable();
            Worksheet sheetAdd2= workbook.CreateEmptySheet("Excel");
            sheetAdd2.InsertDataTable(dataTable2, true, 1, 1);

VB.NET Code:

           'insert the second workbook's worksheet into the first workbook using the dataTable
            Dim sheet2 As Worksheet = workbook2.Worksheets(0)
            Dim dataTable As DataTable = sheet2.ExportDataTable()
            Dim sheetAdd As Worksheet = workbook.CreateEmptySheet("Country")
            sheetAdd.InsertDataTable(dataTable, True, 1, 1)

            'insert the third workbook's worksheet into the first workbook using dataTable2
            Dim sheet3 As Worksheet = workbook3.Worksheets(0)
            Dim dataTable2 As DataTable = sheet3.ExportDataTable()
            Dim sheetAdd2 As Worksheet = workbook.CreateEmptySheet("Excel")
            sheetAdd2.InsertDataTable(dataTable2, True, 1, 1)

Step3. Save and Launch the file.

C# Code:

            //save the workbook
            workbook.SaveToFile("cellsMerge.xls", ExcelVersion.Version97to2003);

            //launch the workbook
            System.Diagnostics.Process.Start("cellsMerge.xls");

VB.NET Code:

           'save the workbook
           workbook.SaveToFile("cellsMerge.xls", ExcelVersion.Version97to2003)

           'launch the workbook
           System.Diagnostics.Process.Start("cellsMerge.xls")


As you see, the whole task can be very easy by using Spire.XLS. If you have more than three excel files you need to merge, you also can add another children step in Step2. Please note that the above method is just merge the data information of three excel files into one excel document. The Excel data format such as hyperlink, font color, background color and so on will not be merged into the final Excel document.  

More Excel Functions




You can also find this post in http://www.dotnetfunda.com.
 
 
Excel document property is just like the background of a person. When we want to know a person, the basic information is very necessary, such as his name, his hometown, his work and so on. So is the excel document. Excel file property can tell us additional information of this document, such as author, created time, modified time, its size, its title, tags and categories. Actually, you also can set manager, subject, comments, hyperlink base. While how to set excel property with C#, VB.NET? Please look at the below paragraphs.


How to set Excel property with C#, VB.NET?

By using Spire.XLS, I only use three simple steps to finish the Excel property setting task in minutes with C#, VB.NET. Spire.XLS is an independent powerful Excel component. You also can Freely Install Spire.XLS in your system. Please follow the below steps.

Step1. Create a new project.

1.      Create a new project in Visual Studio and set the Target Framework to be .NET Framework 2 or above.

2.      Add Spire.Xls DLL as reference.


Step2. Set Excel property.

1.      Create a new excel workbook and load an excel file from system.

C# Code:

            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\michelle\comment.xlsx");

VB.NET Code:
         Dim workbook As New Workbook()
         workbook.LoadFromFile("D:\michelle\ comment.xlsx")

 

2.      Set Excel property.
C# Code:
            workbook.DocumentProperties.Author = "E-iceblue Support Team";
            workbook.DocumentProperties.Title = "Properties Demo";
            workbook.DocumentProperties.Keywords = "Excel Properties C#, Excel Properties VB.NET";
            workbook.DocumentProperties.Category = "Excel Demo";
            workbook.DocumentProperties.Company = "E-iceblue";

VB.NET Code:
         workbook.DocumentProperties.Author = "E-iceblue Support Team"
         workbook.DocumentProperties.Title = "Properties Demo"
         workbook.DocumentProperties.Keywords = "Excel Properties C#, Excel Properties VB.NET"
         workbook.DocumentProperties.Category = "Excel Demo"
         workbook.DocumentProperties.Company = "E-iceblue"

Step3. Save and launch the file.

C# Code:

            workbook.SaveToFile("Properties.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Properties.xlsx");

VB.NET Code:          
         
          workbook.SaveToFile("Properties.xlsx", ExcelVersion.Version2010)
          System.Diagnostics.Process.Start("Properties.xlsx")


Preview


As you see, setting Excel property with C#, VB.NET is really as simple as setting it directly in the Excel document. Spire.xls can help you realize the Excel Functions in a quick and simple way with C#, VB.NET.

 

Related Articles

How to Set PDF Property