3-D is the abbreviation for three-dimensional. After adding a shape into the slide, we could set its format as 3-D, which looks more fresh and attractive. We could use options like Bevel, Contours, and Surface Material to customize 3-D shapes. This article is going to introduce the method to set 3-D shapes in C# using Spire.Presentation.

Note: before start, please download the latest version of Spire.Presentation and add the .dll in the bin folder as the reference of Visual Studio.

Step 1: Create a new presentation document.

             Presentation presentation = new Presentation();

Step 2: Add shape1 and fill it with color.

IAutoShape shape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.RoundCornerRectangle, new RectangleF(150, 150, 150, 150));
shape1.Fill.FillType = FillFormatType.Solid;
shape1.Fill.SolidColor.KnownColor = KnownColors.RoyalBlue;

Step 3: Initialize a new instance of the 3-D class for shape1 and set its properties.

            ShapeThreeD Demo1 = shape1.ThreeD.ShapeThreeD;
            Demo1.PresetMaterial = PresetMaterialType.Powder;
            Demo1.TopBevel.PresetType = BevelPresetType.ArtDeco;
            Demo1.TopBevel.Height = 4;
            Demo1.TopBevel.Width = 12;
            Demo1.BevelColorMode = BevelColorType.Contour;
            Demo1.ContourColor.KnownColor = KnownColors.LightBlue;
            Demo1.ContourWidth = 3.5;

Step 4: Set 3-D format for shape2 as comparison.

IAutoShape shape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Pentagon, new RectangleF(400, 150, 150, 150));
           shape2.Fill.FillType = FillFormatType.Solid;
           shape2.Fill.SolidColor.KnownColor = KnownColors.LawnGreen;
           ShapeThreeD Demo2 = shape2.ThreeD.ShapeThreeD;
           Demo2.PresetMaterial = PresetMaterialType.SoftEdge;
           Demo2.TopBevel.PresetType = BevelPresetType.SoftRound;
           Demo2.TopBevel.Height = 12;
           Demo2.TopBevel.Width = 12;
           Demo2.BevelColorMode = BevelColorType.Contour;
           Demo2.ContourColor.KnownColor = KnownColors.LawnGreen;
           Demo2.ContourWidth = 5;

Step 5: Save the document and launch to see effects.

           presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
           System.Diagnostics.Process.Start("result.pptx");

Effects:

How to set 3-D format for shapes in slides

Full Codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            
            Presentation presentation = new Presentation();

            IAutoShape shape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.RoundCornerRectangle, new RectangleF(150, 150, 150, 150));
            shape1.Fill.FillType = FillFormatType.Solid;
            shape1.Fill.SolidColor.KnownColor = KnownColors.RoyalBlue;
            ShapeThreeD Demo1 = shape1.ThreeD.ShapeThreeD;
            Demo1.PresetMaterial = PresetMaterialType.Powder;
            Demo1.TopBevel.PresetType = BevelPresetType.ArtDeco;
            Demo1.TopBevel.Height = 4;
            Demo1.TopBevel.Width = 12;
            Demo1.BevelColorMode = BevelColorType.Contour;
            Demo1.ContourColor.KnownColor = KnownColors.LightBlue;
            Demo1.ContourWidth = 3.5;

            IAutoShape shape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Pentagon, new RectangleF(400, 150, 150, 150));
            shape2.Fill.FillType = FillFormatType.Solid;
            shape2.Fill.SolidColor.KnownColor = KnownColors.LawnGreen;
            ShapeThreeD Demo2 = shape2.ThreeD.ShapeThreeD;
            Demo2.PresetMaterial = PresetMaterialType.SoftEdge;
            Demo2.TopBevel.PresetType = BevelPresetType.SoftRound;
            Demo2.TopBevel.Height = 12;
            Demo2.TopBevel.Width = 12;
            Demo2.BevelColorMode = BevelColorType.Contour;
            Demo2.ContourColor.KnownColor = KnownColors.LawnGreen;
            Demo2.ContourWidth = 5;

            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");
        }
    }
}

C#/VB.NET: Convert RTF to PDF

2022-03-17 09:03:00 Written by Koohji

RTF (Rich Text Format) is a cross-platform document developed by Microsoft in the 1980s. RTF can be opened by most word processors, and it is also convenient for editing. But when it comes to sharing and printing documents in daily work, it’s more recommended to convert the RTF to PDF for further processing. In this article, you will learn how to convert RTF to PDF programmatically 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

Convert RTF to PDF in C# and VB.NET

Spire.Doc for .NET enables you to directly load a file with .rtf extension and then convert it to PDF with only three lines of code. The detailed steps are as follows.

  • Create a Document instance.
  • Load a sample RTF document using Document.LoadFromFile() method.
  • Save the document as a PDF file using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;

namespace RTFtoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc = new Document();

            //Load a sample RTF document
            doc.LoadFromFile("sample.rtf", FileFormat.Rtf);

            //Save it to PDF
            doc.SaveToFile("RTFtoPDF.pdf", FileFormat.PDF);
        }
    }
}

C#/VB.NET: Convert RTF to 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.

After finishing designs of shapes in slides, accidental changes might happen if we haven't made necessary protecting settings. Locking shapes from being selected firstly or preventing changes to shape attributes (like size, position, rotation etc.) can be used to prevent changes to shapes. It's necessary to mention that Spire.Presentation supports the features to prevent changes to shapes. This article is going to introduce how to prevent or allow changes to shapes in C# using Spire.Presentation.

Note: before start, please download the latest version of Spire.Presentation and add the .dll in the bin folder as the reference of Visual Studio.

Step 1: create a presentation file and add a sample shape.

Presentation presentation = new Presentation();
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 450, 150));

Step 2: format the sample shape.

            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.DarkGreen;
            shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
            shape.TextFrame.Text = "Demo for locking shapes:\n    Green/Black stands for editable.\n    Grey points stands for non-editable.";
            shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

Step 3: set which operations are disabled on the shape to prevent changes. Here the selection and rotation changing of the shape are allowed while the changes of size, position, shape type, text, rotation, handles, and aspect ratio are not allowed.

            shape.Locking.RotationProtection = false;
            shape.Locking.SelectionProtection = false;
            shape.Locking.ResizeProtection = true;
            shape.Locking.PositionProtection = true;
            shape.Locking.ShapeTypeProtection = true;
            shape.Locking.AspectRatioProtection = true;
            shape.Locking.TextEditingProtection = true;
            shape.Locking.AdjustHandlesProtection = true;

Step 4: save the document and launch to see effects.

            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

Effects:

How to prevent or allow changes to shapes

Full codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            
            Presentation presentation = new Presentation();
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 450, 150));
 
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.DarkGreen;
            shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
            shape.TextFrame.Text = "Demo for locking shapes:\n    Green/Black stands for editable.\n    Grey stands for non-editable.";
            shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;
            
            shape.Locking.RotationProtection = false;
            shape.Locking.SelectionProtection = false;
            shape.Locking.ResizeProtection = true;
            shape.Locking.PositionProtection = true;
            shape.Locking.ShapeTypeProtection = true;
            shape.Locking.AspectRatioProtection = true;
            shape.Locking.TextEditingProtection = true;
            shape.Locking.AdjustHandlesProtection = true;

            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");
        }
    }
}

Spire.Doc supports to insert any type of file such as Excel, PDF, PowerPoint and etc, as OLE object into a Word document. In this article, you'll learn how to add a media file (audio or video) to a Word document using Spire.Doc in C#, VB.NET.

In the class of DocOleObject, a method named AppendOleObject(Stream oleStream, DocPicture olePicture, string fileExtension) is available for users to insert media file with the extension of mp3, mp4, avi or any other format into a Word document. The three parameters in this method represent:

  • oleStream: The OLE file stream.
  • olePicture: The image (icon) that is displayed in Word to show the OLE object.
  • fileExtension: The file extension.

Code Snippet:

Step 1: Initialize a new instance of Document class and add a new section.

Document doc = new Document();
Section section = doc.AddSection();

Step 2: Add a new paragraph, append some formatted text into the paragraph.

Paragraph para1 = section.AddParagraph();
para1.AppendText("Double click the PLAY button to view the video file");
ParagraphStyle style1 = new ParagraphStyle(doc);
style1.Name = "Style";
style1.CharacterFormat.FontName = "Calibri";
style1.CharacterFormat.FontSize = 15;
style1.CharacterFormat.Bold = true;
style1.CharacterFormat.TextColor = Color.Red;
doc.Styles.Add(style1);
para1.ApplyStyle(style1.Name);

Step 3: Add another paragraph, append a video file as OLE object into the paragraph.

Paragraph para2 = section.AddParagraph();
Stream s = File.OpenRead("media.mp4");
DocPicture pic = new DocPicture(doc);
pic.LoadImage(Image.FromFile("button.png"));
para2.AppendOleObject(s, pic, "mp4");

Step 4: Save the view the file.

doc.SaveToFile("Result.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("Result.docx");

Output:

How to Embed Media File in Word in C#, VB.NET

Full Code:

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

        static void Main(string[] args)
        {
            //create a new Word document and insert section
            Document doc = new Document();
            Section section = doc.AddSection();
            //add a paragraph and append some text
            Paragraph para1 = section.AddParagraph();
            para1.AppendText("Double click the PLAY button to view the video file");
            ParagraphStyle style1 = new ParagraphStyle(doc);
            style1.Name = "Style";
            style1.CharacterFormat.FontName = "Calibri";
            style1.CharacterFormat.FontSize = 15;
            style1.CharacterFormat.Bold = true;
            style1.CharacterFormat.TextColor = Color.Red;
            doc.Styles.Add(style1);
            para1.ApplyStyle(style1.Name);
            //add another paragraph, append video file as OLE object in Word
            Paragraph para2 = section.AddParagraph();
            Stream s = File.OpenRead("media.mp4");
            DocPicture pic = new DocPicture(doc);
            pic.LoadImage(Image.FromFile("button.png"));
            para2.AppendOleObject(s, pic, "mp4");
            //save and view the file
            doc.SaveToFile("Result.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("Result.docx");

        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Imports System.IO
Namespace EmbedMediaFile
	Class Program

		Private Shared Sub Main(args As String())
			'create a new Word document and insert section
			Dim doc As New Document()
			Dim section As Section = doc.AddSection()
			'add a paragraph and append some text
			Dim para1 As Paragraph = section.AddParagraph()
			para1.AppendText("Double click the PLAY button to view the video file")
			Dim style1 As New ParagraphStyle(doc)
			style1.Name = "Style"
			style1.CharacterFormat.FontName = "Calibri"
			style1.CharacterFormat.FontSize = 15
			style1.CharacterFormat.Bold = True
			style1.CharacterFormat.TextColor = Color.Red
			doc.Styles.Add(style1)
			para1.ApplyStyle(style1.Name)
			'add another paragraph, append video file as OLE object in Word
			Dim para2 As Paragraph = section.AddParagraph()
			Dim s As Stream = File.OpenRead("media.mp4")
			Dim pic As New DocPicture(doc)
			pic.LoadImage(Image.FromFile("button.png"))
			para2.AppendOleObject(s, pic, "mp4")
			'save and view the file
			doc.SaveToFile("Result.docx", FileFormat.Docx2010)
			System.Diagnostics.Process.Start("Result.docx")

		End Sub
	End Class
End Namespace

The Mark as Final command makes a presentation read-only and prevents changes to the document. When you share a presentation that is marked as final, you're telling viewers the presentation is final and no changes on it are wanted. In this article, I'll make a brief introduction about how to mark a presentation as final using Spire.Presentation in C#, VB.NET.

In Spire.Presentation, the presentation class contains a property of DocumentProperty which enables developers to set document properties easily. Here in this case, you are able to mark a presentation as final by setting the Boolean value of MarkAsFinal as true.

Code Snippet:

Step 1: Initialize a new instance of presentation class and load the sample file.

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

Step 2: Set the value of MarkAsFinal property as true.

ppt.DocumentProperty["_MarkAsFinal"] =true;

Step 3: Save and launch the file.

ppt.SaveToFile("result.pptx",FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

Effect:

How to Mark a Presentation as Final using Spire.Presentation in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
namespace MarkPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("sample.pptx", FileFormat.Pptx2010);

            ppt.DocumentProperty["_MarkAsFinal"] = true;

            ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");
            System.Diagnostics.Process.Start("result.pptx");

            }
        }
    }
[VB.NET]
Imports Spire.Presentation
Namespace MarkPPT
	Class Program
		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation()
			ppt.LoadFromFile("sample.pptx", FileFormat.Pptx2010)

			ppt.DocumentProperty("_MarkAsFinal") = True

			ppt.SaveToFile("result.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("result.pptx")
			System.Diagnostics.Process.Start("result.pptx")

		End Sub
	End Class
End Namespace

C#: Insert Paragraphs in Word

2024-11-14 08:01:00 Written by Koohji

Inserting paragraphs in Word is a fundamental skill for creating well-structured and organized documents. Paragraphs can break down large blocks of text, making it easier for readers to follow the flow of ideas and find specific information. In Word, you can add new paragraphs to represent new ideas or add additional information. This article will demonstrate how to insert a new paragraph in Word in C# 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

Add a Paragraph at the End of a Word Document in C#

To add a new paragraph at the end, you need to get the last section of the Word document through the Document.LastSection property, and then add a paragraph at the end of the section through the Section.AddParagraph() method. The following are the detailed steps:

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Get the last section of the document using Document.LastSection property.
  • Add a paragraph at the end of the section using Section.AddParagraph() method, and then add text to it using Paragraph.AppendText() method.
  • Create a ParagraphStyle object and set the font name, size, style of the paragraph text.
  • Apply the paragraph style using Paragraph.ApplyStyle() method
  • Save the result document using Document.SaveToFile() method.
  • C#
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;

namespace AddParagraph
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document object
            Document doc = new Document();

            //Load a Word document
            doc.LoadFromFile("Test.docx");

            //Get the last section
            Section section = doc.LastSection;

            //Add a paragraph at the end and set its text content
            Paragraph para = section.AddParagraph();
            para.AppendText("Add a paragraph to the end of the document.");

            //Set the paragraph style
            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "Style1";
            style.CharacterFormat.FontName = "Times New Roman";
            style.CharacterFormat.FontSize = 12;
            style.CharacterFormat.TextColor = Color.Blue;
            style.CharacterFormat.Bold = true;
            doc.Styles.Add(style);
            para.ApplyStyle("Style1");
            para.Format.BeforeSpacing = 10;

            //Save the result file
            doc.SaveToFile("AddParagraph.docx", FileFormat.Docx2016);
        }
    }
}

An output file that adds a new paragraph with text in Word using C#

Insert a Paragraph at a Specified Location in Word in C#

You can also add a paragraph and then insert it to a specified position through the Section.Paragraphs.Insert(int index, IParagraph paragraph) method. The following are the detailed steps:

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specified section using Document.Sections[] property.
  • Add a paragraph using Section.AddParagraph() method, and then add text to it using Paragraph.AppendText() method.
  • Set the font name, size, style of the paragraph text.
  • Insert the newly added paragraph at a specified index using Section.Paragraphs.Insert(int index, IParagraph paragraph) method.
  • Save the result document using Document.SaveToFile() method.
  • C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertParagraph
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document object
            Document doc = new Document();

            //Load a Word document
            doc.LoadFromFile("Test.docx");
        

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

            //Add a paragraph and set its text content
            Paragraph para = section.AddParagraph();
            TextRange textRange = para.AppendText("Insert a paragraph at a specified location in the Word document.");

            //Set the font name, size, color and style
            textRange.CharacterFormat.TextColor = Color.Blue;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange.CharacterFormat.FontSize = 14;
            textRange.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;

            //Insert the paragraph as the third paragraph
            section.Paragraphs.Insert(2, para);

            //Set spacing after the paragraph
            para.Format.AfterSpacing = 10;

            //Save the result file
            doc.SaveToFile("InsertParagraph.docx", FileFormat.Docx2016);
        }
    }
}

An output file that inserts a new paragraph as the third paragraph in Word with C#

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.

In order to distinguish nested bookmarks more clearly, you can set different font style and font color for parent and child bookmarks respectively. In this article, I’ll introduce how to modify bookmarks in the terms of font style, font color and text using Spire.PDF in C#, VB.NET.

Main Steps:

Step 1: Initialize a new object of PdfDocument and load the existing PDF file.

PdfDocument doc = new PdfDocument("Bookmark.Pdf");

Step 2: Get all bookmarks from the test file.

PdfBookmarkCollection bookmarks = doc.Bookmarks;

Step 3: Traverse very first-level bookmark in the bookmark tree. Change the properties of selected or all bookmarks, including title, color and display style.

foreach (PdfBookmark parentBookmark in bookmarks)
{
    //change "Word Bookmarks" to "M BookMark"
    bookmarks[0].Title = "Modified BookMarks";      
    //set the color of the bookmark
    parentBookmark.Color = Color.Black;
    parentBookmark.DisplayStyle = PdfTextStyle.Bold;
    //edit child bookmark of parent bookmark
    EditChildBookmark(parentBookmark);
}

Step 4: In step 3, there is a nested method predefined as below. By invoking this method, we are able to modify child bookmarks of the upper level bookmark. In this example, we have two nested level bookmarks under the first-level bookmark.

static void EditChildBookmark(PdfBookmark parentBookmark)
{
   foreach (PdfBookmark childBookmark in parentBookmark)
   {
        childBookmark.Color = Color.Brown;
        childBookmark.DisplayStyle = PdfTextStyle.Regular;
        EditChild2Bookmark(childBookmark);
    }
}
static void EditChild2Bookmark(PdfBookmark childBookmark)
{
    foreach (PdfBookmark child2Bookmark in childBookmark)
    {           
        child2Bookmark.Color = Color.LightSalmon;
        child2Bookmark.DisplayStyle = PdfTextStyle.Italic; 
    }
}

Step 5: Save and launch the file.

doc.SaveToFile("Result.Pdf");
System.Diagnostics.Process.Start("Result.Pdf");

Screenshot of Effect:

How to Modify Bookmarks in Existing PDF in C#, VB.NET

Entire Code:

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


namespace ModifyBookmarks
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument("Bookmark.Pdf");
            PdfBookmarkCollection bookmarks = doc.Bookmarks;
            foreach (PdfBookmark parentBookmark in bookmarks)
            {
                //change "Word Bookmarks" to "M BookMark"
                bookmarks[0].Title = "Modified BookMarks";
                //set the color of the bookmark
                parentBookmark.Color = Color.Black;
                parentBookmark.DisplayStyle = PdfTextStyle.Bold;
                //edit child bookmark of parent bookmark
                EditChildBookmark(parentBookmark);
            }
            doc.SaveToFile("Result.Pdf");
            System.Diagnostics.Process.Start("Result.Pdf");
        }
        static void EditChildBookmark(PdfBookmark parentBookmark)
        {
            foreach (PdfBookmark childBookmark in parentBookmark)
            {
                childBookmark.Color = Color.Brown;
                childBookmark.DisplayStyle = PdfTextStyle.Regular;
                EditChild2Bookmark(childBookmark);
            }
        }
        static void EditChild2Bookmark(PdfBookmark childBookmark)
        {
            foreach (PdfBookmark child2Bookmark in childBookmark)
            {
                child2Bookmark.Color = Color.LightSalmon;
                child2Bookmark.DisplayStyle = PdfTextStyle.Italic;
            }
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Bookmarks
Imports System.Drawing


Namespace ModifyBookmarks
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument("Bookmark.Pdf")
			Dim bookmarks As PdfBookmarkCollection = doc.Bookmarks
			For Each parentBookmark As PdfBookmark In bookmarks
				'change "Word Bookmarks" to "M BookMark"
				bookmarks(0).Title = "Modified BookMarks"
				'set the color of the bookmark
				parentBookmark.Color = Color.Black
				parentBookmark.DisplayStyle = PdfTextStyle.Bold
				'edit child bookmark of parent bookmark
				EditChildBookmark(parentBookmark)
			Next
			doc.SaveToFile("Result.Pdf")
			System.Diagnostics.Process.Start("Result.Pdf")
		End Sub
		Private Shared Sub EditChildBookmark(parentBookmark As PdfBookmark)
			For Each childBookmark As PdfBookmark In parentBookmark
				childBookmark.Color = Color.Brown
				childBookmark.DisplayStyle = PdfTextStyle.Regular
				EditChild2Bookmark(childBookmark)
			Next
		End Sub
		Private Shared Sub EditChild2Bookmark(childBookmark As PdfBookmark)
			For Each child2Bookmark As PdfBookmark In childBookmark
				child2Bookmark.Color = Color.LightSalmon
				child2Bookmark.DisplayStyle = PdfTextStyle.Italic
			Next
		End Sub
	End Class
End Namespace

Excel comments are used to add notes to individual cells and it works well to give the reader extra information for the data in the cells. There are articles to show how to add, change comments in Excel using Spire.XLS. This article is going to introduce the method to set the position and text alignment of Excel comments in C# using Spire.XLS.

Note: before start, please download the latest version of Spire.XLS and add the reference in the bin folder as the reference of Visual Studio.

Step 1: Create a new workbook and add a sheet.

            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

Step 2: Set two font styles which will be used in comments.

            ExcelFont font1 = workbook.CreateFont();
            font1.FontName = "Calibri";
            font1.Color = Color.Firebrick;
            font1.IsBold = true;
            font1.Size = 12;
            ExcelFont font2 = workbook.CreateFont();
            font2.FontName = "Calibri";
            font2.Color = Color.Blue;
            font2.Size = 12;
            font2.IsBold = true;

Step 3: Add comment 1 and set its size, text, position and alignment.

            ExcelComment Comment1 = sheet.Range["F5"].Comment;
            Comment1.IsVisible = true;
            Comment1.Height = 150;
            Comment1.Width = 300;
            Comment1.RichText.Text = "Spire.XLS for .Net:\nStandalone Excel component to meet your needs for conversion, data manipulation, charts in workbook etc. ";
            Comment1.RichText.SetFont(0, 19, font1);
            Comment1.TextRotation = TextRotationType.LeftToRight;
            //set the position of Comment
            Comment1.Top = 20;
            Comment1.Left = 40;
            //set the alignment of text in Comment
            Comment1.VAlignment = CommentVAlignType.Center;
            Comment1.HAlignment = CommentHAlignType.Justified;

Step 4: Add comment2 and set its size, text, position and alignment for comparison.

            ExcelComment Comment2= sheet.Range["F14"].Comment;
            Comment2.IsVisible = true;
            Comment2.Height = 150;
            Comment2.Width = 300;
            Comment2.RichText.Text = "About E-iceblue: \nWe focus on providing excellent office components for developers to operate Word, Excel, PDF, and PowerPoint documents.";
            Comment2.TextRotation = TextRotationType.LeftToRight;
            Comment2.RichText.SetFont(0, 16, font2);
            Comment2.Top = 170;
            Comment2.Left = 450;
            Comment2.VAlignment = CommentVAlignType.Top;
            Comment2.HAlignment = CommentHAlignType.Justified;

Step 5: Save the document and launch to see effect.

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

Effects:

How to set position and alignment for Excel comments in C#

Full Codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;
using System.Drawing;

namespace How_to_set_Excel_margin_to_print
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            ExcelFont font1 = workbook.CreateFont();
            font1.FontName = "Calibri";
            font1.Color = Color.Firebrick;
            font1.IsBold = true;
            font1.Size = 12;
            ExcelFont font2 = workbook.CreateFont();
            font2.FontName = "Calibri";
            font2.Color = Color.Blue;
            font2.Size = 12;
            font2.IsBold = true;

            ExcelComment Comment1 = sheet.Range["F5"].Comment;
            Comment1.IsVisible = true;
            Comment1.Height = 150;
            Comment1.Width = 300;
            Comment1.RichText.Text = "Spire.XLS for .Net:\nStandalone Excel component to meet your needs for conversion, data manipulation, charts in workbook etc. ";
            Comment1.RichText.SetFont(0, 19, font1);
            Comment1.TextRotation = TextRotationType.LeftToRight;
            Comment1.Top = 20;
            Comment1.Left = 40;
            Comment1.VAlignment = CommentVAlignType.Center;
            Comment1.HAlignment = CommentHAlignType.Justified;

            ExcelComment Comment2= sheet.Range["F14"].Comment;
            Comment2.IsVisible = true;
            Comment2.Height = 150;
            Comment2.Width = 300;
            Comment2.RichText.Text = "About E-iceblue: \nWe focus on providing excellent office components for developers to operate Word, Excel, PDF, and PowerPoint documents.";
            Comment2.TextRotation = TextRotationType.LeftToRight;
            Comment2.RichText.SetFont(0, 16, font2);
            Comment2.Top = 170;
            Comment2.Left = 450;
            Comment2.VAlignment = CommentVAlignType.Top;
            Comment2.HAlignment = CommentHAlignType.Justified;

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

With Spire.Presentation for .NET, developers can add different shapes to slides in C#. We can also use Spire.Presentation to formatting the lines of shape, such as the style, width, dash style and color of the line, etc. This article will show you how to set the format for the shape lines in C#. We will use rectangle for example. Here comes to the code snippet:

Step 1: Create a PPT document.

Presentation presentation = new Presentation();

Step 2: Add a rectangle shape to the slide.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 100));

Step 3: Set the fill color of the rectangle shape.

shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.White;

Step 4: Apply some formatting on the line of the rectangle.

shape.Line.Style = TextLineStyle.ThickThin;
shape.Line.Width = 5;
shape.Line.DashStyle = LineDashStyleType.Dash;

Step 5: Set the color of the line of the rectangle.

shape.ShapeStyle.LineColor.Color = Color.Red;

Step 6: Save the document to file.

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

Effective screenshot:

How to set the format for the shape lines in C

Full codes:

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace SetFormat
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();

            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 100));

            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.White;

            shape.Line.Style = TextLineStyle.ThickThin;
            shape.Line.Width = 5;
            shape.Line.DashStyle = LineDashStyleType.Dash;

            shape.ShapeStyle.LineColor.Color = Color.Red;

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

        }
    }
}

C#/VB.NET: Convert PDF to PDF/A

2022-07-13 01:01:00 Written by Koohji

PDF/A is an ISO-standardized version of PDF that supports archiving of files for future use. Documents in PDF/A format can be reproduced in exactly the same way regardless of the software used. Due to its advantages in long-term preservation of digital documents, it may sometimes be necessary to convert PDF to PDF/A. In this article, you will learn how to programmatically convert PDF to PDF/A-1A, 2A, 3A, 1B, 2B and 3B compliant PDF 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

Convert PDF to PDF/A

The detailed steps are as follows.

  • Specify the input file path and output folder
  • Create a PdfStandardsConverter instance and pass in the input file as a parameter.
  • Convert the input file to PdfA1A conformance level using PdfStandardsConverter.ToPdfA1A() method.
  • Convert the input file to PdfA1B conformance level using PdfStandardsConverter.ToPdfA1B() method.
  • Convert the input file to PdfA2A conformance level using PdfStandardsConverter.ToPdfA2A() method.
  • Convert the input file to PdfA2B conformance level using PdfStandardsConverter.ToPdfA2B() method.
  • Convert the input file to PdfA3A conformance level using PdfStandardsConverter.ToPdfA3A() method.
  • Convert the input file to PdfA3B conformance level using PdfStandardsConverter.ToPdfA3B() method.
  • C#
  • VB.NET
using System;
using Spire.Pdf.Conversion;

namespace ConvertPdf2Pdfa
{
    class Program
    {
        static void Main(string[] args)
        {
            //Specify input file path
            String inputFile = @"C:\Users\Administrator\Desktop\sample.pdf";

            //Specify output folder
            String outputFolder = @"C:\Users\Administrator\Desktop\Output\";

            //Create a PdfStandardsConverter instance, passing in the input file as a parameter
            PdfStandardsConverter converter = new PdfStandardsConverter(inputFile);

            //Convert to PdfA1A
            converter.ToPdfA1A(outputFolder + "ToPdfA1A.pdf");

            //Convert to PdfA1B
            converter.ToPdfA1B(outputFolder + "ToPdfA1B.pdf");

            //Convert to PdfA2A
            converter.ToPdfA2A(outputFolder + "ToPdfA2A.pdf");

            //Convert to PdfA2B
            converter.ToPdfA2B(outputFolder + "ToPdfA2B.pdf");

            //Convert to PdfA3A
            converter.ToPdfA3A(outputFolder + "ToPdfA3A.pdf");

            //Convert to PdfA3B
            converter.ToPdfA3B(outputFolder + "ToPdfA3B.pdf");
        }
    }
}

C#/VB.NET: Convert PDF to PDF/A

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 48