page 179

With Spire.Doc, we can set the formats for paragraph in C#. This article will focus on demonstrate how to set the spacing before and after the paragraph in C#.

Set the spacing before and after the paragraph for a newly added paragraph added by the method of paragraph.AppendHTML() to a new blank word document.

//create a new word document and add a section and paragraph to it.
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();

//Add the text strings to the paragraph and set the style
para.AppendHTML("

Add a new paragraph to the word and set the spacing

"); para.ApplyStyle(BuiltinStyle.Heading1); //set the spacing before and after para.Format.BeforeAutoSpacing = false; para.Format.BeforeSpacing = 20; para.Format.AfterAutoSpacing = false; para.Format.AfterSpacing = 20; //save the document to file doc.SaveToFile("Result1.docx");

How to set the spacing before and after the paragraph in C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace SetSpacing
{
 class Program
    {

     static void Main(string[] args)
     {
         //create a new word document and load the sample from file
         Document document = new Document();
         document.LoadFromFile("sample.docx", FileFormat.Docx);

         //Add the text strings to the paragraph and set the style
         Paragraph para = new Paragraph(document);
         TextRange textRange1 = para.AppendText("This is a inserted paragraph.");
         textRange1.CharacterFormat.TextColor = Color.Blue;
         textRange1.CharacterFormat.FontSize = 15;

         //set the spacing before and after
         para.Format.BeforeAutoSpacing = false;
         para.Format.BeforeSpacing = 10;
         para.Format.AfterAutoSpacing = false;
         para.Format.AfterSpacing = 10;

         //insert the added paragraph to the word document
         document.Sections[0].Paragraphs.Insert(1, para);

         //save the document to file
         document.SaveToFile("Result2.docx", FileFormat.Docx2010);
     }

    }
}

How to set the spacing before and after the paragraph in C#

Show or Hide PDF Layers in C#

2017-10-30 08:02:54 Written by Koohji

When creating a PDF layer, Spire.PDF allows developers to set an initial visibility state for the layer. While it also supports to change the visibility of existing layers in a PDF document. This article explains how to show or hide the existing layers using Spire.PDF.

PdfLayer.Visibility property is used to change the visibility of a PDF layer. To show a hidden layer, set the PdfLayer.Visibility property to PdfVisibility.On. To hide an existing layer, set the PdfLayer.Visibility to PdfVisibility.Off.

The following example shows how to hide a specific PDF layers:

using Spire.Pdf;
using Spire.Pdf.Graphics.Layer;

namespace HideLayer
{
    class Program
    {
        static void Main(string[] args)
        {
            using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
            {
                //Hide the layer by index
                doc.Layers[1].Visibility = PdfVisibility.Off;

                //Hide the layer by Name
                //doc.Layers["BlueLine"].Visibility = PdfVisibility.Off;

                //Save the file
                doc.SaveToFile("HideLayer.pdf");
            }
        }
    }
}

To show or hide all of the layers:

using Spire.Pdf;
using Spire.Pdf.Graphics.Layer;

namespace ShowLayer
{
    class Program
    {
        static void Main(string[] args)
        {
            using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
            {
                for (int i = 0; i < doc.Layers.Count; i++)
                {
                    //Show all of the layers 
                    //doc.Layers[i].Visibility = PdfVisibility.On;

                    //Hide all of the layers
                    doc.Layers[i].Visibility = PdfVisibility.Off;
                }
                //Save the file
                doc.SaveToFile("HideAllLayers.pdf");
            }
        }
    }
}

Screeshot of the sample PDF document:

Show or Hide PDF Layers in C#

Screenshot after hiding all of the layers:

Show or Hide PDF Layers in C#

Spire.Doc supports to add new shape and shape group to the word document, it also supports to remove the shapes from the word. This article will show you how to reset the size of shape on an existing word document via Spire.Doc.

Firstly, view the original shape on the word document:

C# reset the size of shape on the word

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

Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);

Step 2: Get the first section and the third paragraph that contains the shape.

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

Step 3: Get the shape and reset the width and height for the shape.

ShapeObject shape = para.ChildObjects[0] as ShapeObject;

shape.Width = 400;
shape.Height = 300;

Step 4: Save the document to file.

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

Effective screenshot of the shape after reset the size.

C# reset the size of shape on the word

Full codes:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Reset
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

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

            ShapeObject shape = para.ChildObjects[0] as ShapeObject;

            shape.Width = 400;
            shape.Height = 300;

            doc.SaveToFile("result.docx", FileFormat.Docx2010);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace Reset
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)

			Dim section As Section = doc.Sections(0)
			Dim para As Paragraph = section.Paragraphs(2)

			Dim shape As ShapeObject = TryCast(para.ChildObjects(0), ShapeObject)

			shape.Width = 400
			shape.Height = 300

			doc.SaveToFile("result.docx", FileFormat.Docx2010)
		End Sub
	End Class
End Namespace
page 179

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details