当前位置:网站首页>C#/VB. Net to delete watermarks in word documents

C#/VB. Net to delete watermarks in word documents

2022-07-07 02:25:00 51CTO

stay Word Watermarks added to documents , Such as text watermark or image watermark , Can effectively show ownership , It can also play a certain warning effect . But what if you want to delete these watermarks ? This article will provide a way to delete Word Methods of watermarking in documents . This method is suitable for deleting text watermark and image watermark . Here are the detailed methods and steps .


Program environment

In this test , Introduce... Into the program ​ ​Free Spire.Doc for .NET​​. Can be referenced by Spire.Doc.dll file :

Method 1: take Free Spire.Doc for .NET Download to local , decompression , install . After installation , Find the installation path BIN In folder Spire.Doc.dll. And then in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ Add reference ”, The local path BIN Under folder dll Add a reference to the program .

Method 2: adopt ​ ​NuGet​​ install . This can be done by 2 Methods of installation :

(1) Can be in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ management NuGet package ”, And then the search “Free Spire.Doc”, Click on “ install ”. Wait for the program installation to complete .

(2) Copy the following to PM Console installation .

Install-Package FreeSpire.Doc -Version 10.2.0

Specific steps :
  • initialization Document An instance of a class .
  • call Document.LoadFromFile(string fileName, FileFormat fileFormat) Method loading Word file .
  • take Document.Watermark Property is set to null.
  • adopt Document.SaveToFile(string fileName, FileFormat fileFormat) Method to save the result document to the specified path .
Complete code :

【C#】

      
      
using
using
using
using

namespace
{

class Program

{

static void Main( string[] args)

{
// Create a new one Word Document and load the document that needs to delete the watermark
Document doc = new

doc. LoadFromFile( "Sample.docx", FileFormat. Docx2013);

// Remove the watermark from the document
doc. Watermark = null;

// Save the document
doc. SaveToFile( "RemoveWatermark.docx", FileFormat. Docx2013);

}

}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.

VB.NET

      
      
Imports System
Imports System .Windows .Forms
Imports Spire .Doc
Imports Spire .Doc .Documents

Namespace RemoveWatermark

Class Program

Private Shared Sub Main( ByVal args() As String)

' Create a new one Word Document and load the document that needs to delete the watermark
Dim doc As Document = New Document

doc .LoadFromFile( "Sample.docx", FileFormat .Docx2013)

' Remove the watermark from the document
doc .Watermark = Nothing

' Save the document
doc .SaveToFile( "RemoveWatermark.docx", FileFormat .Docx2013)

End Sub

End Class

End Namespace
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.


design sketch :

C#/VB.NET Delete Word Watermarks in documents _C#


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061833044749.html