When there are overlapping shapes/images in your presentation slide, you can control which shape is under or above which shape by bring a shape forward or to front, or sending a shape backward or to back. The following example shows you how to bring a shape forward using Spire.Presentation with C# and VB.NET.

Code Snippets

[C#]
//load the sample PowerPoint file
Presentation presentation = new Presentation();
presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\input.pptx");

//get the specified shape
IShape shape = presentation.Slides[0].Shapes[0];

//bring the shape forward through SetShapeArrange method
shape.SetShapeArrange(ShapeArrange.BringForward);

//save to file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);
[VB.NET]
'load the sample PowerPoint file
Dim presentation As Presentation =  New Presentation() 
presentation.LoadFromFile("C:\Users\Administrator\Desktop\input.pptx")
 
'get the specified shape
Dim shape As IShape =  presentation.Slides(0).Shapes(0) 
 
'bring the shape forward through SetShapeArrange method
shape.SetShapeArrange(ShapeArrange.BringForward)
 
'save to file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013)

Output

Arrange Shapes in PowerPoint in C#, VB.NET

This article demonstrates how to read and remove built-in and custom document properties in Word document using Spire.Doc for Java.

Read document properties

Read built-in document properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){
        //Load Word document
        Document document = new Document("SetBuiltInProperties.docx");

        //Read built-in properties
        System.out.println("Title: " + document.getBuiltinDocumentProperties().getTitle());
        System.out.println("Subject: " + document.getBuiltinDocumentProperties().getSubject());
        System.out.println("author: " + document.getBuiltinDocumentProperties().getAuthor());
        System.out.println("company: " + document.getBuiltinDocumentProperties().getCompany());
        System.out.println("manager: " + document.getBuiltinDocumentProperties().getManager());
        System.out.println("category: " + document.getBuiltinDocumentProperties().getCategory());
        System.out.println("keyWords: " + document.getBuiltinDocumentProperties().getKeywords());
        System.out.println("comments: " + document.getBuiltinDocumentProperties().getComments());
    }
}

Read and Remove Document Properties in Word in Java

Read custom document properties

Remove built-in properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;


public class SetDocumentProperties {
    public static void main(String[] args){
        //Load Word document
        Document document = new Document("SetBuiltInProperties.docx");

        //Remove built-in properties by setting the value to null
        document.getBuiltinDocumentProperties().setTitle("");
        document.getBuiltinDocumentProperties().setSubject("");
        document.getBuiltinDocumentProperties().setAuthor("");
        document.getBuiltinDocumentProperties().setCompany("");
        document.getBuiltinDocumentProperties().setManager("");
        document.getBuiltinDocumentProperties().setCategory("");
        document.getBuiltinDocumentProperties().setKeywords("");
        document.getBuiltinDocumentProperties().setComments("");

        //Save the resultant document
        document.saveToFile("RemoveBuiltInProperties.docx", FileFormat.Docx_2013);
    }
}

Read and Remove Document Properties in Word in Java

Remove custom document properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){
        //Load Word document
        Document document = new Document("SetCustomProperties.docx");

        //Remove specific custom property by name
        document.getCustomDocumentProperties().remove("TrackingID");
        document.getCustomDocumentProperties().remove("Checked by");

        //Save the resultant document
        document.saveToFile("RemoveCustomProperties.docx", FileFormat.Docx_2013);
    }
}
Thursday, 20 June 2019 05:54

Add Fillable Forms to Word in Java

This article demonstrates how to insert fillable forms such as text boxes, check boxes and drop-down lists to a Word document using Spire.Doc for Java.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ParagraphStyle;
import com.spire.doc.documents.VerticalAlignment;
import com.spire.doc.fields.CheckBoxFormField;
import com.spire.doc.fields.DropDownFormField;
import com.spire.doc.fields.TextFormField;

public class CreateFormFields {

    public static void main(String[] args) {

        //create a Word document and add a section
        Document doc = new Document();
        Section section = doc.addSection();

        //add a table
        Table table = section.addTable();
        table.resetCells(3,2);

        //add text to the cells of the first column
        Paragraph paragraph = table.getRows().get(0).getCells().get(0).addParagraph();
        paragraph.appendText("Text Form Field");
        paragraph = table.getRows().get(1).getCells().get(0).addParagraph();
        paragraph.appendText("Check Box Form Field");
        paragraph = table.getRows().get(2).getCells().get(0).addParagraph();
        paragraph.appendText("Drop Down Form Field");

        //add a text form to the specific cell
        paragraph = table.getRows().get(0).getCells().get(1).addParagraph();
        TextFormField textField = (TextFormField) paragraph.appendField("textbox", FieldType.Field_Form_Text_Input);
        textField.setTextFieldType(TextFormFieldType.Regular_Text);

        //add a checkbox form to the specific cell
        paragraph = table.getRows().get(1).getCells().get(1).addParagraph();
        CheckBoxFormField checkboxField = (CheckBoxFormField)paragraph.appendField("checkbox", FieldType.Field_Form_Check_Box);

        //add a dropdown-list form to the specific cell
        paragraph = table.getRows().get(2).getCells().get(1).addParagraph();
        DropDownFormField dropdownField = (DropDownFormField)paragraph.appendField("listbox",FieldType.Field_Form_Drop_Down);
        dropdownField.getDropDownItems().add("Canada");
        dropdownField.getDropDownItems().add("United States");
        dropdownField.getDropDownItems().add("Other");

        //create a ParagraphStyle object
        ParagraphStyle style = new ParagraphStyle(doc);
        style.setName("newFont");
        style.getCharacterFormat().setFontName("Calibri");
        style.getCharacterFormat().setFontSize(13);
        doc.getStyles().add(style);

        for (int i = 0; i < table.getRows().getCount(); i++) {

            //set row height
            table.getRows().get(i).setHeight(30f);
            for (Object cell:table.getRows().get(i).getCells()){
                if (cell instanceof TableCell)
                {
                    //set the vertical alignment of each cell to middle
                    ((TableCell) cell).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);

                    //apply paragraph style to each cell
                    ((TableCell) cell).getParagraphs().get(0).applyStyle(style.getName());
                }
            }
        }

        //save to file
        doc.saveToFile("output/AddFormFields.docx", FileFormat.Docx_2013);
    }
}

Add Fillable Forms to Word in Java

Starts from version 7.6.5, Spire.Doc supports to add Latex math code to Word document in C#. This article will show you how to add Latex Math Symbols and equation to word document.

//create a word document
Document doc = new Document();

//add a section
Section section = doc.AddSection();

//add a paragraph to the section 
Paragraph paragraph = section.AddParagraph();

//add a LatexMathcode to the first paragraph
OfficeMath officeMath = new OfficeMath(doc);
paragraph.Items.Add(officeMath);
officeMath.FromLatexMathCode("x^{2}+\\sqrt{x^{2}+1}=2");

//add equation to the second paragraph
Paragraph paragraph2 = section.AddParagraph();
OfficeMath officeMath1 = new OfficeMath(doc);
paragraph2.Items.Add(officeMath1);
officeMath1.FromLatexMathCode("\\forall x \\in X, \\quad \\exists y \\leq \\epsilon");

//add symbols to the third paragraph
Paragraph paragraph3 = section.AddParagraph();
OfficeMath officeMath2 = new OfficeMath(doc);
paragraph3.Items.Add(officeMath2);
officeMath2.FromLatexMathCode(" \\alpha,\\beta, \\gamma, \\Gamma, \\pi, \\Pi, \\phi, \\varphi, \\mu, \\Phi");

//save the document to file       
doc.SaveToFile("Equation.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("Equation.docx");

Effective screenshot after adding latex math code and symbols to the word document:

C# insert math equation and symbol to Word document

Wednesday, 12 June 2019 09:31

Insert or Delete Text Box in Word in Java

This article demonstrates how to insert or remove a textbox in a Word document using Spire.Doc for Java.

Insert a text box

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.fields.TextBox;
import com.spire.doc.fields.TextRange;

import java.awt.*;

public class InsertTextbox {

    public static void main(String[] args) {

        //load a Word document
        Document doc = new Document();
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

        //append a textbox to paragraph
        TextBox tb = doc.getSections().get(0).addParagraph().appendTextBox(100f, 350f);

        //set the text wrapping style
        tb.getFormat().setTextWrappingStyle(TextWrappingStyle.Square);

        //set the position of textbox
        tb.getFormat().setHorizontalOrigin(HorizontalOrigin.Right_Margin_Area);
        tb.getFormat().setHorizontalPosition(-100f);
        tb.getFormat().setVerticalOrigin(VerticalOrigin.Page);
        tb.getFormat().setVerticalPosition(100f);

        //set the border style of textbox
        tb.getFormat().setLineStyle(TextBoxLineStyle.Thin_Thick);
        tb.getFormat().setLineColor(new Color(240,135,152));

        //insert an image to textbox as a paragraph
        Paragraph para = tb.getBody().addParagraph();
        DocPicture picture = para.appendPicture("C:\\Users\\Administrator\\Desktop\\logo-2.png");
        picture.setHeight(90f);
        picture.setWidth(80f);
        para.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
        para.getFormat().setAfterSpacing(15f);

        //insert text to textbox as the second paragraph
        para = tb.getBody().addParagraph();
        TextRange textRange = para.appendText("E-iceblue Co. Ltd., a vendor of .NET, Java and WPF "
                +"development components, is dedicated to render developers tremendous potential "
                +"to deal with their files in .NET, Java and WPF applications.");
        textRange.getCharacterFormat().setFontName("Cambria");
        textRange.getCharacterFormat().setFontSize(12f);
        para.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);

        //save to file
        doc.saveToFile("InsertTextbox.docx", FileFormat.Docx_2013);
    }
}

Insert or Delete a Text Box in Word in Java

Remove a text box

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class DeleteTextbox {

    public static void main(String[] args) {
        
        //load the Word document containing textbox
        Document doc = new Document();
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\textbox.docx");

        //remove textbox by index
        doc.getTextBoxes().removeAt(0);

        //remove all
        //doc.getTextBoxes().clear();

        //save to file
        doc.saveToFile("RemoveTextbox.docx", FileFormat.Docx);
    }
}
Tuesday, 11 June 2019 06:51

Java insert WordArt to word document

This article demonstrates how to add WordArt in a Word document in Java applications by using Spire.Doc for Java.

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;


public class WordArt{
    public static void main(String[] args) throws Exception {
        //create a Word document.
        Document doc = new Document();

        //add a section
        Section section = doc.addSection();

        //add a paragraph.
        Paragraph paragraph = section.addParagraph();

        //add a shape
        ShapeObject shape = paragraph.appendShape(250, 70, ShapeType.Text_Wave_4);

        //set the position of the shape
        shape.setVerticalPosition(80);
        shape.setHorizontalPosition(100);

        //set the text of WordArt
        shape.getWordArt().setText("Thanks for reading");

        //set the fill color
        shape.setFillColor(Color.RED);

        //set the border color of the text
        shape.setStrokeColor(Color.GRAY);

        //save the document to file.
        doc.saveToFile("output/wordart.docx", FileFormat.Docx_2013);
    }
}

Java insert WordArt to word document

Spire.Doc for Java supports adding the following two types of document properties to Word document:

  • Built-in document properties
  • Custom document properties

In this article, we will see how to use Spire.Doc for Java to add the above document properties into a Word document.

Add Built-In Document Properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){
        //Load Word document
        Document document = new Document("Input.docx");

        //Add built-in document properties to the Word document
        document.getBuiltinDocumentProperties().setTitle("Document Demo Document");
        document.getBuiltinDocumentProperties().setSubject("demo");
        document.getBuiltinDocumentProperties().setAuthor("James");
        document.getBuiltinDocumentProperties().setCompany("e-iceblue");
        document.getBuiltinDocumentProperties().setManager("Jakson");
        document.getBuiltinDocumentProperties().setCategory("Doc Demos");
        document.getBuiltinDocumentProperties().setKeywords("Document, Property, Demo");
        document.getBuiltinDocumentProperties().setComments("This document is just a demo.");

        //Save the resultant document
        document.saveToFile("SetBuiltInProperties.docx", FileFormat.Docx_2013);
    }
}

Add Document Properties to Word Document in Java

Add Custom Document Properties

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class SetDocumentProperties {
    public static void main(String[] args){

        //Load Word document
        Document document = new Document("Input.docx");

        //Add custom document properties to the Word document
        document.getCustomDocumentProperties().add("TrackingID", "AB01");
        document.getCustomDocumentProperties().add("Checked By", "Wilson");

        //Save the resultant document
        document.saveToFile("SetCustomProperties.docx", FileFormat.Docx_2013);

    }
}

Add Document Properties to Word Document in Java

Wednesday, 29 May 2019 07:35

Add Digital Signature to Word in C#

This article demonstrates how to add digital signature to a Word document using Spire.Doc.

Spire.Doc provides us the following methods to add digital signature to Word document:

  • public void SaveToFile(string fileName, FileFormat fileFormat, byte[] certificateData, string securePassword);
  • public void SaveToFile(string fileName, FileFormat fileFormat, string certificatePath, string securePassword);
  • public void SaveToStream(Stream stream, FileFormat fileFormat, byte[] certificateData, string securePassword);
  • public void SaveToStream(Stream stream, FileFormat fileFormat, string certificatePath, string securePassword);
  • public static byte[] Sign(Stream sourceStream, byte[] certificateData, string securePassword);
  • public static byte[] Sign(Stream sourceStream, string certificatePath, string securePassword);

In the following example, we'll see how to add digital signature to a Word document and save the result to file using the SaveToFile method with Document object.

//Load the Word document
Document doc = new Document("sample.docx");
//Sign the document with certificate and save to file
doc.SaveToFile("AddDigitalSignature.docx", FileFormat.Docx2013, "gary.pfx", "e-iceblue");

We can also add digital signature to a Word document and save the result to stream using the SaveToStream method with Document object.

//Load the Word document
Document doc = new Document("sample.docx");
//Create a FileStream
FileStream fs = new FileStream();
//Sign the document with certificate and save to stream
doc.SaveToStream(fs, FileFormat.Docx2013, "gary.pfx", "e-iceblue");
fs.Flush();

The following example shows how to add digital signature to a Word document using the Sign method with Document class.

//Read the Word document into a FileStream
FileStream fs = File.OpenRead("sample.docx");
//Sign the document using Sign method with Document class
byte[] result = Document.Sign(fs, "gary.pfx", "e-iceblue");
File.WriteAllBytes("AddDigitalSignature.docx", result);
fs.Flush();

The output document:

Add Digital Signature to Word in C#

Besides the Combo Box, Text, Date Picker and Drop-Down List content controls, Checkbox and picture content control also are the mostly used content control in word document. Spire.Doc supports to add many kinds of content controls to the word document. This article will show you how to add checkbox and picture content control to word document by Spire.Doc for .NET.

Code snippets of how to add checkbox and picture content control:

static void Main(string[] args)
{
    //Create a new word document
    Document document = new Document();

    //Add a section to the document
    Section section = document.AddSection();

    //Add a document to the section
    Paragraph paragraph = section.AddParagraph();

    //Add checkbox content control
    StructureDocumentTagInline sdt = new StructureDocumentTagInline(document);
    paragraph = section.AddParagraph();
    sdt = new StructureDocumentTagInline(document);
    sdt.CharacterFormat.FontSize = 20;
    paragraph.ChildObjects.Add(sdt);
    sdt.SDTProperties.SDTType = SdtType.CheckBox;
    SdtCheckBox scb = new SdtCheckBox();
    sdt.SDTProperties.ControlProperties = scb;
    TextRange tr = new TextRange(document);
    tr.CharacterFormat.FontName = "MS Gothic";
    tr.CharacterFormat.FontSize = 20;
    sdt.ChildObjects.Add(tr);
    scb.Checked = true;

    sdt.SDTProperties.Alias = "CheckoBox";
    sdt.SDTProperties.Tag = "Checkbox";

    //Add picture content control
    paragraph = section.AddParagraph();
    sdt = new StructureDocumentTagInline(document);
    paragraph.ChildObjects.Add(sdt);
    sdt.SDTProperties.ControlProperties = new SdtPicture();

    sdt.SDTProperties.Alias = "Picture";
    sdt.SDTProperties.Tag = "Picture";

    DocPicture pic = new DocPicture(document) { Width = 10, Height = 10 };
    pic.LoadImage(Image.FromFile("Logo.jpg"));
    sdt.SDTContent.ChildObjects.Add(pic);

    document.SaveToFile("Sample.docx", FileFormat.Docx2013);
}

Effective screenshot after adding checkbox and picture content control to word document:

Add checkbox and picture content control to word document in C#

This article demonstrates how to add text, images, lines and page numbers to the header or footer of a Word document by using Spire.Doc for Java.

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.fields.TextRange;

public class InsertHeaderAndFooter {

    public static void main(String[] args) {

        //load a Word document
        Document document = new Document();
        document.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

        //get the first section
        Section section = document.getSections().get(0);

        //call insertHeaderAndFooter method to add header and footer to the section
        insertHeaderAndFooter(section);

        //save to file
        document.saveToFile("output/HeaderAndFooter.docx", FileFormat.Docx);
    }

    private static void insertHeaderAndFooter(Section section) {

        //get header and footer from a section
        HeaderFooter header = section.getHeadersFooters().getHeader();
        HeaderFooter footer = section.getHeadersFooters().getFooter();

        //add a paragraph to header
        Paragraph headerParagraph = header.addParagraph();

        //insert a picture to header paragraph and set its position
        DocPicture headerPicture = headerParagraph.appendPicture("C:\\Users\\Administrator\\Desktop\\Logo.png");
        headerPicture.setHorizontalAlignment(ShapeHorizontalAlignment.Left);
        headerPicture.setVerticalOrigin(VerticalOrigin.Top_Margin_Area);
        headerPicture.setVerticalAlignment(ShapeVerticalAlignment.Bottom);

        //add text to header paragraph
        TextRange text = headerParagraph.appendText("Demo of Spire.Doc");
        text.getCharacterFormat().setFontName("Arial");
        text.getCharacterFormat().setFontSize(10);
        text.getCharacterFormat().setItalic(true);
        headerParagraph.getFormat().setHorizontalAlignment(HorizontalAlignment.Right);

        //set text wrapping to behind
        headerPicture.setTextWrappingStyle(TextWrappingStyle.Behind);

        //set the bottom border style of the header paragraph
        headerParagraph.getFormat().getBorders().getBottom().setBorderType(BorderStyle.Single);
        headerParagraph.getFormat().getBorders().getBottom().setLineWidth(1f);

        //add a paragraph to footer
        Paragraph footerParagraph = footer.addParagraph();

        //add Field_Page and Field_Num_Pages fields to the footer paragraph
        footerParagraph.appendField("page number", FieldType.Field_Page);
        footerParagraph.appendText(" of ");
        footerParagraph.appendField("number of pages", FieldType.Field_Num_Pages);
        footerParagraph.getFormat().setHorizontalAlignment(HorizontalAlignment.Right);

        //set the top border style of the footer paragraph
        footerParagraph.getFormat().getBorders().getTop().setBorderType(BorderStyle.Single);
        footerParagraph.getFormat().getBorders().getTop().setLineWidth(1f);
    }
}

Insert Header and Footer to Word in Java

Page 2 of 109