Edit Table in PowerPoint document

2014-06-10 03:57:22 Written by Koohji

Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. There is a document in our website introducing you how to insert table. And in this document, you will be introduced how to edit a table within a PPT document.

Step 1: Create a Presentation instance and load the file.

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

Step 2: Store the data used in replacement in string [].

string[] str = new string[] { "Germany", "Berlin", "Europe", "0152458", "20860000" };

Step 3: Get the table within the PPT document.

ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
    if (shape is ITable)
    {
        table = (ITable) shape;
    }
}

Step 4: Fill in the third row with new data and set the HighlightColor.

for (int i = 0; i < table.ColumnsList.Count;i++ )
{
    //replace the data in cell
    table[i, 2].TextFrame.Text = str[i];

    //set the highlightcolor
    table[i, 2].TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet;
}

Step 5: Set the style of the table.

table.StylePreset = TableStylePreset.LightStyle1Accent2;

Step 6: Save the document.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);

Download and install Spire.Presentation for .NET and refer to below code to edit table within PPT document.

Screenshots and full code:

Before:

Edit Table in PowerPoint document

After:

Edit Table in PowerPoint document

[C#]
using Spire.Presentation;
using System.Drawing;

namespace EditTable
{

    class Program
    {

        static void Main(string[] args)
        {
            //create a PPT document
            Presentation presentation = new Presentation();

            presentation.LoadFromFile("table.pptx");

            //the data used in replacement
            string[] str = new string[] { "Germany", "Berlin", "Europe", "0152458", "20860000" };

            ITable table = null;

            //get the table in PPT document
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //change the style of table
                    table.StylePreset = TableStylePreset.LightStyle1Accent2;

                    for (int i = 0; i < table.ColumnsList.Count; i++)
                    {
                        //replace the data in cell
                        table[i, 2].TextFrame.Text = str[i];

                        //set the highlightcolor
                        table[i, 2].TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet;
                    }
                }
            }

            //save the document
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }

    }
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing

Namespace EditTbale

	Class Program

		Private Shared Sub Main(args As String())
			'create a PPT document
			Dim presentation As New Presentation()

			presentation.LoadFromFile("table.pptx")

			'the data used in replacement
			Dim str As String() = New String() {"Germany", "Berlin", "Europe", "0152458", "20860000"}

			Dim table As ITable = Nothing

			'get the table in PPT document
			For Each shape As IShape In presentation.Slides(0).Shapes
				If TypeOf shape Is ITable Then
					table = DirectCast(shape, ITable)

					'change the style of table
					table.StylePreset = TableStylePreset.LightStyle1Accent2

					For i As Integer = 0 To table.ColumnsList.Count - 1
						'replace the data in cell
						table(i, 2).TextFrame.Text = str(i)

						'set the highlightcolor
						table(i, 2).TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet
					Next
				End If
			Next

			'save the document
			presentation.SaveToFile("result.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("result.pptx")

		End Sub

	End Class
End Namespace

If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.

Set X dimension of Barcode

2014-06-06 06:53:23 Written by Koohji

Spire.Barcode is a free .NET component specially designed for developers. It can generate many kinds of barcode such as EAN128, Codabar, DataMatrix, PostNet and so on. It can also scan the barcode images. X dimension is the measure of the narrowest bar in a barcode. Barcodes and scanners have different X dimensions, so they must be matched. Using Spire.Barcode, it is quiet an easy job to do this.

In this document, I will introduce you how to so.

Step 1: Create a BarcodeSettings instance.

BarcodeSettings setting = new BarcodeSettings();

Step 2: Set the data to render.

setting.Data = "58465157484";
setting.Data2D = "58465157484";

Step 3: Set the type of barcode to generate.

setting.Type = BarCodeType.UPCA;

Step 4: Set the value of X dimension.

setting.Unit = GraphicsUnit.Millimeter;
setting.X = 0.8F;

The property Unit specifies the measurement unit. In this sample, the measurement unit is millimeter.

Step 5: Generate barcode image using BarCodeGenerator.

BarCodeGenerator gen = new BarCodeGenerator(setting);
Image img = gen.GenerateImage();
img.Save("barcode.png");

Screenshot and Full Code:

Set X dimension of Barcode

[C#]
using Spire.Barcode;
using System.Drawing;


namespace SetXDimension
{
    class Program
    {
        static void Main(string[] args)
        {
            BarcodeSettings barsetting = new BarcodeSettings();

            //set the x dimension
            barsetting.X = 0.8f;
            barsetting.Unit = GraphicsUnit.Millimeter;

            barsetting.HasBorder = true;
            barsetting.BorderWidth = 0.5F;

            //set the data
            barsetting.Data = "58465157484";
            barsetting.Data2D = "58465157484";

            //generate UPCA barcode
            barsetting.Type = BarCodeType.UPCA;

            BarCodeGenerator bargenerator = new BarCodeGenerator(barsetting);
            Image barcodeimage = bargenerator.GenerateImage();
            barcodeimage.Save("barcode.png");

            System.Diagnostics.Process.Start("barcode.png");
        }
    }
}
[VB.NET]
Imports Spire.Barcode
Imports System.Drawing


Namespace SetXDimension
	Class Program
		Private Shared Sub Main(args As String())
			Dim barsetting As New BarcodeSettings()

			'set the x dimension
			barsetting.X = 0.8F
			barsetting.Unit = GraphicsUnit.Millimeter

			barsetting.HasBorder = True
			barsetting.BorderWidth = 0.5F

			'set the data
			barsetting.Data = "58465157484"
			barsetting.Data2D = "58465157484"

			'generate UPCA barcode
			barsetting.Type = BarCodeType.UPCA

			Dim bargenerator As New BarCodeGenerator(barsetting)
			Dim barcodeimage As Image = bargenerator.GenerateImage()
			barcodeimage.Save("barcode.png")

			System.Diagnostics.Process.Start("barcode.png")
		End Sub
	End Class
End Namespace

Blank pages in PDFs are not uncommon to find because they may have been left intentionally by the author or added accidentally when manipulating documents. These blank pages can be annoying when you are reading or printing the document, so it may be quite necessary to remove them. In this article you will learn how to programmatically find and remove blank pages from PDF documents using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Find and Delete Blank Pages from a PDF Document

Spire.PDF for .NET provides a method PdfPageBase.IsBlank() to detect if a PDF page is absolutely blank. But some pages that look blank actually contain white images, these pages won't be deemed as blank using the PdfPageBase.IsBlank() method. Therefore, it is necessary to create a custom method IsImageBlank() to be used in conjunction with PdfPageBase.IsBlank() method to detect these white but non-blank pages.

Note: This solution will convert PDF pages into images and detect if an image is blank. It is necessary to apply a license to remove the evaluation message in the converted images. Otherwise, this method won't work properly. If you do not have a license, contact sales@e-iceblue.com for a temporary one for evaluation purpose.

The detailed steps are as follows:

  • Create a PdfDocument instance.
  • Load a PDF document using PdfDocument.LoadFromFile() method.
  • Loop through the pages in the PDF document to detect if the pages are blank using PdfPageBase.IsBlank() method.
  • For absolutely blank pages, delete them using PdfDocument.Pages.RemoveAt() method.
  • For pages that are not absolutely blank, save them as images using PdfDocument.SaveAsImage() method. Then detect if the converted images are blank using custom method IsImageBlank() and remove the pages that are "blank" using PdfDocument.Pages.RemoveAt() method.
  • Save the result document using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace DeleteBlankPage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Apply license by license key
            Spire.Pdf.License.LicenseProvider.SetLicenseKey("your license key");

            //Create a PdfDocument instance
            PdfDocument document = new PdfDocument();

            //Load a sample PDF document
            document.LoadFromFile("input.pdf");

            //Loop through all pages in the PDF
            for (int i = document.Pages.Count - 1; i >= 0; i--)
            {
                //Detect if a page is blank
                if (document.Pages[i].IsBlank())
                {
                    //Remove the absolutely blank page
                    document.Pages.RemoveAt(i);
                }
                else
                {
                    //Save PDF page as image
                    Image image = document.SaveAsImage(i, PdfImageType.Bitmap);

                    //Detect if the converted image is blank
                    if (IsImageBlank(image))
                    {
                        //Remove the page
                        document.Pages.RemoveAt(i);
                    }
                }
            }

            //Save the result document
            document.SaveToFile("RemoveBlankPage.pdf", FileFormat.PDF);
        }

        //Detect if an image is blank
        public static bool IsImageBlank(Image image)
        {
            Bitmap bitmap = new Bitmap(image);
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    Color pixel = bitmap.GetPixel(i, j);
                    if (pixel.R < 240 || pixel.G < 240 || pixel.B < 240)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

C#/VB.NET: Find and Remove Blank Pages from PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

page 263