Monday, 19 October 2020 08:37

Create Bubble Chart in Excel in C#/VB.NET

This article will show you how to use Spire.XLS for .NET to create a bubble chart in Excel in C# and VB.NET.

C#
using Spire.Xls;

namespace BubbleChart
{
    class Program
    {
        static void Main(string[] args)

        {
            //Create a new workbook
            Workbook workbook = new Workbook();

            //Add a worksheet and set name 
            workbook.CreateEmptySheets(1);
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "Chart data";
            //Initialize chart and set its type
            Chart chart = sheet.Charts.Add(ExcelChartType.Bubble);
            
            //Set the position of the chart in the worksheet
            chart.LeftColumn = 1;
            chart.RightColumn = 10;
            chart.TopRow = 1;
            chart.BottomRow = 20;

            //Set title for the chart and values
            Spire.Xls.Charts.ChartSerie cs1 = chart.Series.Add("Bubble Chart");
            cs1.EnteredDirectlyValues = new object[] { 2.2, 5.6 };
            cs1.EnteredDirectlyCategoryLabels = new object[] { 1.1, 4.4 };
            cs1.EnteredDirectlyBubbles = new object[] { 3, 6 };

            //Save the document to file
            workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010);
        }
    }
    
}
VB.NET
Imports Spire.Xls

Namespace BubbleChart
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Create a new workbook
            Dim workbook As Workbook = New Workbook
            'Add a worksheet and set name 
            workbook.CreateEmptySheets(1)
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.Name = "Chart data"
            'Initialize chart and set its type
            Dim chart As Chart = sheet.Charts.Add(ExcelChartType.Bubble)
            'Set the position of the chart in the worksheet
            chart.LeftColumn = 1
            chart.RightColumn = 10
            chart.TopRow = 1
            chart.BottomRow = 20
            'Set title for the chart and values
            Dim cs1 As Spire.Xls.Charts.ChartSerie = chart.Series.Add("Bubble Chart")
            cs1.EnteredDirectlyValues = New Object() {2.2, 5.6}
            cs1.EnteredDirectlyCategoryLabels = New Object() {1.1, 4.4}
            cs1.EnteredDirectlyBubbles = New Object() {3, 6}
            'Save the document to file
            workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010)
        End Sub
    End Class
End Namespace

Effective screenshot of Excel Bubble chart:

Create Bubble Chart in Excel in C#/VB.NET

We have already demonstrated how to insert HTML formatted text to a Presentation slide by using Spire.Presentation for Java. This article will introduce the way to insert HTML with images to PowerPoint and each html tag will be added to the slide as a separate shape.

import com.spire.presentation.*;
import com.spire.presentation.collections.*;

public class AddHTMLWithImage {
    public static void main(String[] args) throws Exception {
        //Create an instance of presentation document
        Presentation ppt = new Presentation();
        //Get the shapes on the first slide.
        ShapeList shapes = ppt.getSlides().get(0).getShapes();
        //Add contents to shapes from HTML codes, which includes text and image.
        shapes.addFromHtml("<html><div><p>E-iceblue</p>" +
                "<p><img src='https://cdn.e-iceblue.com/C:\\Users\\Test1\\Desktop\\logo.png'/></p>" +
                "<p>Spire.Presentation for Java</p></html>");

        //Save the document
        String result = "output/insertHtmlWithImage.pptx";
        ppt.saveToFile(result, FileFormat.PPTX_2013);
    }
}

Insert HTML with images into PowerPoint in Java

This article demonstrates how to add hyperlinks to SmartArt Nodes in a PowerPoint document in C# and VB.NET using Spire.Presentation for .NET.

C#
using Spire.Presentation;
using Spire.Presentation.Diagrams;

namespace SmartArt
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("SmartArt.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];
           
            //Get the SmartArt
            ISmartArt smartArt = slide.Shapes[0] as ISmartArt;

            //Add hyperlink to the first node of the SmartArt to link to a web page
            smartArt.Nodes[0].Click = new ClickHyperlink("https://www.e-iceblue.com");
            //Add hyperlink to the first node of the SmartArt to link to a specific slide
            smartArt.Nodes[1].Click = new ClickHyperlink(ppt.Slides[1]);

            //Save the result document
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);
        }
    }
}
VB.NET
Imports Spire.Presentation
Imports Spire.Presentation.Diagrams

Namespace SmartArt
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim ppt As Presentation = New Presentation()
            ppt.LoadFromFile("SmartArt.pptx")
            Dim slide As ISlide = ppt.Slides(0)
            Dim smartArt As ISmartArt = TryCast(slide.Shapes(0), ISmartArt)
            smartArt.Nodes(0).Click = New ClickHyperlink("https://www.e-iceblue.com")
            smartArt.Nodes(1).Click = New ClickHyperlink(ppt.Slides(1))
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

Output:

Add Hyperlinks to SmartArt Nodes in PowerPoint in C#, VB.NET

We have demonstrated how to use Spire.Doc for Java to add text watermark and image watermark to word document. This article will show you how to add WordArt to the Word header to get the multiple watermarks on the Word document:

Insert multiple text watermarks to Word

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ShapeLineStyle;
import com.spire.doc.documents.ShapeType;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;

public class WordWatermark {

    public static void main(String[] args) {

        //Load the sample document
        Document doc = new Document();
        doc.loadFromFile("Sample.docx");
        //Add WordArt shape and set the size
        ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
        shape.setWidth(60);
        shape.setHeight(20);
        //Set the text, position and sytle for the wordart
        shape.setVerticalPosition(30);
        shape.setHorizontalPosition(20);
        shape.setRotation(315);
        shape.getWordArt().setText("Confidential");
        shape.setFillColor(Color.red);
        shape.setLineStyle(ShapeLineStyle.Single);
        shape.setStrokeColor(new Color(192, 192, 192, 255));
        shape.setStrokeWeight(1);

        Section section;
        HeaderFooter header;
        for (int n = 0; n < doc.getSections().getCount(); n++) {
            section = doc.getSections().get(n);
            //Get the header of section
            header = section.getHeadersFooters().getHeader();
            Paragraph paragraph1;
            for (int i = 0; i < 4; i++) {
                //Add the hearder to the paragraph
                paragraph1 = header.addParagraph();
                for (int j = 0; j < 3; j++) {
                    //copy the word are and add it to many places
                    shape = (ShapeObject) shape.deepClone();
                    shape.setVerticalPosition(50 + 150 * i);
                    shape.setHorizontalPosition(20 + 160 * j);
                    paragraph1.getChildObjects().add(shape);
                }
            }
        }
        //Save the document to file
        doc.saveToFile("Result.docx", FileFormat.Docx_2013);

    }
}

Effective screenshot:

Java insert multiple text watermarks to Word document

Tuesday, 29 September 2020 08:40

Java Convert HTML to PDF

This article will demonstrate how to use Spire.Doc for Java to convert HTML string and HTML file to PDF in Java applications.

HTML String to PDF

import com.spire.doc.*;
import java.io.*;

public class htmlStringToWord {

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

        String inputHtml = "InputHtml.txt";
        //Create a new document
        Document document = new Document();
        //Add a section
        Section sec = document.addSection();

        String htmlText = readTextFromFile(inputHtml);
        //add a paragraph and append html string.
        sec.addParagraph().appendHTML(htmlText);

        //Save to PDF
        document.saveToFile("HTMLstringToPDF.pdf", FileFormat.PDF);
    }
    public static String readTextFromFile(String fileName) throws IOException{
        StringBuffer sb = new StringBuffer();
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String content = null;
        while ((content = br.readLine()) != null) {
            sb.append(content);
        }
        return sb.toString();
    }
}

Java Convert HTML to PDF

Convert HTML file to PDF

import com.spire.doc.*;
import com.spire.doc.documents.XHTMLValidationType;

public class htmlFileToWord {

    public static void main(String[] args) throws Exception {
        // Load the sample HTML file
        Document document = new Document();
        document.loadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None);

        //Save to file
        document.saveToFile("Result.pdf",FileFormat.PDF);
    }
}

Effective screenshot:

Java Convert HTML to PDF

Monday, 28 September 2020 01:49

Set Dpi when Converting Excel to Image in Java

This article demonstrates how to set dpi on x and y axis when converting an Excel worksheet to an image using Spire.XLS for Java.

import com.spire.xls.*;

public class ConvertExcelToImage {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook wb = new Workbook();

        //Load an Excel file
        wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

        //Set dpi on x and y axis
        wb.getConverterSetting().setXDpi(300);
        wb.getConverterSetting().setYDpi(300);

        //Declare a Worksheet variable
        Worksheet sheet;

        //Loop through the worksheets 
        for (int i = 0; i < wb.getWorksheets().size(); i++) {

            //Get the specific worksheet
            sheet = wb.getWorksheets().get(i);
            
            //Convert worksheet to image 
            sheet.saveToImage("C:\\Users\\Administrator\\Desktop\\Output\\image-" + i + ".png");
        }
    }
}

Set Dpi when Converting Excel to Image in Java

Sunday, 27 September 2020 07:14

Ungroup Shapes in PowerPoint in C#, VB.NET

This article demonstrates how to ungroup grouped shapes in a PowerPoint document using Spire.Presentation for .NET.

The input PowerPoint document:

Ungroup Shapes in PowerPoint in C#, VB.NET

C#
using Spire.Presentation;

namespace UngroupShapes
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("Sample.pptx");

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

            //Loop through the shapes in the slide
            for(int i = 0; i< slide.Shapes.Count;i++)
            {
                IShape shape = slide.Shapes[i];
                //Detect if the shape is a grouped shape
                if (shape is GroupShape)
                {
                    GroupShape groupShape = shape as GroupShape;
                    //Ungroup the grouped shape
                    slide.Ungroup(groupShape);
                }
            }

            //Save the resultant document
            ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013);
        }
    }
}
VB.NET
Imports Spire.Presentation

Namespace UngroupShapes
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim ppt As Presentation = New Presentation()
            ppt.LoadFromFile("Sample.pptx")
            Dim slide As ISlide = ppt.Slides(0)

            For i As Integer = 0 To slide.Shapes.Count - 1
                Dim shape As IShape = slide.Shapes(i)

                If TypeOf shape Is GroupShape Then
                    Dim groupShape As GroupShape = TryCast(shape, GroupShape)
                    slide.Ungroup(groupShape)
                End If
            Next

            ppt.SaveToFile("UngroupShapes.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

The output PowerPoint document after ungrouping shapes:

Ungroup Shapes in PowerPoint in C#, VB.NET

Start from Spire.PDF for Java 3.9.6, it supports converting SVG to PDF with several rows of codes, and adding a SVG image to PDF efficiently. This article will show you how to do it.

Convert SVG to PDF

Spire.PDF for Java offers the loadFromSvg method to load a SVG sample directly and then convert it to PDF file using the saveToFile method.

import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;

public class SVGToPDF {
    public static void main(String[] args) {
        //Load a SVG sample
        PdfDocument doc = new PdfDocument();
        doc.loadFromSvg("C:\\Users\\Test1\\Desktop\\logo.svg");
        //Save to PDF file
        doc.saveToFile("output/ToPDF.pdf", FileFormat.PDF);
    }
}

Output

Convert SVG to PDF and Add a SVG Image to PDF in Java

Add a SVG image to PDF

In addition to converting SVG to PDF, Spire.PDF for Java supports adding a SVG image to PDF. You can set the position and size of the image during the process.

import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import java.awt.*;
import java.awt.geom.Point2D;

public class AddSVGImagetoPDF {
    public static void main(String[] args) {
        //Load a SVG sample
        PdfDocument doc1 = new PdfDocument();
        doc1.loadFromSvg("C:\\Users\\Test1\\Desktop\\logo.svg");
        //Load a PDF sample
        PdfDocument doc2 = new PdfDocument();
        doc2.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pdf");
        //Set the position and size of the image
        doc2.getPages().get(0).getCanvas().drawTemplate(doc1.getPages().get(0).createTemplate(),
                new Point2D.Float(100,150), new Dimension(200,200) );
        //Save to PDF file
        doc2.saveToFile("output/AddSVGImagetoPDF.pdf", FileFormat.PDF);
        doc1.close();
        doc2.close();
    }
}

Output

Convert SVG to PDF and Add a SVG Image to PDF in Java

This article demonstrates how to add shadow effects to shapes in PowerPoint by using Spire.Presentation for Java. In addition to the PresetShadowEffect shown in this article, you can also add InnerShadowEffect, OuterShadowEffect and SoftEdgeEffect, etc.

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;

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

        //Create a Presentation instance
        Presentation ppt = new Presentation();

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Add a shape to the slide.
        Rectangle2D rect = new Rectangle2D.Float(120, 100, 150, 300);
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, rect);

        //Fill the shape with a picture
        shape.getFill().setFillType(FillFormatType.PICTURE);
        shape.getFill().getPictureFill().getPicture().setUrl("https://cdn.e-iceblue.com/C:\\Users\\Administrator\\Desktop\\img.png");
        shape.getLine().setFillType(FillFormatType.NONE);
        shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);

        //Set shadow effect
        PresetShadow presetShadow = new PresetShadow();
        presetShadow.setPreset(PresetShadowValue.BACK_RIGHT_PERSPECTIVE);
        presetShadow.getColorFormat().setColor(Color.lightGray);

        //Apply the shadow effect to shape
        shape.getEffectDag().setPresetShadowEffect(presetShadow);

        //Save the document
        ppt.saveToFile("output/ShapeShadow.pptx", FileFormat.PPTX_2013);
    }
}

Add Shadow Effects to Shapes in PowerPoint in Java

We have demonstrated how to use PresentationPrintDocument to print the presentation slides. This article will show you how to use PrinterSettings to print Presentation slides in Java applications.

import com.spire.ms.Printing.*;
import com.spire.presentation.*;
public class PrintPPT {

    public static void main(String[] args) throws Exception {
        //Load the sample document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Use PrinterSettings object to print presentation slides
        PrinterSettings ps = new PrinterSettings();
        ps.setPrintRange(PrintRange.AllPages);
        //ps.setPrintToFile(true);

        //Print the slide with frame
        presentation.setSlideFrameForPrint(true);

        //Print the slide with Grayscale
        presentation.setGrayLevelForPrint(true);

        //Print 4 slides horizontal
        presentation.setSlideCountPerPageForPrint(PageSlideCount.Four);
        presentation.setOrderForPrint(Order.Horizontal);

        //Only select some slides to print
        presentation.SelectSlidesForPrint("1", "3");

        //Print the document
        presentation.print(ps);
        presentation.dispose();
    }
}
Page 3 of 129