LoginSignup
0
0

More than 5 years have passed since last update.

C#でWord文書にテキストと画像の透かしを追加する

Last updated at Posted at 2018-08-21

透かしは、会社のウェブサイトのロゴやテキストなど、オリジナルのワードドキュメントにいくつかのユニークなコンテンツを追加して、そのドキュメントが著作権で保護されており、自由に使用できないことを他人に思い出させることを指します。
私たちのよく使われるウォーターマークは、イメージウォーターマークとテキストウォーターマークです。 この資料では、Spire.Docを使用してWordの文書に画像の透かしまたはテキストの透かしを追加する方法について詳しく説明します。

画像の透かしを追加
[C#]

Program.cs


            //新しい単語文書オブジェクトを作成し、透かしを入れる必要がある単語文書をロードする
            Document document = new Document();
            document.LoadFromFile("テスト.docx");
            //新しい画像透かしオブジェクトを作成し、画像を追加する
            PictureWatermark picture = new PictureWatermark();
            picture.Picture = System.Drawing.Image.FromFile("ピクチャ.jpg");
            //画像のサイズを設定し、それをウォーターマークとして設定する
            picture.Scaling = 100;
            picture.IsWashout = false;
            document.Watermark = picture;
            //ドキュメントを保存
            document.SaveToFile("画像の透かし.docx", FileFormat.Docx2010);

イメージウォーターマークレンダリング
1.jpg

テキストの透かしを追加
[C#]

Program.cs

            //新しい単語文書オブジェクトを作成し、透かしを入れる必要がある単語文書をロードする      
            Document document = new Document();
            document.LoadFromFile("テスト.docx");
            //新しいテキストウォーターマークオブジェクトを作成し、ウォーターマークとして設定されるテキストを追加する
            TextWatermark txtWatermark = new TextWatermark();
            txtWatermark.Text = "著作権";
            //テキストのフォントサイズ、色、配置を設定する
            txtWatermark.FontSize = 45;
            txtWatermark.Color = Color.Green;
            txtWatermark.Layout = WatermarkLayout.Diagonal;
            //Word文書の透かしとしてテキストを設定する
            document.Watermark = txtWatermark;
            //テキストを保存する
            document.SaveToFile("テキスト透かし.docx", FileFormat.Docx2010);'

テキストウォーターマークのレンダリング
2.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0