Java settings word Page background color Word allows you to set a background setting color for different document layout design requirements. In general, you can import a single color, gradient, or a specified image and set it as the background. Set the background color of the bottom three Word pages in Java.
Add a single color background color </ b>
import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import java.awt.*;
import java.io.IOException;
public class BackgroundColor_Doc {
public static void main (String[] args) throws IOException{
//Load test document
String input="test.docx";
String output="backgroundcolor.docx";
Document doc = new Document(input);
//Set a monochrome background
doc.getBackground().setType(BackgroundType.Color);
doc.getBackground().setColor(Color.PINK);
//Save document
doc.saveToFile(output,FileFormat.Docx_2013);
}
}
Add gradient background color </ b>
import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import com.spire.doc.documents.GradientShadingStyle;
import com.spire.doc.documents.GradientShadingVariant;
import java.awt.*;
import java.io.IOException;
public class GradientBackground_Doc {
public static void main(String[] arg) throws IOException{
//Load test document
String input= "test.docx";
String output="GradientBackgound.docx";
Document doc = new Document(input);
//Gradient settings
doc.getBackground().setType(BackgroundType.Gradient);
doc.getBackground().getGradient().setColor1(Color.white);
doc.getBackground().getGradient().setColor2(Color.green);
doc.getBackground().getGradient().setShadingVariant(GradientShadingVariant.Shading_Middle);
doc.getBackground().getGradient().setShadingStyle(GradientShadingStyle.Horizontal);
//Save document
doc.saveToFile(output, FileFormat.Docx_2010);
}
}
Load image into background </ b>
import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import java.io.IOException;
public class ImgBackground_Doc {
public static void main(String[] arg) throws IOException {
//Load test document
String input= "test.docx";
String output="ImgBackgound.docx";
String img= "lye.png ";
Document doc = new Document(input);
//Set image background
doc.getBackground().setType(BackgroundType.Picture);
doc.getBackground().setPicture(img);
//Save document
doc.saveToFile(output, FileFormat.Docx);
}
}
Recommended Posts