Spire.Presentation offer developers an easy way to add the watermarks to the presentation slides. There are two kinds of watermarks in PowerPoint documents: text watermark and image watermark. We'll learn how to add image watermark in PowerPoint document via Spire.Presentation.

The goal of the article is to make an image as a background img watermark as following screenshot.

How to add image watermark in PowerPoint document in C#

Here comes to the steps of how to add image watermarks in C#:

Step 1: Create a presentation document and load the document from the file

Presentation ppt = new Presentation();
ppt.LoadFromFile(fileName);

Step 2: Get the image you want to add as image watermark.

IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));

Step 3: Set the properties of SlideBackground, and then fill the image as watermark.

ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType=PictureFillType.Stretch;
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

step4: Save the document to a new file.

ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);

Full codes:

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddimageWatermark
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(fileName);
            IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));
            ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

            if (fileExtensions == ".ppt")
            {
                ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);
            }
            else
            {
                ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.Pptx2007);
            }

            Viewer(resultFileName);
        }
    }
}

Sometimes we need to make use of the attachments added to the PDF files. There are 2 kinds of attachment in pdf, one is common attachment that added to the file directly, the other is attachment annotations which is add to the particular place as an annotation like the following picture, when you click correlative icon, that attachment will be opened.

In this article, we will learn how to extract these two kinds of attachment in C# via Spire.PdfViewer.

Extract the attachments from PDF document via PDFViewer

Here are the steps:

Step 1: Download PdfViewer, add PdfViewer Control to VS Toolbox (How to add control).

Extract the attachments from PDF document via PDFViewer

Step 2: Create a Windows Forms application, design Form as below.

  • Two buttons respectively for common attachment and attachment annotation, and set name for them.
  • One open file button and one close attachment button.
  • A PdfDocmentViewer in the middle and one ViewList on the bottom.

Step 3: Get attachments

1) Get common attachment via methord GetAttachments(), then traverse attachment array and get common attachment property.

PdfDocumentAttachment[] attchments = this.pdfDocumentViewer1.GetAttachments();
if (attchments != null && attchments.Length > 0)
         {
             for (int i = 0; i < attchments.Length; i++)
             {
                 PdfDocumentAttachment attachment = attchments[i];
                 string fileName = attachment.FileName;
                 string mimeType = attachment.MimeType;
                 string desc = attachment.Description;
                 DateTime createDate = attachment.CreationTime;
                 DateTime modifyDate = attachment.ModifyTime;
                 Object data = attachment.Data;
                 ListViewItem item = new ListViewItem();
                 item.Text = Path.GetFileName(fileName);
                 item.SubItems.Add(mimeType);
                 item.SubItems.Add(desc);
                 item.SubItems.Add(createDate.ToShortDateString());
                 item.SubItems.Add(modifyDate.ToShortDateString());
                 item.Tag = attachment;
                 this.listView1.Items.Add(item);
             }
         }

Results:

Extract the attachments from PDF document via PDFViewer

2) Extract attachment annotation:

Get attachment annotations via methord GetAttachmentAnnotaions(). Then traverse annotation array and save each annotation property as an individual item in listview.

PdfDocumentAttachmentAnnotation[] annotations = this.pdfDocumentViewer1.GetAttachmentAnnotaions();  
if (annotations != null && annotations.Length > 0)
         {
             for (int i = 0; i < annotations.Length; i++)
             {
                 PdfDocumentAttachmentAnnotation annotation = annotations[i];
                 ListViewItem item = new ListViewItem(annotation.FileName);
                 item.SubItems.Add(annotation.Text);
                 item.SubItems.Add(annotation.PageIndex.ToString());
                 item.SubItems.Add(annotation.Location.ToString());
                 item.Tag = annotation;
                 this.listView1.Items.Add(item);
             }
         }

Results:

Extract the attachments from PDF document via PDFViewer

3) ListView

Here if we click the file name information of annotation attachment in the listView, PdfDocumentViewer will go to specified attachment annotation.

if (this.m_isAttachmentAnnotation)
     {
         PdfDocumentAttachmentAnnotation annotation = (PdfDocumentAttachmentAnnotation)this.listView1.SelectedItems[0].Tag;
         this.pdfDocumentViewer1.GotoAttachmentAnnotation(annotation);
     }

Double click it, the attachment can be saved to local. Get data of annotation, and write into file.

PdfDocumentAttachmentAnnotation annotation = (PdfDocumentAttachmentAnnotation)item.Tag;
byte[] data = annotation.Data;
writer.Write(data);

About saving common attachment:

PdfDocumentAttachment annotation = (PdfDocumentAttachment)item.Tag;
byte[] data = annotation.Data;
writer.Write(data);

Spire.PDFViewer is a powerful PDF Viewer component performed on .NET and WPF. It enables developers to load PDF document from stream, file and byte array. Also it supports rotation, page layout setup and thumbnail control. Worth a shot. Click to know more

A chart filled with an image of company logo or propaganda is more impressive than a plain chart; adding a proper image into a chart as background will dramatically draw attention from your readers. As is similar to MS Excel, Spire.XLS enables users to insert pictures to specific chart elements such as chart area, bar area and plot area. In this article, I'll introduce how to enhance your chart by inserting image in chart area and plot area in C#, VB.NET.

Test File:

Fill Chart Elements with Pictures

Code Snippet for Inserting Background Image:

Step 1: Create a new workbook and load the test file

Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx");

Step 2: Get the first worksheet from workbook, get the first chart from worksheet.

Worksheet ws = workbook.Worksheets[0];
Chart chart = ws.Charts[0];

Step 3:

A) Insert chart area with a custom picture and set the transparency of plot area as 0.9. If you don't make plot area transparent, it will cover up the background image filled in chart area. Anyway, it all depends on your own needs.

chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");
chart.PlotArea.Fill.Transparency = 0.9;

B) Insert plot area with a custom picture

chart.PlotArea.Fill.CustomPicture(Image.FromFile("01.jpg"), "None");

Step 4: Save the file

workbook.SaveToFile("Sample.xlsx",ExcelVersion.Version2010);

Result:

A) Fill chart area with image

Fill Chart Elements with Pictures

B) Fill plot area with image

Fill Chart Elements with Pictures

Full Code:

[C#]
using Spire.Xls;
using System.Drawing;
namespace FillChartElement
{
    class Program
    {

        static void Main(string[] args)
        {

            Workbook workbook = new Workbook();
            workbook.LoadFromFile("test.xlsx");

            Worksheet ws = workbook.Worksheets[0];
            Chart chart = ws.Charts[0];

            // A. Fill chart area with image
            chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");
            chart.PlotArea.Fill.Transparency = 0.9;

            //// B.Fill plot area with image
            //chart.PlotArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");

            workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2010);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Drawing
Namespace FillChartElement
	Class Program

		Private Shared Sub Main(args As String())

			Dim workbook As New Workbook()
			workbook.LoadFromFile("test.xlsx")

			Dim ws As Worksheet = workbook.Worksheets(0)
			Dim chart As Chart = ws.Charts(0)

			' A. Fill chart area with image
			chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None")
			chart.PlotArea.Fill.Transparency = 0.9

			'''/ B.Fill plot area with image
			'chart.PlotArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");

			workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace
page 249