page 104

Spire.PDF for Java offers PdfDocument.saveAsImage() method to convert PDF document to image. From Version 4.11.1, Spire.PDF for Java supports to set the transparent value for the background of the resulted images during PDF to image conversion. This article will show you how to convert PDF to images with transparent background in Java applications.

Install Spire.PDF for Java

First of all, you need to add the Spire.PDF.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>11.11.11</version>
    </dependency>
</dependencies>

Convert PDF to Images with Transparent Background

  • Create an object of PdfDocument class.
  • Load a sample PDF document using PdfDocument.loadFromFile() method.
  • Specify the transparent value for the background of the resulted images using PdfDocument.getConvertOptions().setPdfToImageOptions() method.
  • Save the document to images using PdfDocument.saveAsImage() method.
  • Java
import com.spire.pdf.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;


public class PdftoImage {
    public static void main(String[] args) throws Exception {

        //Create an object of PdfDocument class.
        PdfDocument pdf = new PdfDocument();
        
        //Load the sample PDF document
        pdf.loadFromFile("Sample.pdf");
        
        //Specify the background transparent value as 0 during PDF to image conversion.
        pdf.getConvertOptions().setPdfToImageOptions(0);

        //Save PDF to .png image
        BufferedImage image = pdf.saveAsImage(0);
        File file = new File( String.format("ToImage.png"));
        ImageIO.write(image, "PNG", file);
    }
}

Java: Convert PDF to Images with Transparent Background

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.

When creating a new table in PowerPoint, the rows and columns are evenly distributed by default. As you insert data into the table cells, the row heights and column widths will be automatically adjusted to fit with the contents. To make the table nicely organized, you may want to re-distribute the rows and columns. This article demonstrates how to accomplish this task in C# and VB.NET using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

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

PM> Install-Package Spire.Presentation

Distribute Table Rows and Columns

The following are the steps to distribute table rows and columns evenly in PowerPoint.

  • C#
  • VB.NET
using Spire.Presentation;

namespace DistributeRowsAndColumns
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load the PowerPoint document
            presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\Table.pptx");

            //Get the first slide
            ISlide slide = presentation.Slides[0];

            //Loop through the shapes
            for (int i = 0; i < slide.Shapes.Count; i++)
            {
                //Determine if a shape is table
                if (slide.Shapes[i] is ITable)
                {
                    //Get the table in the slide
                    ITable table = (ITable)slide.Shapes[i];

                    //Distribute table rows
                    table.DistributeRows(0, table.TableRows.Count-1);

                    //Distribute table columns
                    table.DistributeColumns(0, table.ColumnsList.Count-1);

                }
            }

            //Save the result to file
            presentation.SaveToFile("DistributeRowsAndColumns.pptx", FileFormat.Pptx2013);
        }
    }
}
Imports Spire.Presentation
 
Namespace DistributeRowsAndColumns
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a Presentation instance
            Dim presentation As Presentation =  New Presentation() 
 
            'Load the PowerPoint document
            presentation.LoadFromFile("C:\Users\Administrator\Desktop\Table.pptx")
 
            'Get the first slide
            Dim slide As ISlide =  presentation.Slides(0) 
 
            'Loop through the shapes
            Dim i As Integer
            For  i = 0 To  slide.Shapes.Count- 1  Step  i + 1
                'Determine if a shape is table
                If TypeOf slide.Shapes(i) Is ITable Then
                    'Get the table in the slide
                    Dim table As ITable = CType(slide.Shapes(i), ITable)
 
                    'Distribute table rows
                    table.DistributeRows(0, table.TableRows.Count-1)
 
                    'Distribute table columns
                    table.DistributeColumns(0, table.ColumnsList.Count-1)
 
                End If
            Next
 
            'Save the result to file
            presentation.SaveToFile("DistributeRowsAndColumns.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

C#/VB.NET: Distribute Table Rows and Columns in PowerPoint

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.

C#/VB.NET: Replace a Picture in Excel

2021-11-05 01:15:01 Written by Koohji

Sometimes after you have finished an Excel workbook, you may need to replace some of the existing pictures with better ones for the purpose of making the workbook more appealing and persuasive. In this tutorial, you will learn how to replace a picture in Excel using Spire.XLS for .NET.

Install Spire.XLS for .NET

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

  • Package Manager
PM> Install-Package Spire.XLS

Replace a Picture in Excel

The following are the detailed steps to replace a picture with another one using Spire.XLS for .NET.

  • C#
  • VB.NET
using Spire.Xls;
using Spire.Xls.Collections;
using System.Drawing;

namespace ReplacePictureinExcel
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance 
            Workbook workbook = new Workbook();
            //Load the Excel file
            workbook.LoadFromFile (“Input.xls”);

            //Get the first sheet
            Worksheet sheet = workbook.Worksheets[0];

            //Get Excel picture collection
            PicturesCollection pictureCollection = sheet.Pictures;

            //Get the first picture from the collection 
            ExcelPicture excelPicture = pictureCollection[0];
            
            // Creates an Image from the specified file.
            excelPicture.Picture = Image.FromFile (image);

            //Save the document
            workbook.SaveToFile("ReplaceImage.xlsx", ExcelVersion.Version2013);
        }
    } 
}
Imports Spire.Xls
Imports Spire.Xls.Collections
Imports System.Drawing

Namespace ReplacePictureinExcel
	Class Program
		Private Shared Sub Main(args As String())

			'Create a Workbook instance 
			Dim workbook As New Workbook()
			'Load the Excel file
			workbook.LoadFromFile(Input.xls)

			'Get the first sheet
			Dim sheet As Worksheet = workbook.Worksheets(0)

			'Get Excel picture collection
			Dim pictureCollection As PicturesCollection = sheet.Pictures

			'Get the first picture from the collection 
			Dim excelPicture As ExcelPicture = pictureCollection(0)

			' Creates an Image from the specified file.
			excelPicture.Picture = Image.FromFile(image)

			'Save the document
			workbook.SaveToFile("ReplaceImage.xlsx", ExcelVersion.Version2013)
		End Sub
	End Class
End Namespace

The original file:

C#/VB.NET: Replace a Picture in Excel

The generated file:

C#/VB.NET: Replace a Picture in Excel

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 104

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details