Spire.Presentation is a powerful and standalone .NET component which designed for developers to operate the PowerPoint documents in C# and VB.NET. Spire.Presentation enable developers to insert a new table, remove rows or columns in an existing table, and remove the whole table from the presentation slides. This article we will show you how to add a row to an existing table in presentation slide by using C# code.

Step 1: Create Presentation instance and load file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("table.pptx");

Step 2: Get the table within the PowerPoint document.

ITable table = ppt.Slides[0].Shapes[4] as ITable;

Step 3: Add a new row into the PowerPoint table and set the data for the cells in the new row.

//Get the first row
TableRow row = table.TableRows[0];
//Clone the row and add it to the end of table
table.TableRows.Append(row);
int rowCount = table.TableRows.Count;
//Get the last row
TableRow lastRow = table.TableRows[rowCount - 1];
//Set new data of the first cell of last row
lastRow[0].TextFrame.Text = " The first cell";
//Set new data of the second cell of last row
lastRow[1].TextFrame.Text = " The second cell";

Step 4: Save the document and preview it.

ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

Effective screenshot:

How to add a row to an existing table in PowerPoint documents

Full codes:

using Spire.Presentation;

namespace AddRow
{

    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("table.pptx");

            ITable table = ppt.Slides[0].Shapes[4] as ITable;
            TableRow row = table.TableRows[0];
            table.TableRows.Append(row);
            int rowCount = table.TableRows.Count;
            TableRow lastRow = table.TableRows[rowCount - 1];
            lastRow[0].TextFrame.Text = "The first cell";
            lastRow[1].TextFrame.Text = "The second cell";

            ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }
    }
}

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

page 251