The table of contents plays a critical role in enhancing the readability and navigability of a document. It provides readers with a clear overview of the document's structure and enables them to quickly locate and access specific sections or information they are interested in. This can be especially valuable for longer documents, such as reports, books, or academic papers, where readers may need to refer back to specific sections or chapters multiple times. In this article, we'll explore how to create a table of contents in a PDF document in C# and VB.NET using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Create a Table of Contents in PDF in C# and VB.NET

A table of contents mainly includes the TOC title (e.g. Table of Contents), TOC content, page numbers, and actions that will take you to the target pages when clicked on. To create a table of contents in PDF using Spire.PDF for .NET, you can follow these steps:

  • Initialize an instance of the PdfDocument class.
  • Load a PDF document using PdfDocument.LoadFromFile() method.
  • Get the page count of the document using PdfDocument.Pages.Count property.
  • Insert a new page into the PDF document as the first page using PdfDocument.Pages.Insert(0) method.
  • Draw the TOC title, TOC content, and page numbers on the page using PdfPageBase.Canvas.DrawString() method.
  • Create actions using PdfActionAnnotation class and add the actions to the page using PdfNewPage.Annotations.Add() method.
  • Save the result document using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.Annotations;
using Spire.Pdf.General;
using Spire.Pdf.Graphics;
using System;
using System.Drawing;

namespace TableOfContents
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the PdfDocument class
            PdfDocument doc = new PdfDocument();
            //Load a PDF document
            doc.LoadFromFile("Sample.PDF");

            //Get the page count of the document
            int pageCount = doc.Pages.Count;

            //Insert a new page into the pdf document as the first page
            PdfPageBase tocPage = doc.Pages.Insert(0);

            //Draw TOC title on the new page
            string title = "Table of Contents";
            PdfTrueTypeFont titleFont = new PdfTrueTypeFont(new Font("Arial", 20, FontStyle.Bold));
            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            PointF location = new PointF(tocPage.Canvas.ClientSize.Width / 2, titleFont.MeasureString(title).Height + 10);
            tocPage.Canvas.DrawString(title, titleFont, PdfBrushes.CornflowerBlue, location, centerAlignment);

            //Draw TOC content on the new page
            PdfTrueTypeFont titlesFont = new PdfTrueTypeFont(new Font("Arial", 14));
            String[] titles = new String[pageCount];
            for (int i = 0; i < titles.Length; i++)
            {
                titles[i] = string.Format("This is page {0}", i + 1);
            }
            float y = titleFont.MeasureString(title).Height + 10;
            float x = 0;

            //Draw page numbers of the target pages on the new page
            for (int i = 1; i <= pageCount; i++)
            {
                string text = titles[i - 1];
                SizeF titleSize = titlesFont.MeasureString(text);

                PdfPageBase navigatedPage = doc.Pages[i];

                string pageNumText = (i + 1).ToString();
                SizeF pageNumTextSize = titlesFont.MeasureString(pageNumText);
                tocPage.Canvas.DrawString(text, titlesFont, PdfBrushes.CadetBlue, 0, y);
                float dotLocation = titleSize.Width + 2 + x;
                float pageNumlocation = tocPage.Canvas.ClientSize.Width - pageNumTextSize.Width;
                for (float j = dotLocation; j < pageNumlocation; j++)
                {
                    if (dotLocation >= pageNumlocation)
                    {
                        break;
                    }
                    tocPage.Canvas.DrawString(".", titlesFont, PdfBrushes.Gray, dotLocation, y);
                    dotLocation += 3;
                }
                tocPage.Canvas.DrawString(pageNumText, titlesFont, PdfBrushes.CadetBlue, pageNumlocation, y);

                //Add actions that will take you to the target pages when clicked on to the new page
                location = new PointF(0, y);
                RectangleF titleBounds = new RectangleF(location, new SizeF(tocPage.Canvas.ClientSize.Width, titleSize.Height));
                PdfDestination Dest = new PdfDestination(navigatedPage, new PointF(-doc.PageSettings.Margins.Top, -doc.PageSettings.Margins.Left));
                PdfActionAnnotation action = new PdfActionAnnotation(titleBounds, new PdfGoToAction(Dest));
                action.Border = new PdfAnnotationBorder(0);
                (tocPage as PdfNewPage).Annotations.Add(action);
                y += titleSize.Height + 10;
            }

            //Save the result pdf document
            doc.SaveToFile("AddTableOfContents.pdf");
            doc.Close();
        }
    }
}

C#/VB.NET: Create a Table of Contents (TOC) in PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Sometimes we may need to re-encrypt the document whose password has been or is at the risk of being leaked out. This article will show you how to load an encrypted PowerPoint document and modify its password using Spire.Presentation.

Code Snippet:

Step 1: Create an object of Presentation class.

Presentation presentation = new Presentation();

Step 2: Load an encrypted PowerPoint document into the Presentation object.

presentation.LoadFromFile("Encrypted.pptx",FileFormat.Pptx2010, "oldPassword");

Step 3: Remove the encryption.

presentation.RemoveEncryption();

Step 4: Protect the document by setting a new password.

presentation.Protect("newPassword");

Step 5: Save the file.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);

Full Code:

[C#]
using Spire.Presentation;
namespace ModifyPassword
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Encrypted.pptx", FileFormat.Pptx2010, "oldPassword");

            presentation.RemoveEncryption();
            presentation.Protect("newPassword");

            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);

        }
    }
}
[VB.NET]
Imports Spire.Presentation
Namespace ModifyPassword

	Class Program

		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
			presentation.LoadFromFile("Encrypted.pptx", FileFormat.Pptx2010, "oldPassword")

			presentation.RemoveEncryption()
			presentation.Protect("newPassword")

			presentation.SaveToFile("result.pptx", FileFormat.Pptx2010)

		End Sub
	End Class
End Namespace

Spire.Presentation as a powerful PowerPoint library, enables developers to create SmartArt, add text to SmartArt and format SmartArt in a flexible way (Reference: How to Create and Format SmartArt in PowerPoint in C#, VB.NET). In this article, we will further introduce how to extract text from SmartArt in PowerPoint in C# and VB.NET by using Spire.Presentation for .NET.

Please look at the appearance of the sample PPT file first:

How to Extract Text from SmartArt in PowerPoint in C#, VB.NET

Detail steps and code snippets are as below:

Step 1: Create a new instance of Presentation class and load the sample PPT file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx");

Step 2: Create a new instance of StringBulider class, traverse through all the slides of the PPT file, find the SmartArt shapes, and then extract text from SmartArt shape Nodes and append to the StringBuilder object.

StringBuilder st = new StringBuilder();
for (int i = 0; i < ppt.Slides.Count; i++)
{
    for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
    {
        if (ppt.Slides[i].Shapes[j] is ISmartArt)
        {
            ISmartArt smartArt = ppt.Slides[i].Shapes[j] as ISmartArt;
            for (int k = 0; k < smartArt.Nodes.Count; k++)
            {
                st.Append(smartArt.Nodes[k].TextFrame.Text);
            }
        }
    }
}

Step 3: Create a new text file and write the extracted text to the text file.

File.WriteAllText("Result.txt", st.ToString());

The result text file:

How to Extract Text from SmartArt in PowerPoint in C#, VB.NET

Full codes:

[C#]
using System.IO;
using System.Text;
using Spire.Presentation;
using Spire.Presentation.Diagrams;

namespace Extract_text_from_SmartArt_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx");

            StringBuilder st = new StringBuilder();
            for (int i = 0; i < ppt.Slides.Count; i++)
            {
                for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
                {
                    if (ppt.Slides[i].Shapes[j] is ISmartArt)
                    {
                        ISmartArt smartArt = ppt.Slides[i].Shapes[j] as ISmartArt;
                        for (int k = 0; k < smartArt.Nodes.Count; k++)
                        {
                            st.Append(smartArt.Nodes[k].TextFrame.Text);
                        }
                    }
                }
            }
            File.WriteAllText("Result.txt", st.ToString());
       }
    }
}
[VB.NET]
Imports System.IO
Imports System.Text
Imports Spire.Presentation
Imports Spire.Presentation.Diagrams

Namespace Extract_text_from_SmartArt_in_PPT
	Class Program
		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation()
			ppt.LoadFromFile("Sample.pptx")

			Dim st As New StringBuilder()
			For i As Integer = 0 To ppt.Slides.Count - 1
				For j As Integer = 0 To ppt.Slides(i).Shapes.Count - 1
					If TypeOf ppt.Slides(i).Shapes(j) Is ISmartArt Then
						Dim smartArt As ISmartArt = TryCast(ppt.Slides(i).Shapes(j), ISmartArt)
						For k As Integer = 0 To smartArt.Nodes.Count - 1							st.Append(smartArt.Nodes(k).TextFrame.Text)
						Next
					End If
				Next
			Next
			File.WriteAllText("Result.txt", st.ToString())
		End Sub
	End Class
End Namespace

Draw right to left text on PDF in C#

2016-06-28 09:07:38 Written by Koohji

With the help of Spire.PDF, developers can easily draw texts on the PDF files in C#. We have already introduced how to draw text in PDF with different styles. Usually the texts are left to right format, for some languages, such as Hebrew, Arabic, etc. the texts are from right to left. Spire.PDF offers a property to enable developers to set RightToLeft as true to draw right to left text on PDF in C#. Here comes to the steps of how to draw the Hebrew texts from right to left.

Step 1: Define the text string in Hebrew:

string value = "וַיֹּאמֶר אֱלֹהִים, יְהִי אוֹר; וַיְהִי-אוֹר.";

Step 2: Create a new PDF document.

PdfDocument doc = new PdfDocument();

Step 3: Add a new page to the PDF document.

PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins());

Step 4: Set the font and position for the text.

PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Alef-Regular.ttf", 16f, FontStyle.Bold), true);
RectangleF labelBounds = new RectangleF(20, 20, 400, font.Height);

Step 5: Draw the text and set the value to indicate the text direction mode.

page.Canvas.DrawString(value, font, PdfBrushes.Black, labelBounds, new PdfStringFormat() { RightToLeft = true });

Step 6: Save the document to file.

doc.SaveToFile("result.pdf");

Effective screenshot:

How to draw right to left text on PDF in C#

Full codes:

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


namespace RightToLeftText
{
    class Program
    {
        static void Main(string[] args)
        {
            string value = "וַיֹּאמֶר אֱלֹהִים, יְהִי אוֹר; וַיְהִי-אוֹר.";
            PdfDocument doc = new PdfDocument();

            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins());

            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Alef-Regular.ttf", 16f, FontStyle.Bold), true);

            RectangleF labelBounds = new RectangleF(20, 20, 400, font.Height);
            page.Canvas.DrawString(value, font, PdfBrushes.Black, labelBounds, new PdfStringFormat() { RightToLeft = true });

            labelBounds = new RectangleF(20, 50, 400, font.Height);
            page.Canvas.DrawString(value, font, PdfBrushes.Black, labelBounds, new PdfStringFormat() { RightToLeft = false });

            doc.SaveToFile("result.pdf");
        }
    }
}

When working with spreadsheets, you may find that certain cells contain combined information that need to be split for further sorting, filtering, or analyzing. MS Excel provides the “Text to Columns” feature to help users handle such situation, but manually processing large datasets is tedious and error prone. Using Spire.XLS, a robust .NET library, you can automate splitting data into columns efficiently.

This article will guide you through the process of splitting Excel data into multiple columns with C#, saving you time and ensuring accuracy.

Why Use Spire.XLS for Splitting Excel Data?

  • No Office Dependency: Manipulate Excel files without installing Microsoft Office.
  • Rich Features: Beyond splitting data, Spire.XLS also allows to edit, format, or export split data to other formats.
  • .NET Integration: Seamlessly embed Excel automation into .NET applications.

How to Install the .NET Excel Library?

To follow along with the examples in this article, you'll need to have the Spire.XLS for .NET library installed. The product package can be downloaded from the official website and then imported manually. Or you can install it directly via NuGet:

PM> Install-Package Spire.XLS

Split Excel Data into Multiple Columns with C# (Steps & Code)

With Spire.XLS, you can first retrieve the content in a cell, then split the cell content based on specific delimiter, and finally write the split data into different columns. The detailed steps are as follows:

  • Load Excel and get a worksheet.
    • Create a Workbook object and use its LoadFromFile() method to load an Excel file.
    • Access a specified worksheet through the Workbook.Worksheets[index] property.
  • Retrieve and split cell data.
    • Iterate through each row in the sheet.
    • Access a specified cell and then get its content using the CellRange.Text property.
    • Call the string.Split(params char[] separator) method to split the content based on a specified separator (e.g., comma, space, semicolon, etc.).
  • Write data into multiple columns and save.
    • Iterate through each split data.
    • Write the split data into different columns.
    • Save the modified workbook to a new file using the Workbook.SaveToFile() method.

Below is the sample code:

  • C#
using Spire.Xls;

namespace ConvertTextToColumns
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook workbook = new Workbook();

            // Load an Excel file
            workbook.LoadFromFile("Data.xlsx");

            // Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            // Loop through each row in the worksheet
            for (int i = 0; i < sheet.LastRow; i++)
            {
                // Get the text of the first cell in the current row
                string cellText = sheet.Range[i + 1, 1].Text;

                // Split the text by comma
                string[] splitText = cellText.Split(',');

                // Iterate through each split value
                for (int j = 0; j < splitText.Length; j++)
                {
                    // Write the split data into different columns
                    sheet.Range[i + 1, j + 3].Text = splitText[j];
                }
            }

            // Autofit column widths
            sheet.AllocatedRange.AutoFitColumns();

            // Save the result file
            workbook.SaveToFile("SplitExcelData.xlsx", ExcelVersion.Version2016);
        }
    }
}

Split Excel data in one column into multiple columns

Get a Free License

To fully experience the capabilities of Spire.XLS for .NET without any evaluation limitations, you can request a free 30-day trial license.

Conclusion

Splitting text into columns in Excel using C# streamlines data processing and reduces the risk of errors. With Spire.XLS, you can automate complex tasks while maintaining data integrity, making data management easier.

When we want to manage the pagination for the paragraphs, we can insert a page break directly. But later we may find that it is hard to add or remove text above the page break and then we have to remove the whole page break. With Microsoft word, we can also use the Paragraph dialog to manage the pagination flexible for the word paragraph as below:

How to manage pagination on word document in C#

We have already shown you how to insert page break to the word document, this article we will show you how to manage the pagination by using the Paragraph.Format offered by Spire.Doc. Here comes to the steps of how to manage the pagination for the word document paragraph in C#:

Step 1: Create a new word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: Get the first section and the paragraph we want to manage the pagination

Section sec = doc.Sections[0];
Paragraph para = sec.Paragraphs[4];

Step 3: Set the pagination format as Format.PageBreakBefore for the checked paragraph.

para.Format.PageBreakBefore = true; 

Step 4: Save the document to file.

doc.SaveToFile("result.docx",FileFormat.Docx2010);

Effective screenshot after managing the pagination for the word document:

How to manage pagination on word document in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
namespace ManagePage
{
 class Program
    {

     static void Main(string[] args)
     {
         Document doc = new Document();
         doc.LoadFromFile("sample.docx");

         Section sec = doc.Sections[0];
         Paragraph para = sec.Paragraphs[4];
         para.Format.PageBreakBefore = true;

         doc.SaveToFile("result.docx", FileFormat.Docx2010);

     }

    }
}

A table in Microsoft Word can contain a variety of elements, including text, images, and many more. Sometimes, you may want to insert images into a table to present some information or extract images from a table for use in other documents. This article will teach you how to insert or extract images from tables in Word documents in C# and VB.NET using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Insert Images into a Table in a Word Document in C# and VB.NET

Spire.Doc provides the TableCell.Paragraphs[int].AppendPicture() method which enables you to add an image to a specific table cell. The detailed steps are as follows:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specific section in the document by its index through Document.Sections[int] property.
  • Get a specific table in the section by its index through Section.Tables[int] property.
  • Access a specific cell to which you want to add an image through Table.Row[int].Cells[int] property.
  • Add an image to a specific paragraph of the cell using TableCell.Paragraphs[int].AppendPicture() method.
  • Set image width and height through DocPicture.Width and DocPicture.Height properties.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertImagesIntoTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document doc = new Document();
            //Load a Word document
            doc.LoadFromFile("Table.docx");

            //Get the first section of the document
            Section section = doc.Sections[0];

            //Get the first table from the first section
            Table table = (Table)section.Tables[0];

            //Add an image to the 3rd cell of the second row in the table
            TableCell cell = table.Rows[1].Cells[2];
            DocPicture picture = cell.Paragraphs[0].AppendPicture(Image.FromFile("doc.png"));
            //Set image width and height
            picture.Width = 100;
            picture.Height = 100;
            //Add an image to the 3rd cell of the 3rd row in the table
            cell = table.Rows[2].Cells[2];
            picture = cell.Paragraphs[0].AppendPicture(Image.FromFile("xls.png"));
            //Set image width and height
            picture.Width = 100;
            picture.Height = 100;

            //Save the result document
            doc.SaveToFile("AddImageToTable.docx", FileFormat.Docx2013);
        }
    }
}

C#/VB.NET: Insert or Extract Images from Tables in Word

Extract Images from a Table in a Word Document in C# and VB.NET

To extract images from a table, you need to iterate through all rows in the tale, all cells in each row, all paragraphs in each cell and all child objects in each paragraph, then find the objects that are of DocPicture type and call DocPicture.Image.Save() method to save them to a specified file path. The detailed steps are as follows:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specific section in the document by its index through Document.Sections[int] property.
  • Get a specific table in the section by its index through Section.Tables[int] property.
  • Iterate through all rows in the table.
  • Iterate through all cells in each row.
  • Iterate through all paragraphs in each cell.
  • Iterate through all child objects in each paragraph.
  • Check if the current child object is of DocPicture type.
  • If the result is true, typecast the object as DocPicture and call DocPicture.Image.Save() method to save the image to a specified file path.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Drawing.Imaging;

namespace ExtractImagesFromTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document doc = new Document();
            //Load a Word document
            doc.LoadFromFile("AddImageToTable.docx");

            //Get the first section of the document
            Section section = doc.Sections[0];

            //Get the first table from the first section
            Table table = (Table)section.Tables[0];

            int index = 0;
            string imageName = null;

            //Iterate through all rows in the table
            for (int i = 0; i < table.Rows.Count; i++)
            {
                //Iterate through all cells in each row
                for (int j = 0; j < table.Rows[i].Cells.Count; j++)
                {
                    //Iterate through all paragraphs in each cell
                    foreach (Paragraph para in table[i, j].Paragraphs)
                    {
                        //Iterate through all child objects in each paragraph
                        foreach (DocumentObject obj in para.ChildObjects)
                        {
                            //Check if the current child object is of DocPicture type
                            if (obj is DocPicture)
                            {
                                //Save the images to a specified file path
                                imageName = string.Format(@"images\TableImage-{0}.png", index);
                                (obj as DocPicture).Image.Save(imageName, ImageFormat.Png);
                                index++;
                            }
                        }
                    }
                }
            }
        }
    }
}

C#/VB.NET: Insert or Extract Images from Tables in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Page transitions give visual sparkle by creating a "PowerPoint-like" effect when switching between pages. Page transitions are useful when you create a slideshow in PDF format. This article will introduce how to add page transition effects to an existing PDF document using Spire.PDF.

Code Snippet:

Step 1: Initialize an object of PdfDocument class and load the sample PDF which you want to add transition effects to.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

Step 2: Create a new PDF document, add sections to it based on the page count of source file and transfer every individual page to a section. Spire.PDF provides PageSettings property in PdfSection class for setting transition effects, that's reason why we should add pages to sections within a new PDF document.

PdfDocument newDoc = new PdfDocument();
for (int i = 0; i < doc.Pages.Count; i++)
{
    PdfSection secetion = newDoc.Sections.Add();
    PdfPageBase page = doc.Pages[i];
    PdfTemplate template = page.CreateTemplate();
    PdfNewPage newpage = secetion.Pages.Add();
    newpage.Canvas.DrawTemplate(template, new PointF(0 - doc.PageSettings.Margins.Left, 0- doc.PageSettings.Margins.Top));
}

Step 3: As demonstrated above, we know that each section in the new document contains a page. Then we could set transition effect for each page through PageSettings.Transition.

PdfSection secetion1 = newDoc.Sections[0];
secetion1.PageSettings.Transition.Style = PdfTransitionStyle.Cover;
secetion1.PageSettings.Transition.Duration = 3;
secetion1.PageSettings.Transition.PageDuration = 2;

PdfSection secetion2 = newDoc.Sections[1];
secetion2.PageSettings.Transition.Style = PdfTransitionStyle.Glitter;
secetion2.PageSettings.Transition.Duration = 3;
secetion2.PageSettings.Transition.PageDuration = 2;

PdfSection secetion3 = newDoc.Sections[2];
secetion3.PageSettings.Transition.Style = PdfTransitionStyle.Fade;
secetion3.PageSettings.Transition.Duration = 3;
secetion3.PageSettings.Transition.PageDuration = 2;

Step 4: Save and launch the file.

newDoc.SaveToFile("Transition.pdf", FileFormat.PDF);
System.Diagnostics.Process.Start("Transition.pdf");

Output:

How to set page transitions for existing PDF document in C#, VB.NET

[C#]
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;


namespace SetPageTransitions
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            PdfDocument newDoc = new PdfDocument();
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                PdfSection secetion = newDoc.Sections.Add();
                PdfPageBase page = doc.Pages[i];
                PdfTemplate template = page.CreateTemplate();
                PdfNewPage newpage = secetion.Pages.Add();
                newpage.Canvas.DrawTemplate(template, new PointF(0 - doc.PageSettings.Margins.Left, 0 - doc.PageSettings.Margins.Top));
            }

            PdfSection secetion1 = newDoc.Sections[0];
            secetion1.PageSettings.Transition.Style = PdfTransitionStyle.Cover;
            secetion1.PageSettings.Transition.Duration = 3;
            secetion1.PageSettings.Transition.PageDuration = 2;

            PdfSection secetion2 = newDoc.Sections[1];
            secetion2.PageSettings.Transition.Style = PdfTransitionStyle.Glitter;
            secetion2.PageSettings.Transition.Duration = 3;
            secetion2.PageSettings.Transition.PageDuration = 2;

            PdfSection secetion3 = newDoc.Sections[2];
            secetion3.PageSettings.Transition.Style = PdfTransitionStyle.Fade;
            secetion3.PageSettings.Transition.Duration = 3;
            secetion3.PageSettings.Transition.PageDuration = 2;

            newDoc.SaveToFile("Transition.pdf", FileFormat.PDF);
            System.Diagnostics.Process.Start("Transition.pdf");
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing


Namespace SetPageTransitions
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")

			Dim newDoc As New PdfDocument()
			For i As Integer = 0 To doc.Pages.Count - 1
				Dim secetion As PdfSection = newDoc.Sections.Add()
				Dim page As PdfPageBase = doc.Pages(i)
				Dim template As PdfTemplate = page.CreateTemplate()
				Dim newpage As PdfNewPage = secetion.Pages.Add()
				newpage.Canvas.DrawTemplate(template, New PointF(0 - doc.PageSettings.Margins.Left, 0 - doc.PageSettings.Margins.Top))
			Next

			Dim secetion1 As PdfSection = newDoc.Sections(0)
			secetion1.PageSettings.Transition.Style = PdfTransitionStyle.Cover
			secetion1.PageSettings.Transition.Duration = 3
			secetion1.PageSettings.Transition.PageDuration = 2

			Dim secetion2 As PdfSection = newDoc.Sections(1)
			secetion2.PageSettings.Transition.Style = PdfTransitionStyle.Glitter
			secetion2.PageSettings.Transition.Duration = 3
			secetion2.PageSettings.Transition.PageDuration = 2

			Dim secetion3 As PdfSection = newDoc.Sections(2)
			secetion3.PageSettings.Transition.Style = PdfTransitionStyle.Fade
			secetion3.PageSettings.Transition.Duration = 3
			secetion3.PageSettings.Transition.PageDuration = 2

			newDoc.SaveToFile("Transition.pdf", FileFormat.PDF)
			System.Diagnostics.Process.Start("Transition.pdf")
		End Sub
	End Class
End Namespace

How to hide word paragraph in C#

2016-06-08 05:46:24 Written by Koohji

When we operate the word document, we can hide some texts or the whole paragraph on the Microsoft Word after click the font box to hide the selected texts. Please check the screenshot of how Microsoft hide the text as below:

How to hide word paragraph in C#

Spire.Doc offers a CharacterFormat.Hidden property to enable developers to hide the specified text or the whole paragraph. This article will demonstrate how to hide the whole paragraph on the word document in C#.

Here comes to the code snippets:

Step 1: Create a new word document and load from file.

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: Get the first section and the first paragraph from the word document.

Section sec = doc.Sections[0];
Paragraph para = sec.Paragraphs[0];

Step 3: Get the first TextRange and set CharacterFormat.Hidden property as true to hide the texts.

(para.ChildObjects[0] as TextRange).CharacterFormat.Hidden = true;

Step 4: Save the document to file.

doc.SaveToFile("result.docx", FileFormat.Docx);

Effective screenshot after the paragraph is hidden:

How to hide word paragraph in C#

After we set the options to display the hidden text, the hidden text will show like this:

How to hide word paragraph in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace HideParagh
{
 class Program
    {
     
      static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("sample.docx");
            Section sec = doc.Sections[0];
            Paragraph para = sec.Paragraphs[0];

            (para.ChildObjects[0] as TextRange).CharacterFormat.Hidden = true;

            doc.SaveToFile("result.docx", FileFormat.Docx);
        }
    }
}

When demonstrating an excel report, you may also want to share information from other external files or websites. In Excel, we can add both URL hyperlinks and external files by right-clicking on cells, selecting hyperlink and then adding URL address or choosing files from disk. This article is aimed to explain how to add hyperlinks to external files in excel programmatically using Spire.XLS for WPF. To add URL hyperlinks, please refer to this article: How to Insert Hyperlink in Excel for WPF Applications.

Please see the effective screenshot below after adding hyperlinks to external files:

How to add hyperlinks to external files in Excel for WPF Applications

Code Snippets:

Use the following namespace:

using System.Windows;
using Spire.Xls;

Step 1: Initialize a new Workbook object, load the sample excel file and get its first worksheet.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];

Step 2: Get the cell/cell range that you want to add hyperlink to, then call the sheet.HyperLinks.Add(CellRange range) method to add the hyperlink to the cell/cell range.

CellRange range1 = sheet.Range["D18"];
HyperLink hyperlink1 = sheet.HyperLinks.Add(range1); 

Step 3: Specify the hyperlink style and the hyperlink target, here we set its style to file and target to an external excel file.

hyperlink1.Type = HyperLinkType.File;
hyperlink1.Address = "SalesInfo.xlsx";

Step 4: Repeat step 2 and step 3 to add a hyperlink to another specific cell, set the hyperlink style to file and set its target to a word file.

CellRange range2 = sheet.Range["E18"];
HyperLink hyperlink2 = sheet.HyperLinks.Add(range2);
hyperlink2.Type = HyperLinkType.File;
hyperlink2.Address = "Report.doc";

Step 5: Save and launch the file.

workbook.SaveToFile("LinktoFile.xlsx", FileFormat.Version2010);
System.Diagnostics.Process.Start("LinktoFile.xlsx");

Full Codes:

C#
using Spire.Xls;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Vendors Information.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            HyperLink Link = sheet.HyperLinks.Add(sheet.Range["A5"]);
            Link.TextToDisplay = sheet.Range["A5"].Text;
            Link.Type = HyperLinkType.Url;
            Link.Address = "https://en.wikipedia.org/wiki/Canada";

            HyperLink NewLink = sheet.HyperLinks.Add(sheet.Range["D13"]);
            NewLink.TextToDisplay = "https://www.google.com";
            NewLink.Type = HyperLinkType.Url;
            NewLink.Address = "https://www.google.com";

            workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Hyperlink.xlsx");
        }
    }
}
VB.NET
Imports Spire.Xls
Imports System.Windows

Namespace WpfApplication1
	Public Partial Class MainWindow
		Inherits Window
		Public Sub New()
			InitializeComponent()
		End Sub
		Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
			Dim workbook As New Workbook()
			workbook.LoadFromFile("Vendors Information.xlsx")
			Dim sheet As Worksheet = workbook.Worksheets(0)

			Dim Link As HyperLink = sheet.HyperLinks.Add(sheet.Range("A5"))
			Link.TextToDisplay = sheet.Range("A5").Text
			Link.Type = HyperLinkType.Url
			Link.Address = "https://en.wikipedia.org/wiki/Canada"

			Dim NewLink As HyperLink = sheet.HyperLinks.Add(sheet.Range("D13"))
			NewLink.TextToDisplay = "https://www.google.com"
			NewLink.Type = HyperLinkType.Url
			NewLink.Address = "https://www.google.com"

			workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010)
			System.Diagnostics.Process.Start("Hyperlink.xlsx")
		End Sub
	End Class
End Namespace
page 37