page 199

C#/VB.NET: Rearrange Pages in PDF

2022-04-27 07:29:00 Written by Koohji

For PDF documents with pages out of order, rearranging the pages can avoid confusing the reader and also make the document more organized. This article will demonstrate how to programmatically rearrange the pages in an existing PDF document 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 DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Rearrange Pages in an Existing PDF Document

  • Create a PdfDocument object.
  • Load a sample PDF document using PdfDocument.LoadFromFile() method.
  • Get the pages in the PDF document using PdfDocument.Pages property.
  • Rearrange PDF pages using PdfPageCollection.ReArrange(int[] orderArray) method.
  • Save the document to another file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;

namespace RearrangePDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument pdf = new PdfDocument();

            //Load a sample PDF document
            pdf.LoadFromFile("input.pdf");

            //Rearrange pages by page index
            pdf.Pages.ReArrange(new int[] { 1, 0, 2, 3 });

            //Save the document
            pdf.SaveToFile("ChangeOrder.pdf");
            pdf.Close();
        }
    }
}

C#/VB.NET: Rearrange Pages 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.

A comment in Word can contain rich elements such as text, image, OLE object, and etc. This article presents how we can insert a picture to a comment in Word using Spire.Doc.

Step 1: Initialize an instance of Document class and load a sample document.

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

Step 2: Get the third paragraph from section one.

Paragraph paragraph = doc.Sections[0].Paragraphs[2];

Step 3: Append a comment to the paragraph.

Comment comment = paragraph.AppendComment("This is a comment.");
comment.Format.Author = "E-iceblue";   

Step 4: Insert an image to comment body.

DocPicture docPicture = new DocPicture(doc);
Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");
docPicture.LoadImage(img);
comment.Body.AddParagraph().ChildObjects.Add(docPicture);

Step 5: Save the file.

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

Output:

How to Insert Picture into Comment in Word in C#, VB.NET

Full Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertPicture
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.docx");
            Paragraph paragraph = doc.Sections[0].Paragraphs[2];

            Comment comment = paragraph.AppendComment("This is a comment.");
            comment.Format.Author = "E-iceblue";
            DocPicture docPicture = new DocPicture(doc);
            Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");
            docPicture.LoadImage(img);
            comment.Body.AddParagraph().ChildObjects.Add(docPicture);

            doc.SaveToFile("result.docx", FileFormat.Docx2013);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace InsertPicture
	Class Program

		Private Shared Sub Main(args As String())

			Dim doc As New Document()
			doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.docx")
			Dim paragraph As Paragraph = doc.Sections(0).Paragraphs(2)

			Dim comment As Comment = paragraph.AppendComment("This is a comment.")
			comment.Format.Author = "E-iceblue"
			Dim docPicture As New DocPicture(doc)
			Dim img As Image = Image.FromFile("C:\Users\Administrator\Desktop\logo.png")
			docPicture.LoadImage(img)
			comment.Body.AddParagraph().ChildObjects.Add(docPicture)

			doc.SaveToFile("result.docx", FileFormat.Docx2013)
		End Sub
	End Class
End Namespace

We have already demonstrated how to using Spire.XLS hide excel columns and rows in C#. Sometimes we don't want to show the data on a certain cell to others but not hide the whole row or column. Then we can only hide the data on this cell by setting the number format for it. This article will focus on showing how to hide the content on a certain cell by setting the number format as ";;;" to hide the content to others.

Step 1: Initialize an instance of Workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Get the first worksheet from the workbook.

Worksheet worksheet = workbook.Worksheets[0];

Step 3: Hide the area by setting the number format as ";;;".

worksheet.Range["E2"].NumberFormat = ";;;";

Step 4: Save the document to file.

workbook.SaveToFile("Result.xlsx", FileFormat.Version2010);

Effective screenshot of hide the content on Excel cell by setting the number format:

Hide the content on Cell by setting the number format

Full codes:

using Spire.Xls;
namespace HideContent
{
    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.Range["E2"].NumberFormat = ";;;";

            workbook.SaveToFile("Result.xlsx", FileFormat.Version2010);
        }
    }
}
page 199