Word bookmarks are widely used for point out a specified location or give brief information of the paragraph. If you add an image into the bookmark position, the bookmarks will be more obviously and clearly. This article will show you how to insert an image at bookmark position in C# with the help of Spire.Doc.

Spire.Doc offers an instance of BookmarksNavigator to find the bookmarks, and then developers use AppendPicture to add an image. Here comes to the steps:

Step 1: Load a word documents with bookmarks.

Document document = new Document();
document.LoadFromFile("Test.docx");

Step 2: Create an instance of BookmarksNavigator and find the bookmark where you want to insert an image.

//Create an instance of BookmarksNavigator
BookmarksNavigator bn = new BookmarksNavigator(document);
//Find a bookmark and its name is Spire
bn.MoveToBookmark("Spire", true, true);

Step 3: Insert an image at the position of bookmarks you found.

//Add a section and named it section0
Section section0 = document.AddSection();
//Add a paragraph for section0
Paragraph paragraph = section0.AddParagraph();
Image image = Image.FromFile("step.png");
//Add a picture into paragraph
DocPicture picture = paragraph.AppendPicture(image);
//Add a paragraph with picture at the position of bookmark
bn.InsertParagraph(paragraph);
document.Sections.Remove(section0);

Step 4: Save the new document and process it.

string output = "sample3.docx";
document.SaveToFile(output, FileFormat.Docx);
System.Diagnostics.Process.Start(output);

Spire.Doc also offers the following properties to set the image position based on developers' requirements.

picture.TextWrappingStyle
picture.HorizontalAlignment
picture.HorizontalOrigin
picture.HorizontalPosition
picture.VerticalAlignment
picture.VerticalOrigin
picture.VerticalPosition

Effective screenshot:

Insert an image at bookmark in word documents

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertImage
{
    class Program
    {

        static void Main(string[] args)
        {

            Document document = new Document();
            document.LoadFromFile("Test.docx");
            BookmarksNavigator bn = new BookmarksNavigator(document);
            bn.MoveToBookmark("Spire", true, true);
            Section section0 = document.AddSection();
            Paragraph paragraph = section0.AddParagraph();
            Image image = Image.FromFile("step.png");
            DocPicture picture = paragraph.AppendPicture(image);
            bn.InsertParagraph(paragraph);
            document.Sections.Remove(section0);
            string output = "sample.docx";
            document.SaveToFile(output, FileFormat.Docx);
            System.Diagnostics.Process.Start(output);
        }
    }
}

Bookmarks give convenience when users want go to specified location and it is clearly to know the contents brief information. Spire.Doc for .NET has a powerful function of operating the word elements of bookmarks. Developers can add bookmarks, Edit/replace bookmarks and remove bookmarks in word documents. Now Spire.Doc starts to support preserve bookmarks in DOCX to PDF conversion. This article will show you how to preserve bookmarks in C# when converting word document into PDF file format.

Download and install Spire.Doc for .NET (Version 5.2.20 or above) and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll".

Here comes to the details of how to preserve the bookmarks from word to PDF conversion in C#.

Step 1: Load a word documents with bookmarks.

Document doc = new Document();
doc.LoadFromFile("test.docx", FileFormat.Docx);

Step 2: Create an instance of ToPdfParameterList

ToPdfParameterList toPdf = new ToPdfParameterList();

Step 3: Set CreateWordBookmarks to true to use word bookmarks when create the bookmarks.

toPdf.CreateWordBookmarks = true;

Step 4: Save the PDF file.

doc.SaveToFile("test.Pdf",toPdf);

Effective screenshot of preserve the bookmarks in result PDF page:

Preserve bookmarks in PDF from word

Full codes:

[C#]
using Spire.Doc;
namespace PreventBookmark
{
    class Program
    {

        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("test.docx", FileFormat.Docx);
            ToPdfParameterList toPdf = new ToPdfParameterList();
            toPdf.CreateWordBookmarks = true;
            doc.SaveToFile("test.Pdf", toPdf);
            System.Diagnostics.Process.Start("test.Pdf");

        }
    }
}

As is shown in the following presentation slide, shapes automatically stack in separate layers as you add them. To change the order of overlapping shapes, we can move the layers forward and backward. But how can we achieve this task programmatically using C# or VB.NET? This article is aimed to present you a solution on how to reorder overlapping shapes using Spire.Presentation.

Reorder overlapping shapes in presentation

In the early edition, Spire.Presentation is already capable of adding different kinds of shapes to the slides, setting color and fill style of the shape. In the Version2.0.18, we add reordering overlapping shapes as a new feature to satisfy our customer’s demands. Now, let’s see how to make it happen with sample code snippet.

Step 1: Create a new instance of Spire.Presentation class and load the test file.

Spire.Presentation.Presentation presentation = new Presentation();
presentation.LoadFromFile("..\\..\\test.pptx");

Step 2: Get the first shape from the slide.

IShape shape = presentation.Slides[0].Shapes[0];

Step 3: Change the shape's Zorder by setting its position index.

presentation.Slides[0].Shapes.ZOrder(1, shape);

Step 4: Save to a PPTX file and launch the file.

string output = "output.pptx";
presentation.SaveToFile(output,FileFormat.Pptx2010);
System.Diagnostics.Process.Start(output);

Output:

Reorder overlapping shapes in presentation

Full code:

[C#]
using Spire.Presentation;

namespace ReorderOverlappingShape
{

    class Program
    {

        static void Main(string[] args)
        {
            //Create an instance of Spire.Presentation
            Spire.Presentation.Presentation presentation = new Presentation();
            //Load a pptx file
            presentation.LoadFromFile("..\\..\\test.pptx");

            //Get the first shape of the first slide
            IShape shape = presentation.Slides[0].Shapes[0];
            //Change the shape's zorder
            presentation.Slides[0].Shapes.ZOrder(1, shape);

            //Save to a pptx2010 file.
            string output = "output.pptx";
            presentation.SaveToFile(output, FileFormat.Pptx2010);
            //Launch the output file
            System.Diagnostics.Process.Start(output);

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

Namespace ReorderOverlappingShape

	Class Program

		Private Shared Sub Main(args As String())
			'Create an instance of Spire.Presentation
			Dim presentation As Spire.Presentation.Presentation = New Presentation()
			'Load a pptx file
			presentation.LoadFromFile("..\..\test.pptx")

			'Get the first shape of the first slide
			Dim shape As IShape = presentation.Slides(0).Shapes(0)
			'Change the shape's zorder
			presentation.Slides(0).Shapes.ZOrder(1, shape)

			'Save to a pptx2010 file.
			Dim output As String = "output.pptx"
			presentation.SaveToFile(output, FileFormat.Pptx2010)
			'Launch the output file
			System.Diagnostics.Process.Start(output)

		End Sub
	End Class
End Namespace
page 272