page 248

Zoom is a basic as well useful function in any text file reader. Users can chose to zoom out or zoom in of a document depending on how small the font is, or on their own view preference. In this article, I’ll introduce two ways to zoom Word file using Spire.DocViewer:

  • Zoom with a particular zoom mode
  • Zoom by entering a percentage

Now, I will explain more by creating a Windows Forms Application. Some steps about how to add DocVierwer control to toolbox and how to open Word file using Spire.DocViewer have been demonstrated previously. In the following section, I only add a MenuItem and a TextBox to Form1.

In the MenuItem, named Zoom, I create three sub-items which are used to save three particular zoom modes.

  • Default: View page in its original size.
  • Fit to page: When this option is selected, the document will be resized to match the dimensions of your view window.
  • Fit to width: When this option is selected, the document will best fit to width of window.

Code behind:

        private void defaultToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.docDocumentViewer1.ZoomMode = ZoomMode.Default;
        }
        private void fitToPageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.docDocumentViewer1.ZoomMode = ZoomMode.FitPage;
        }
        private void fitToWidthToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.docDocumentViewer1.ZoomMode = ZoomMode.FitWidth;
        }

Another way to zoom in or out of Word document is enter a desired percentage in TextBox.

Code for TextBox:

      private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (Keys.Enter == e.KeyCode)
            {
                int p;
                if (int.TryParse(this.toolStripTextBox1.Text, out p))
                {
                    this.docDocumentViewer1.ZoomTo(p);
                }
            }
        }

Run the program, you can get following windows application.

Zoom Word Document using Spire.DocViewer

Fit to Width:

Zoom Word Document using Spire.DocViewer

Zoom with 50 percentages:

Zoom Word Document using Spire.DocViewer

Add underline text in PDF in C#

2014-12-23 08:15:41 Written by Koohji

Adding text into the PDF files is one of the most important requirements for developers. With the help of Spire.PDF, developer can draw transform text, alignment text and rotate text in PDF files easily. This tutorial will show you how to add underline text in C#.

By using the method canvas.drawstring offered by Spire.PDF, developers can set the position, font, brush and style for the adding texts. With the PdfFontStyle, developers can set the style to underline, bold, italic, regular and strikeout. Here comes to the code snippet of how to add underline text in PDF.

Step 1: Create a new PDF document.

PdfDocument pdf = new PdfDocument();

Step 2: Add a new page to the PDF file.

PdfPageBase page = pdf.Pages.Add();

Step 3: Create a true type font with size 20f, underline style.

PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);

Step 4: Create a blue brush.

PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

Step 5: Draw the text string at the specified location with the specified Brush and Font objects.

page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));

Step 6: Save the PDF file.

pdf.SaveToFile("Result.pdf", FileFormat.PDF);

Effective screenshot:

How to add underline text in PDF in C#

Full codes:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace AddUnderlinetext
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
            PdfTrueTypeFont font = new PdfTrueTypeFont(@"C:\WINDOWS\Fonts\CONSOLA.TTF", 20f, PdfFontStyle.Underline);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            page.Canvas.DrawString("Hello E-iceblue Support Team", font, brush, new PointF(10, 10));
            pdf.SaveToFile("Result.pdf", FileFormat.PDF);
        }
    }
}

Built-in table styles are predefined formatting options that can be quickly applied to any table, greatly enhancing its appearance and readability. As same as MS PowerPoint, Spire.Presentation provides such a feature to give your table a professional look by applying a certain built-in table style. This article presents how this purpose can be achieved using Spire.Presentation with C#, VB.NET.

As we can see from below picture, plain tale is not that attractive before applying any style.

How to Apply Built-in Style to PowerPoint Table in C#, VB.NET

Code Snippet for Applying Table Style:

Step 1: Create an instance of presentation and load the test file.

Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);

Step 2: Get the table from presentation slide.

ITable table = ppt.Slides[0].Shapes[1] as ITable;

Step 3: Choose one table style from TableStylePreset and apply it to selected table.

table.StylePreset = TableStylePreset.MediumStyle2Accent2;

Step 4: Save the file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Output:

How to Apply Built-in Style to PowerPoint Table in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;

namespace Apply_Built_in_Style
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);
            ITable table = ppt.Slides[0].Shapes[1] as ITable;
            table.StylePreset = TableStylePreset.MediumStyle2Accent2;
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }

    }
}
[VB.NET]
Imports Spire.Presentation

Namespace Apply_Built_in_Style

	Class Program

		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation("test.pptx", FileFormat.Pptx2010)
			Dim table As ITable = TryCast(ppt.Slides(0).Shapes(1), ITable)
			table.StylePreset = TableStylePreset.MediumStyle2Accent2
			ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010)

		End Sub

	End Class
End Namespace
page 248