Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri May 17, 2024 10:46 am

Hi Team ,

how to add watermark only in one page .is it possible?

Thanks

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Mon May 20, 2024 2:34 am

Hi,

Thank you for your message and sorry to reply late for weekend.
Please note that the standard watermark in Microsoft Word cannot be added for a single page. However, you can refer to the following code to set a page as a separate Section and then add a watermark by inserting text or image in the header.

Code: Select all
        //Load the sample document
        Document doc = new Document();
        doc.loadFromFile("Sample.docx");

        //Add WordArt shape and set the size
        ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
        shape.setWidth(60);
        shape.setHeight(20);
        //Set the text, position and sytle for the wordart
        shape.setVerticalPosition(30);
        shape.setHorizontalPosition(20);
        shape.setRotation(315);
        shape.getWordArt().setText("Confidential");
        shape.setFillColor(Color.red);
        shape.setLineStyle(ShapeLineStyle.Single);
        shape.setStrokeColor(new Color(192, 192, 192, 255));
        shape.setStrokeWeight(1);

        // Add a section
        Section section = new Section(doc);
        doc.getSections().insert(0,section);
        HeaderFooter header;
        //Get the header of section
        header = section.getHeadersFooters().getHeader();
        Paragraph paragraph1 = header.addParagraph();
        // Insert shape into paragraph of header
        shape = (ShapeObject) shape.deepClone();
        shape.setVerticalPosition(200);
        shape.setHorizontalPosition(180);
        paragraph1.getChildObjects().add(shape);
        //Save the document to file
        doc.saveToFile("Result.docx", FileFormat.Docx_2013);


If there's still any issue, please provide your test file and tell us the page you want to add the watermark to and we'll investigate further.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 273
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.Doc