冰蓝科技
|
028-81705109
|
|
微信扫一扫
|

Spire.Cloud 纯前端文档控件

Spire.XLS for Java 12.8.4已发布。此版本支持通过Worksheet.getMaxDispalyRange()方法获取所有单元格范围,包含其中的图片、形状等对象,并且支持=Days() 公式。此外,本次更新还增强了Excel 到 PDF的转换功能。一些已知问题也得到了修复,如修复了应用获取图表DataRange时抛出“NullPointerException”等问题。详情请阅读以下内容。

新功能:

问题修复:


下载Spire.XLS for Java 12.8.4 请点击:

https://www.e-iceblue.cn/Downloads/Spire-XLS-JAVA.html

Tab 1

此演示向您展示如何在 PowerPoint 文档中创建图表。

Data

e-iceblue

Option

e-iceblue
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

package ppt;

import com.spire.data.table.DataColumn;
import com.spire.data.table.DataRow;
import com.spire.data.table.DataTable;
import com.spire.pdf.tables.table.DataTypes;
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.charts.ChartType;
import com.spire.presentation.charts.IChart;

import java.awt.geom.Rectangle2D;

public class ChartDemo {
    public void chartDemoPpt(String resultFilePath, ChartType chartType) throws Exception {
        Presentation presentation = new Presentation();
        Rectangle2D rect1 = new Rectangle2D.Double(90, 100, 550, 320);
        IChart chart = presentation.getSlides().get(0).getShapes().appendChart(chartType, rect1, false);
        //chart title
        chart.getChartTitle().getTextProperties().setText("Chart");
        chart.getChartTitle().getTextProperties().isCentered(true);
        chart.getChartTitle().setHeight(30);
        chart.hasTitle( true);
        DataTable dataTable = getDataTable();
        insertDatatableToChart(chart,dataTable);
        //set series label
        chart.getSeries().setSeriesLabel(chart.getChartData().get("B1", "D1"));
        System.out.println(chart.getSeries().size());
       if (chartType.getName().contains("Scatter") || chartType.getName().contains("Bubble")){
            chart.getSeries().get(0).setXValues(chart.getChartData().get("A2", "A7"));
            chart.getSeries().get(0).setYValues(chart.getChartData().get("B2", "B7"));
            chart.getSeries().get(1).setYValues(chart.getChartData().get("C2", "C7"));
            chart.getSeries().get(2).setYValues(chart.getChartData().get("D2", "D7"));
            if (chartType.getName().contains("Bubble")){
                for (int i = 0; i < chart.getSeries().size();i++){
                    chart.getSeries().get(i).getBubbles().add(1);
                    chart.getSeries().get(i).getBubbles().add(4);
                    chart.getSeries().get(i).getBubbles().add(3);
                    chart.getSeries().get(i).getBubbles().add(4);
                    chart.getSeries().get(i).getBubbles().add(2);
                    chart.getSeries().get(i).getBubbles().add(9);
                }
            }
        }else {
            //set category label
            chart.getCategories().setCategoryLabels(chart.getChartData().get("A2", "A7"));
            //set values for series
            chart.getSeries().get(0).setValues(chart.getChartData().get("B2", "B7"));
            chart.getSeries().get(1).setValues(chart.getChartData().get("C2", "C7"));
            chart.getSeries().get(2).setValues(chart.getChartData().get("D2", "D7"));
            if (chartType.getName().contains("3D")){
                chart.getRotationThreeD().setXDegree(10);
                chart.getRotationThreeD().setYDegree(10);
            }
        }
        presentation.saveToFile(resultFilePath, FileFormat.PPTX_2013);

    }

    private DataTable getDataTable() throws Exception {
        DataTable dataTable = new DataTable();
        dataTable.getColumns().add(new DataColumn("SalesPers", DataTypes.DATATABLE_STRING));
        dataTable.getColumns().add(new DataColumn("SaleAmt", DataTypes.DATATABLE_INT));
        dataTable.getColumns().add(new DataColumn("ComPct", DataTypes.DATATABLE_INT));
        dataTable.getColumns().add(new DataColumn("ComAmt", DataTypes.DATATABLE_INT));
        DataRow row1 = dataTable.newRow();
        row1.setString("SalesPers", "Joe");
        row1.setInt("SaleAmt", 250);
        row1.setInt("ComPct", 150);
        row1.setInt("ComAmt", 99);
        DataRow row2 = dataTable.newRow();
        row2.setString("SalesPers", "Robert");
        row2.setInt("SaleAmt", 270);
        row2.setInt("ComPct", 150);
        row2.setInt("ComAmt", 99);
        DataRow row3 = dataTable.newRow();
        row3.setString("SalesPers", "Michelle");
        row3.setInt("SaleAmt", 310);
        row3.setInt("ComPct", 120);
        row3.setInt("ComAmt", 49);
        DataRow row4 = dataTable.newRow();
        row4.setString("SalesPers", "Erich");
        row4.setInt("SaleAmt", 330);
        row4.setInt("ComPct", 120);
        row4.setInt("ComAmt", 49);
        DataRow row5 = dataTable.newRow();
        row5.setString("SalesPers", "Dafna");
        row5.setInt("SaleAmt", 360);
        row5.setInt("ComPct", 150);
        row5.setInt("ComAmt", 141);
        DataRow row6 = dataTable.newRow();
        row6.setString("SalesPers", "Rob");
        row6.setInt("SaleAmt", 380);
        row6.setInt("ComPct", 150);
        row6.setInt("ComAmt", 135);
        dataTable.getRows().add(row1);
        dataTable.getRows().add(row2);
        dataTable.getRows().add(row3);
        dataTable.getRows().add(row4);
        dataTable.getRows().add(row5);
        dataTable.getRows().add(row6);
        return dataTable;
    }

    private void insertDatatableToChart(IChart chart, DataTable dataTable) throws Exception {
        for (int c = 0; c < dataTable.getColumns().size(); c++) {
            chart.getChartData().get(0, c).setText(dataTable.getColumns().get(c).getColumnName());
        }
        for (int r = 0; r < dataTable.getRows().size(); r++) {
            Object[] datas = dataTable.getRows().get(r).getArrayList();
            for (int c = 0; c < datas.length; c++) {
                chart.getChartData().get(r + 1, c).setValue(datas[c]);
            }
        }
    }
}
                        

Tab 3

using Spire.Presentation;
using Spire.Presentation.Charts;
using System;
using System.Data;
using System.Drawing;

namespace DemoOnlineCode
{
    class CreateCharts
    {
        public void ChartDemo(String resultFileName, ChartType chartType)
        {
            Presentation presentation = new Presentation();
            RectangleF rect1 = new RectangleF(90, 100, 550, 320);
            IChart chart = presentation.Slides[0].Shapes.AppendChart(chartType, rect1, false);
            //chart title
            chart.ChartTitle.TextProperties.Text = "Chart";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;
            DataTable dataTable = getDataTable();
            insertDatatableToChart(chart, dataTable);
            //set series label
            chart.Series.SeriesLabel = chart.ChartData["B1", "D1"];
            if (chartType.ToString().Contains("Scatter") || chartType.ToString().Contains("Bubble"))
            {
                chart.Series[0].XValues = chart.ChartData["A2", "A7"];
                chart.Series[0].YValues = chart.ChartData["B2", "B7"];
                chart.Series[1].XValues = chart.ChartData["A2", "A7"];
                chart.Series[1].YValues = chart.ChartData["C2", "C7"];
                chart.Series[2].XValues = chart.ChartData["A2", "A7"];
                chart.Series[2].YValues = chart.ChartData["D2", "D7"];
                if (chartType.ToString().Contains("Bubble"))
                {
                    for (int i = 0; i < chart.Series.Count; i++)
                    {
                        chart.Series[i].Bubbles.Add(1);
                        chart.Series[i].Bubbles.Add(4);
                        chart.Series[i].Bubbles.Add(3);
                        chart.Series[i].Bubbles.Add(4);
                        chart.Series[i].Bubbles.Add(2);
                        chart.Series[i].Bubbles.Add(9);
                    }
                }
            }
            else
            {
                //set category label
                chart.Categories.CategoryLabels = chart.ChartData["A2", "A7"];
                //set values for series
                chart.Series[0].Values = chart.ChartData["B2", "B7"];
                chart.Series[1].Values = chart.ChartData["C2", "C7"];
                chart.Series[2].Values = chart.ChartData["D2", "D7"];
                if (chartType.ToString().Contains("3D"))
                {
                    chart.RotationThreeD.XDegree = 10;
                    chart.RotationThreeD.YDegree = 10;
                }
            }
            presentation.SaveToFile(resultFileName+".pptx", FileFormat.Pptx2013);
        }

        private static DataTable getDataTable()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("SalesPers", typeof(String)));
            dataTable.Columns.Add(new DataColumn("SaleAmt", typeof(Int32)));
            dataTable.Columns.Add(new DataColumn("ComPct", typeof(Int32)));
            dataTable.Columns.Add(new DataColumn("ComAmt", typeof(Int32)));
            dataTable.Rows.Add("Jeo", 250, 150, 99);
            dataTable.Rows.Add("Robert", 270, 150, 99);
            dataTable.Rows.Add("Michelle", 310, 120, 49);
            dataTable.Rows.Add("Erich", 330, 120, 49);
            dataTable.Rows.Add("Dafna", 360, 150, 141);
            dataTable.Rows.Add("Rob", 380, 150, 135);
            return dataTable;
        }

        private static void insertDatatableToChart(IChart chart, DataTable dataTable)
        {
            for (int c = 0; c < dataTable.Columns.Count; c++)
            {
                chart.ChartData[0, c].Text = dataTable.Columns[c].ColumnName;
            }
            for (int r = 0; r < dataTable.Rows.Count; r++)
            {
                Object[] datas = dataTable.Rows[r].ItemArray;
                for (int c = 0; c < datas.Length; c++)
                {
                    chart.ChartData[r + 1, c].Value = datas[c];
                }
            }
        }
    }
}

                        

Tab 1

此演示向您展示如何将文本水印和图像水印添加到 PowerPoint 文档。

Set text watermark

Text:
Font:
Font Size:
Color:
Rotate:
e-iceblue
downloads

Set image watermark

Image:
Click here to browse files
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

package ppt;

import com.spire.presentation.*;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.IImageData;
import com.spire.presentation.drawing.PictureFillType;

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

public class WatermarkDemo {

    public void watermark(String filePath, String watermarkType, String text, String imageFile, String resultFilePath) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile(filePath);

        switch (watermarkType){
            case "TEXT":
                addTextWatermark(presentation,text);
                break;
            case "IMAGE":
                File file = new File(imageFile);
                BufferedImage bufferedImage = ImageIO.read(file);
                addImageWatermark(presentation,bufferedImage);
                break;
        }
        presentation.saveToFile(resultFilePath,FileFormat.PPTX_2013);

    }

    private void addTextWatermark(Presentation presentation, String text) throws Exception {
        int width= 400;
        int height= 300;
        Rectangle2D.Double rect = new Rectangle2D.Double((presentation.getSlideSize().getSize().getWidth() - width) / 2,
                (presentation.getSlideSize().getSize().getHeight() - height) / 2, width, height);
        for (int i = 0; i< presentation.getSlides().getCount();i++){
            IAutoShape shape = presentation.getSlides().get(i).getShapes().appendShape(ShapeType.RECTANGLE,rect);
            shape.getFill().setFillType(FillFormatType.NONE);
            shape.getShapeStyle().getLineColor().setColor(Color.white);
            shape.setRotation(-45);
            shape.getLocking().setSelectionProtection(true);
            shape.getLine().setFillType(FillFormatType.NONE);
            shape.getTextFrame().setText(text);
            PortionEx textRange = shape.getTextFrame().getTextRange();
            TextFont font = new TextFont("Arial Rounded MT Bold");
            textRange.setLatinFont(font);
            textRange.getFill().setFillType(FillFormatType.SOLID);
            textRange.getFill().getSolidColor().setColor(Color.RED);
            textRange.setFontHeight(22);
        }
    }

    private void addImageWatermark(Presentation presentation, BufferedImage bufferedImage) throws DocumentEditException {
        IImageData image = presentation.getImages().append(bufferedImage);
        for (int i = 0; i< presentation.getSlides().getCount();i++) {
            ISlide slide = presentation.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(image);
        }
    }
}
                        

Tab 3

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
using System.Windows.Forms;

namespace DemoOnlineCode
{
    class AddWatermark
    {

        public void AddTextOrImageWatermarkDemo(string filePath,string format,string text, string imagePath,  string resultFileName)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(filePath);
            switch (format)
            {
                case "TEXT":
                    AddTextWatermark(presentation,text,resultFileName);
                    break;
                case "IMAGE":
                    AddImageWatermark(presentation,imagePath,resultFileName);
                    break;
            }
        }


        private static void AddTextWatermark(Presentation presentation, string text, string resultFileName)
        {
            Form frm = new Form();
            Graphics gc = frm.CreateGraphics();
            SizeF size = gc.MeasureString(text, new Font("Lucida Sans Unicode", 50));

            //Define a rectangle range
            RectangleF rect = new RectangleF((presentation.SlideSize.Size.Width - size.Width) / 2, (presentation.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);

            foreach (ISlide slide in presentation.Slides)
            {
                IAutoShape shape =slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                //Set the style of the shape
                shape.Fill.FillType = FillFormatType.None;
                shape.ShapeStyle.LineColor.Color = Color.White;
                shape.Rotation = -45;
                shape.Locking.SelectionProtection = true;
                shape.Line.FillType = FillFormatType.None;

                //Add text to the shape
                shape.TextFrame.Text = text;
                TextRange textRange = shape.TextFrame.TextRange;
                //Set the style of the text range
                textRange.Fill.FillType = FillFormatType.Solid;
                textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                textRange.FontHeight = 50;
            }
            presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013);
        }

        private static void AddImageWatermark(Presentation presentation, string imageFile, string resultFileName)
        {
            IImageData image = presentation.Images.Append(Image.FromFile(imageFile));
            foreach (ISlide slide in presentation.Slides)
            {
                slide.SlideBackground.Type = BackgroundType.Custom;
                slide.SlideBackground.Fill.FillType = FillFormatType.Picture;
                slide.SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
                slide.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
            }
            presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013);
        }
    }
}

                        

Tab 1

此演示向您展示如何将文本和图像添加到 PowerPoint 文档。

Add text

Text:
Font:
Font Size:
Color:
downloads

Add image

Image:
Click here to browse files
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

package ppt;

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;



public class AddTextOrImageDemo {

    public void addTextOrImage(String filePath, String addType, String text, String imageFile, String resultFilePath) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile(filePath);

        switch (addType){
            case "TEXT":
                addText(presentation,text);
                break;
            case "IMAGE":
                addImage(presentation,imageFile);
                break;
        }
        presentation.saveToFile(resultFilePath,FileFormat.PPTX_2013);
    }

    private void addText(Presentation presentation, String text) throws Exception {
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(50, 70, 620, 150));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getShapeStyle().getLineColor().setColor(Color.white);
        shape.getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.LEFT);
        shape.getTextFrame().getParagraphs().get(0).setIndent(50);
        shape.getTextFrame().getParagraphs().get(0).setLineSpacing(150);
        shape.getTextFrame().setText(text);
        shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setLatinFont(new TextFont("Arial Rounded MT Bold"));
        shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setFontHeight(16);
        shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
        shape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().getSolidColor().setColor(Color.RED);
    }

    private void addImage(Presentation presentation, String imageFile) throws Exception {
        Rectangle2D.Double rect1 = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 280, 140, 120, 120);
        IEmbedImage image = presentation.getSlides().get(0).getShapes().appendEmbedImage(ShapeType.RECTANGLE, imageFile, rect1);
        image.getLine().setFillType(FillFormatType.NONE);
    }
}
                        

Tab 3

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoOnlineCode
{
    class AddTextOrImage
    {
        public void AddTextOrImageDemo(string format, string text, string imageFilePath, string resultFileName)
        {
            Presentation presentation = new Presentation();
            switch (format)
            {
                case "TEXT":
                    AddText(presentation,text,resultFileName);
                    break;
                case "IMAGE":
                    AddImage(presentation, imageFilePath, resultFileName);
                    break;
            }

        }
        private static void AddText(Presentation presentation, string text, string resultFileName)
        {
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 620, 150));
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;

            //Set the alignment of paragraph
            shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
            //Set the indent of paragraph
            shape.TextFrame.Paragraphs[0].Indent = 50;
            //Set the linespacing of paragraph
            shape.TextFrame.Paragraphs[0].LineSpacing = 150;
            //Set the text of paragraph
            shape.TextFrame.Text = text;

            //Set the Font
            shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

            presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013);
        }

        private static void AddImage(Presentation presentation, string imageFilePath, string resultFileName)
        {
            RectangleF rect1 = new RectangleF(presentation.SlideSize.Size.Width / 2 - 280, 140, 120, 120);
            IEmbedImage image = presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, imageFilePath, rect1);
            image.Line.FillType = FillFormatType.None;
            presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013);
        }

    }
}

                        

Tab 1

此演示向您展示如何在 PowerPoint 文档中搜索特定文本并替换匹配的文本。

Upload

Maximum file size: 1 MB. Files accepted: ppt, pptx.
Click here to browse files.
fileerrors

Convert to

Source file:
filename
Search Text:
Replace Text:
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

package ppt;

import com.spire.presentation.*;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class FindAndReplaceDemo {

    public void findOrReplace(String filePath,String changeType, String text, String newText, String resultFilePath) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile(filePath);
        switch (changeType){
            case "FIND":
                findText(presentation,text);
                break;
            case "REPLACE":
                replaceText(presentation,text,newText);
                break;
        }
        presentation.saveToFile(resultFilePath,FileFormat.PPTX_2013);
    }

    private void findText(Presentation presentation, String text){
        for(int i = 0; i < presentation.getSlides().getCount();i++){
            ISlide slide = presentation.getSlides().get(i);
            for (int j = 0; j < slide.getShapes().getCount();j++){
                IAutoShape shape = (IAutoShape)slide.getShapes().get(j);
                TextHighLightingOptions options = new TextHighLightingOptions();
                options.setWholeWordsOnly(true);
                options.setCaseSensitive(true);
                shape.getTextFrame().highLightText(text, Color.yellow, options);
            }
        }
    }

    private void replaceText(Presentation presentation, String oldText, String newText){
        for(int i = 0; i < presentation.getSlides().getCount();i++){
            ISlide slide = presentation.getSlides().get(i);
            Map map = new HashMap<>();
            map.put(oldText,newText);
            replaceTags(slide,map);
        }
    }

    private static void replaceTags(ISlide pSlide, Map tagValues) {
        for (int i = 0; i < pSlide.getShapes().getCount(); i++) {
            IShape curShape = pSlide.getShapes().get(i);
            if (curShape instanceof IAutoShape) {
                for (int j = 0; j < ((IAutoShape) curShape).getTextFrame().getParagraphs().getCount(); j++) {
                    ParagraphEx tp = ((IAutoShape) curShape).getTextFrame().getParagraphs().get(j);
                    for (Map.Entry entry : tagValues.entrySet()) {
                        String mapKey = entry.getKey();
                        String mapValue = entry.getValue();
                        if (tp.getText().contains(mapKey)) {
                            tp.setText(tp.getText().replace(mapKey, mapValue));
                        }
                    }
                }
            }
        }
    }
}
                        

Tab 3

using Spire.Presentation;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoOnlineCode
{
    class HighlightOrReplace
    {
        public void HighlightOrReplaceDemo(string filePath, string format, string text, string newText,  string resultFileName)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(filePath);
            switch (format)
            {
                case "HIGHLIGHT":
                    HighlightText(presentation,text,resultFileName);
                    break;

                case "REPLACE":
                    ReplaceText(presentation, text, newText, resultFileName);
                    break;
            }
        }

        private static void HighlightText(Presentation presentation, string text, string resultFileName)
        {
            foreach (ISlide slide in presentation.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    if (shape is IAutoShape)
                    {
                        IAutoShape autoShape = shape as IAutoShape;
                        TextHighLightingOptions options = new TextHighLightingOptions();
                        options.WholeWordsOnly = true;
                        options.CaseSensitive = true;
                        autoShape.TextFrame.HighLightText(text, Color.Yellow, options);
                    }
                }
            }
            presentation.SaveToFile(resultFileName+".pptx", FileFormat.Pptx2013);
        }

        private static void ReplaceText(Presentation presentation, string oldText, string newText, string resultFileName)
        {
            Dictionary tagValues = new Dictionary();
            tagValues.Add(oldText,newText);
            foreach (ISlide slide in presentation.Slides)
            {
                ReplaceTags(slide, tagValues);
            }
            presentation.SaveToFile(resultFileName + ".pptx", FileFormat.Pptx2013);
        }
        private static void ReplaceTags(ISlide pSlide, Dictionary TagValues)
        {
            foreach (IShape curShape in pSlide.Shapes)
            {
                if (curShape is IAutoShape)
                {
                    foreach (TextParagraph tp in (curShape as IAutoShape).TextFrame.Paragraphs)
                    {
                        foreach (var curKey in TagValues.Keys)
                        {
                            if (tp.Text.Contains(curKey))
                            {
                                tp.Text = tp.Text.Replace(curKey, TagValues[curKey]);
                            }
                        }
                    }
                }
            }
        }

    }
}

                        

Tab 1

此演示向您展示如何将 PowerPoint 文档 ( ppt/pptx ) 转换为 PDF、HTML、图像、XPS 和 Tiff。

Upload

Maximum file size: 1 MB. Files accepted: ppt , pptx.
Click here to browse files.
fileerrors

Convert to

Source file:
filename
Target file type:
e-iceblue

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

package ppt;

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

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

public class ConvertDemo {

    public void convertDemo(String filePath, String convertTo, String resultFileName) throws Exception {
        Presentation presentation = new Presentation();
        presentation.loadFromFile(filePath);
        ConvertFormat(presentation, convertTo,resultFileName);
    }


    private void ConvertFormat(Presentation presentation, String convertTo, String resultFileName) throws Exception {
        switch (convertTo){
            case "PDF":
                presentation.saveToFile(resultFileName+".pdf", FileFormat.PDF);
                break;

            case "HTML":
                presentation.saveToFile(resultFileName+".html",FileFormat.HTML);
                break;

            case "IMAGE":
                BufferedImage[] images = new BufferedImage[presentation.getSlides().getCount()];
                for (int i = 0; i< presentation.getSlides().getCount();i++){
                    images[i] = presentation.getSlides().get(i).saveAsImage();
                }
                if (images != null && images.length > 0){
                    if (images.length == 1){
                        ImageIO.write(images[0],".PNG", new File(resultFileName+".png"));
                    }
                }else {
                    for (int j = 0; j < images.length;j++){
                        String fileName = String.format("image-{0}.png",j);
                        ImageIO.write(images[j],".PNG",new File(fileName));
                    }
                }
                break;

            case "XPS":
                presentation.saveToFile(resultFileName+".xps",FileFormat.XPS);
                break;

            case "TIFF":
                presentation.saveToFile(resultFileName+".tiff",FileFormat.TIFF);
                break;
        }
    }
}
                        

Tab 3

using Spire.Presentation;
using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace DemoOnlineCode
{
    class Convertors
    {
        public void demoConvert(string filePath, string format, string resultFileName)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(filePath);
            ConvertFormat(presentation,format,resultFileName);
        }
        private static void ConvertFormat(Presentation presentation, string format, string resultFileName)
        {
            switch (format)
            {
                case "PDF":
                    presentation.SaveToFile(resultFileName + ".PDF", FileFormat.PDF);
                    break;

                case "HTML":
                    presentation.SaveToFile(resultFileName + ".html", FileFormat.Html);
                    break;

                case "IMAGE":
                    Image[] images = new Image[presentation.Slides.Count];
                    for (int i = 0; i < presentation.Slides.Count;i++)
                    {
                        images[i] = presentation.Slides[i].SaveAsImage();
                    }
                    if (images != null && images.Length > 0)
                    {
                        if (images.Length == 1)
                        {
                            images[0].Save(resultFileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                        }
                        else
                        {
                            for (int i = 0; i < images.Length; i++)
                            {
                                string fileName = string.Format("{0}-Image-{1}.png", resultFileName, i);
                                images[i].Save(fileName, ImageFormat.Png);
                            }
                        }
                    }
                        break;

                case "XPS":
                    presentation.SaveToFile(resultFileName + ".xps", FileFormat.XPS);
                    break;

                case "TIFF":
                    Image[] images2 = new Image[presentation.Slides.Count];
                    if (images2 != null && images2.Length > 0)
                    {
                        for (int i = 0; i < presentation.Slides.Count; i++)
                        {
                            images2[i] = presentation.Slides[i].SaveAsImage();
                        }
                            JoinTiffImages(images2,resultFileName+ ".tiff", EncoderValue.CompressionLZW);
                    }
                    break;
            }
        }

        private static ImageCodecInfo GetEncoderInfo(string mimeType)
        {
            ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
            for (int j = 0; j < encoders.Length; j++)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }

            throw new Exception(mimeType + " mime type not found in ImageCodecInfo");
        }

        public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder)
        {
            //Use the save encoder
            System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag;

            EncoderParameters ep = new EncoderParameters(2);
            ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
            ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)compressEncoder);

            Image pages = null;
            int frame = 0;
            ImageCodecInfo info = GetEncoderInfo("image/tiff");

            foreach (Image img in images)
            {
                if (frame == 0)
                {
                    pages = img;

                    //Save the first frame
                    pages.Save(outFile, info, ep);
                }
                else
                {
                    //Save the intermediate frames
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);

                    pages.SaveAdd(img, ep);
                }

                if (frame == images.Length - 1)
                {
                    //Flush and close
                    ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
                    pages.SaveAdd(ep);
                }
                frame++;
            }
        }

    }
}

                        

Tab 1

此演示向您展示如何将文本水印或图像水印添加到 PDF 文档。

Upload

Maximum file size: 1 MB. Files accepted: pdf.
Click here to browse files.
Source file:
filename
fileerrors

Set text watermark

Text:
Font:
Font Size:
Color:
downloads

Set image watermark

Image:
Click here to browse files
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.graphics.*;

import java.awt.*;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;


public class PdfWatermarkDemo {

    public void addWatermark(String pdfFile, String watermarkType, String text, byte[] imageData){
        String outputFile = "output.pdf";

        PdfDocument pdf=new PdfDocument();
        pdf.loadFromFile(pdfFile);
        switch (watermarkType) {
            case "Text":
                addTextWatermark(pdf, text);
                break;
            case "Image":
                addImageWatermark(pdf, imageData);
                break;
        }
        pdf.saveToFile(outputFile, FileFormat.PDF);
        pdf.close();
    }
    public void addImageWatermark(PdfDocument pdf, byte[] imgData) {
        PdfImage image = PdfImage.fromStream(new ByteArrayInputStream(imgData));
        for (int i = 0; i < pdf.getPages().getCount(); i++) {
            PdfPageBase page = pdf.getPages().get(i);
            page.getCanvas().save();
            page.getCanvas().setTransparency(0.5f, 0.5f, PdfBlendMode.Multiply);
            page.getCanvas().drawImage(image, new Point2D.Float(160, 260));
            page.getCanvas().restore();
        }
    }
    public void addTextWatermark(PdfDocument pdf, String text) {
        for (int i = 0; i < pdf.getPages().getCount(); i++) {
            PdfPageBase page = pdf.getPages().get(i);
            Dimension2D dimension2D = new Dimension();
            dimension2D.setSize(page.getCanvas().getClientSize().getWidth() / 2, page.getCanvas().getClientSize().getHeight() / 3);
            PdfTilingBrush brush = new PdfTilingBrush(dimension2D);
            brush.getGraphics().setTransparency(0.3F);
            brush.getGraphics().save();
            brush.getGraphics().translateTransform((float) brush.getSize().getWidth() / 2, (float) brush.getSize().getHeight() / 2);
            brush.getGraphics().rotateTransform(-45);
            brush.getGraphics().drawString(text, new PdfTrueTypeFont(new Font("Arial", Font.BOLD, 80), true), PdfBrushes.getViolet(), 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
            brush.getGraphics().restore();
            brush.getGraphics().setTransparency(0.5);
            Rectangle2D loRect = new Rectangle2D.Float();
            loRect.setFrame(new Point2D.Float(0, 0), page.getCanvas().getClientSize());
            page.getCanvas().drawRectangle(brush, loRect);
        }
    }
}
                        

Tab 3

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.IO;

namespace DemoOnlineCode
{
    class WatermarkDemo
    {
        public void addWatermark(string pdfFile, string watermarkType, string text, byte[] imageData)
        {
            string outputFile = "output.pdf";

            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(pdfFile);
            switch (watermarkType)
            {
                case "Text":
                    addTextWatermark(pdf, text);
                    break;
                case "Image":
                    addImageWatermark(pdf, imageData);
                    break;
            }
            pdf.SaveToFile(outputFile, FileFormat.PDF);
            pdf.Close();
        }
        public void addImageWatermark(PdfDocument pdf, byte[] imgData)
        {
            PdfImage image = PdfImage.FromStream(new MemoryStream(imgData));
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                PdfPageBase page = pdf.Pages[i];
                page.Canvas.Save();
                page.Canvas.SetTransparency(0.5f, 0.5f, PdfBlendMode.Multiply);
                page.Canvas.DrawImage(image, new System.Drawing.PointF(160,260));
                page.Canvas.Restore();
            }
        }
        public void addTextWatermark(PdfDocument pdf, string text)
        {
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                PdfPageBase page = pdf.Pages[i];

                PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
                brush.Graphics.SetTransparency(0.3F);
                brush.Graphics.Save();
                brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
                brush.Graphics.RotateTransform(-45);
                brush.Graphics.DrawString(text, new PdfTrueTypeFont(new Font("Arial",80,FontStyle.Bold), true), PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
                brush.Graphics.Restore();
                brush.Graphics.SetTransparency(0.5f);
                page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
            }
        }
    }
}

                        

Tab 1

此演示向您展示如何将多个 PDF 文件合并为一个 PDF 文档。

Upload

Maximum file size: 1 MB. Files accepted: pdf.Upload up to 3 files.
e-iceblue
fileerrors

Source file:

filename
Target file type:

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfDocumentBase;

public class MergePdfsDemo {

    public void mergePdfs(String []pdfFiles){
        String outputFile="output.pdf";

        PdfDocumentBase documentBase= PdfDocument.mergeFiles(pdfFiles);
        documentBase.save(outputFile);

        documentBase.close();
    }
}
                        

Tab 3

using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoOnlineCode
{
    class MergePdfsDemo
    {
        public void mergePdfs(string[] pdfFiles)
        {
            String outputFile = "output.pdf";

            PdfDocumentBase documentBase = PdfDocument.MergeFiles(pdfFiles);
            documentBase.Save(outputFile);

            documentBase.Close();
        }
    }
}
                        

Tab 1

此演示向您展示如何在 PDF 文档中创建包含指定数据的表格。

Data

e-iceblue

Option

borderColor:
repeatHeader:
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import com.spire.pdf.grid.PdfGrid;
import com.spire.pdf.grid.PdfGridCell;
import com.spire.pdf.grid.PdfGridRow;

import java.awt.*;
import java.util.List;

public class PdfTableDemo {

    public void createTable(List< CustomerModel > data,Color borderColor){
        String outputFile = "output.pdf";
        String []haeder={"Contact","Company","City","Country","Phone"};
        PdfDocument pdf = new PdfDocument();
        PdfPageBase page = pdf.getPages().add(PdfPageSize.A4, new PdfMargins(40, 30, 40, 30));
        PdfBorders borders = new PdfBorders();
        if (borderColor == null) {
            borders.setAll(new PdfPen(new PdfRGBColor(Color.TRANSLUCENT)));
        } else {
            borders.setAll(new PdfPen(new PdfRGBColor(borderColor)));
        }

        PdfGrid grid = null;
        PdfGridRow pdfGridRow;
        PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", Font.BOLD, 16), true);
        PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", Font.PLAIN, 10), true);
        PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
        grid = new PdfGrid();
        grid.setAllowCrossPages(true);
        grid.getStyle().setCellSpacing(3f);
        grid.getColumns().add(5);

        double width = page.getCanvas().getClientSize().getWidth() - (grid.getColumns().getCount() + 1);
        grid.getColumns().get(0).setWidth(width * 0.2);
        grid.getColumns().get(1).setWidth(width * 0.2);
        grid.getColumns().get(2).setWidth(width * 0.2);
        grid.getColumns().get(3).setWidth(width * 0.2);
        grid.getColumns().get(4).setWidth(width * 0.2);
        pdfGridRow = grid.getHeaders().add(1)[0];
        pdfGridRow.setHeight(50);
        int i = 0;

        //header row
        for (i = 0; i < haeder.length; i++) {
            PdfGridCell cell = pdfGridRow.getCells().get(i);

            cell.setColumnSpan(1);
            cell.setValue(haeder[i]);
            cell.setStringFormat(format1);
            cell.getStyle().setBorders(borders);
            cell.getStyle().setFont(font1);
        }
        //data row
        for (i = 0; i < data.size(); i++) {
            pdfGridRow = grid.getRows().add();
            pdfGridRow.setHeight(40f);
            CustomerModel model=data.get(i);
            String []values={model.getContact(),model.getCompany(),model.getCity(),model.getCountry(),model.getPhone()};
            for (int j = 0; j < pdfGridRow.getCells().getCount(); j++) {
                PdfGridCell cell = pdfGridRow.getCells().get(j);
                cell.setColumnSpan(1);
                cell.setValue(values[j]);
                cell.getStyle().setBorders(borders);
                cell.getStyle().setFont(font2);
                cell.setStringFormat(format1);
            }
        }
        grid.setRepeatHeader(true);
        grid.draw(page, new Point(0, 0));
        pdf.saveToFile(outputFile, FileFormat.PDF);

        pdf.close();
    }
}

class CustomerModel {
    private String contact;
    private String company;
    private String city;
    private String country;
    private String phone;

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}
                        

Tab 3

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Grid;
using System;
using System.Collections.Generic;
using System.Drawing;


namespace DemoOnlineCode
{
    class CreateTableDemo
    {
        public void createTable(List< CustomerModel > data, Color borderColor)
        {
            String outputFile = "output.pdf";
            String[] haeder = { "Contact", "Company", "City", "Country", "Phone" };
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, new PdfMargins(40, 30, 40, 30));
            PdfBorders borders = new PdfBorders();
            if (borderColor == null)
            {
                borders.All=new PdfPen(new PdfRGBColor(Color.Transparent));
            }
            else
            {
                borders.All=new PdfPen(new PdfRGBColor(borderColor));
            }

            PdfGrid grid = null;
            PdfGridRow pdfGridRow;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial",16f, FontStyle.Bold), true);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f,FontStyle.Regular), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            grid = new PdfGrid();
            grid.AllowCrossPages=true;
            grid.Style.CellSpacing=3f;
            grid.Columns.Add(5);

            float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width=width * 0.2f;
            grid.Columns[1].Width=width * 0.2f;
            grid.Columns[2].Width=width * 0.2f;
            grid.Columns[3].Width=width * 0.2f;
            grid.Columns[4].Width=width * 0.2f;
            pdfGridRow = grid.Headers.Add(1)[0];
            pdfGridRow.Height=50;
            int i = 0;

            //header row
            for (i = 0; i < haeder.Length; i++)
            {
                PdfGridCell cell = pdfGridRow.Cells[i];

                cell.ColumnSpan=1;
                cell.Value = haeder[i];
                cell.StringFormat = format1;
                cell.Style.Borders = borders;
                cell.Style.Font = font1;
            }
            //data row
            for (i = 0; i < data.Count; i++)
            {
                pdfGridRow = grid.Rows.Add();
                pdfGridRow.Height = 40f;
                CustomerModel model = data[i];
                String[] values = { model.Contact, model.Company,model.City, model.Country, model.Phone };
                for (int j = 0; j < pdfGridRow.Cells.Count; j++)
                {
                    PdfGridCell cell = pdfGridRow.Cells[j];
                    cell.ColumnSpan=1;
                    cell.Value = values[j];
                    cell.Style.Borders = borders;
                    cell.Style.Font = font2;
                    cell.StringFormat = format1;
                }
            }
            grid.RepeatHeader = true;
            grid.Draw(page, new Point(0, 0));
            pdf.SaveToFile(outputFile, FileFormat.PDF);

            pdf.Close();
        }
    }
}
class CustomerModel
{
    public string Contact;
    public string Company;
    public string City;
    public string Country;
    public string Phone;
}

Tab 1

此演示向您展示如何在 PDF 文档中搜索文本并突出显示匹配的文本。

Upload

Maximum file size: 1 MB. Files accepted: pdf.
Click here to browse files.
fileerrors

Convert to

Source file:
filename
Search Text:

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。

Tab 2

import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.general.find.PdfTextFind;
import com.spire.pdf.general.find.TextFindParameter;

import java.awt.*;
import java.util.EnumSet;

public class PdfFindAndHighlightDemo {

    public void findAndHighlight(String pdfFiles, String keyText, Color highlightColor){

        String outputFile = "output.pdf";
        PdfDocument pdf=new PdfDocument();
        pdf.loadFromFile(pdfFiles);
        PdfTextFind[] result = null;
        for (Object pageObj : pdf.getPages()) {
            PdfPageBase page = (PdfPageBase) pageObj;
            // Find text
            result = page.findText(keyText, EnumSet.of(TextFindParameter.None)).getFinds();
            if (result != null) {
                for (PdfTextFind find : result) {
                    find.applyHighLight(highlightColor);
                }
            }
        }
        pdf.saveToFile(outputFile, FileFormat.PDF);
        pdf.close();

    }
}
                        

Tab 3

using Spire.Pdf;
using Spire.Pdf.General.Find;
using System.Drawing;

namespace DemoOnlineCode
{
    class FindAndHighlightDemo
    {
        public void findAndHighlight(string pdfFiles, string keyText, Color highlightColor)
        {

            string outputFile = "output.pdf";
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(pdfFiles);
            PdfTextFind[] result = null;
            foreach (PdfPageBase page in pdf.Pages)
            {
                // Find text
                result = page.FindText(keyText, TextFindParameter.None).Finds;
                if (result != null)
                {
                    foreach (PdfTextFind find in result)
                    {
                        find.ApplyHighLight(highlightColor);
                    }
                }
            }
            pdf.SaveToFile(outputFile, FileFormat.PDF);
            pdf.Close();

        }
    }
}