C # Set the background of a Word document (solid color/gradient/image background ),

Source: Internet
Author: User

C # Set the background of a Word document (solid color/gradient/image background ),

Word is an essential tool for document processing in our daily life, study, and work. Exquisite and beautiful documents can provide a visual aesthetic for reading. This article describes how to use the Free Spire. Doc for. NET (Community edition) component to set the document background for Word. In the following example, adding a background to a Word is described in three cases: adding a solid color background, gradient background, and image background.

Tool usage: After downloading and installing the Free Spire. Doc control, add Spire. Doc. dll to the project (This dll can be obtained in the Bin folder of the installation file)

I, Add solid color background
Using Spire. doc; using System. drawing; namespace AddBackground {class Program {static void Main (string [] args) {// create a Document class object and load the Word Document document = new Document (); Document. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ Test.docx"); // set the background filling mode of the document to color filling document. background. type = Spire. doc. documents. backgroundType. color; // set the background Color document. background. color = Color. mistyRose; // save and open the document. saveToFile ("PureBackground.docx", FileFormat. docx2013); System. diagnostics. process. start ("PureBackground.docx ");}}}

After debugging and running the program, generate a document

II, Add gradient background
Using Spire. doc; using System. drawing; using Spire. doc. documents; namespace AddGradientBackground {class Program {static void Main (string [] args) {// create a Document class instance and load the Word Document document = new Document (); Document. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ Test.docx"); // set the background filling mode of the document to gradient filling document. background. type = Spire. doc. documents. backgroundType. gradient; // set the gradient background color BackgroundGradient Gradient = document. background. gradient; gradient. color1 = Color. lightSkyBlue; gradient. color2 = Color. paleGreen; // set gradient in gradient mode. shadingVariant = GradientShadingVariant. shadingMiddle; gradient. shadingStyle = GradientShadingStyle. fromCenter; // save and open the document. saveToFile ("GradientColor.docx", FileFormat. docx2013); System. diagnostics. process. start ("GradientColor.docx ");}}}

3. Add an image background
Using System. drawing; using Spire. doc; namespace ImageBackground {class Program {static void Main (string [] args) {// create a Document class instance and load the Word Document document = new Document (); Document. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ Test.docx"); // set the background filling mode of the document to fill the document with images. background. type = Spire. doc. documents. backgroundType. picture; // set the background image document. background. picture = Image. fromFile (@ "C: \ Users \ Administrator \ Desktop \ 1.jpg"); // save and open the document. saveToFile ("ImageBackground.docx", FileFormat. docx2013); System. diagnostics. process. start ("ImageBackground.docx ");}}}

The preceding three methods are used to add the background of a Word document. If you like this article, you are welcome to reprint it. (For more information, see the source ).

Thank you for browsing!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.