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

Spire.Cloud 纯前端文档控件

Spire.PDF 7.7.10已发布。本次更新增强了转换PDF到HTML/图片/SVG的功能,修复了打印和合并PDF文档时出现的问题。此外,该版本还修复了查找、替换和提取文本时出现的问题。详情请阅读以下内容。

问题修复:


获取Spire.PDF 7.7.10请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html

在之前的文章中我们介绍了如何给Word中指定文字添加批注,在本文中,我们将介绍如何获取Word中指定批注所标记的文字。

原Word文档:

Java 获取 Word 中指定批注所标记的文字

import com.spire.doc.Document;
import com.spire.doc.documents.CommentMark;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.Comment;
import com.spire.doc.fields.TextRange;


public class GetMarkedTextOfSpecificComment {
    public static void main(String[] args){
        //加载Word文档
        Document doc = new Document();
        doc.loadFromFile("Input.docx");

        //获取文档中第一个批注
        Comment comment = doc.getComments().get(0);
        
        //获取该批注的开始标记和结束标记
        Paragraph para = comment.getOwnerParagraph();
        CommentMark start = comment.getCommentMarkStart();
        CommentMark end = comment.getCommentMarkEnd();
        //获取开始标记和结束标记在段落中的索引
        int indexOfStart = para.getChildObjects().indexOf(start);
        int indexOfEnd = para.getChildObjects().indexOf(end);

        String markedText = "";
        //根据索引获取批注的开始标记和结束标记之间的文字
        for (int i = indexOfStart + 1; i < indexOfEnd; i++) {
            if (para.getChildObjects().get(i) instanceof TextRange) {
                TextRange range = (TextRange) para.getChildObjects().get(i);
                markedText += range.getText();
            }
        }
        
        //打印文字到控制台
        System.out.println(markedText);
    }
}

输出结果:

Java 获取 Word 中指定批注所标记的文字

本文介绍使用Spire.Doc for Java给Word中的指定文本字符添加边框的方法。

import com.spire.doc.*;
import com.spire.doc.documents.BorderStyle;
import com.spire.doc.documents.TextSelection;

import java.awt.*;

public class TextrangeBoder {
    public static void main(String[] args) {
        //加载Word文档
        Document document = new Document("inputfile.docx");

        //查找文本
        TextSelection[] textSelections1 = document.findAllString("Spire.Doc for Java", false, false);

        //给文本字符串添加边框
        for (TextSelection selection : textSelections1)
        {
            selection.getAsOneRange().getCharacterFormat().getBorder().setBorderType(BorderStyle.Single);
            selection.getAsOneRange().getCharacterFormat().getBorder().setColor(Color.red);
            selection.getAsOneRange().getCharacterFormat().getBorder().setLineWidth(2);
        }


        //保存文档
        document.saveToFile("BorderToCharacter.docx", FileFormat.Docx_2013);
    }
}

Java 给 Word 中的指定文本字符串添加边框

本文介绍如何使用Spire.PDF for Java为PDF文档添加数字签名时添加一个可信时间戳。

import com.spire.pdf.PdfDocument;
import com.spire.pdf.graphics.*;
import com.spire.pdf.security.GraphicMode;
import com.spire.pdf.security.PdfCertificate;
import com.spire.pdf.security.PdfCertificationFlags;
import com.spire.pdf.security.PdfSignature;

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

public class SignWithTimestamp {
    public static void main(String[] args) {

        //加载PDF文档
        PdfDocument doc = new PdfDocument();
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Introduction.pdf");

        //加载pfx文档
        PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\gary.pfx", "e-iceblue");

        //添加数字签名,设置其位置和大小
        PdfSignature signature = new PdfSignature(doc, doc.getPages().get(0), cert, "MySignature");
        Rectangle2D rect = new Rectangle2D.Float();
        rect.setFrame(new Point2D.Float((float) doc.getPages().get(0).getActualSize().getWidth() - 220, (float) doc.getPages().get(0).getActualSize().getHeight() - 140), new Dimension(200, 100));
        signature.setBounds(rect);

        //设置签名为文本模式
        signature.setGraphicMode(GraphicMode.Sign_Detail);

        //设置签名的内容
        signature.setNameLabel("签字者:");
        signature.setName("Gary");
        signature.setContactInfoLabel("联系电话:");
        signature.setContactInfo("02881705109");
        signature.setLocationInfoLabel("地点:");
        signature.setLocationInfo("成都");
        signature.setReasonLabel("原因:");
        signature.setReason("我是文档所有者");

        //设置签名的字体
        signature.setSignDetailsFont(new PdfTrueTypeFont(new Font("宋体", Font.PLAIN, 12)));

        //设置文档权限为禁止更改
        signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
        signature.setCertificated(true);

        //配置时间戳服务器
        String timestampeServerUrl = "http://timestamp.digicert.com";
        signature.configureTimestamp(timestampeServerUrl);

        //保存文档
        doc.saveToFile("output/Timestamp.pdf");
        doc.close();
    }
}

Java 添加时间戳数字签名到 PDF

Spire.Barcode 5.7.1现已发布。该版本支持获取条码在图片中的位置和条码类型,同时还修复了扫描图片程序挂起和扫描结果不正确的问题。详情如下。

新功能:

问题修复:


获取Spire.Barcode 5.7.1 请点击:

https://www.e-iceblue.cn/Downloads/Spire-Barcode-NET.html

Spire.Presentation 6.7.2已正式发布。该版本支持设置图表坐标轴的刻度线间隔,并新增了LoadFromStream重载方法支持从流加载加密的文档,同时修复了转换PPT到PDF,OLE图标不正确的问题。新功能及问题修复详情如下。

新功能:

问题修复:


获取Spire.Presentation 6.7.2,请点击:

https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html

本文将介绍如何使用Spire.PDF for Java提取PDF文件包(Portfolio)中的文件。

原PDF文档:

Java 如何提取 PDF 文件包(Portfolio)中的文件

import com.spire.pdf.PdfDocument;
import com.spire.pdf.attachments.PdfAttachment;

import java.io.*;

public class ReadPortfolio {
    public static void main(String []args) throws IOException {
        //创建PdfDocument实例
        PdfDocument pdf = new PdfDocument();
        //加载PDF文档
        pdf.loadFromFile("Portfolio.pdf");

        //遍历文档中的附件
        for(Object obj : pdf.getAttachments()) {
            PdfAttachment attachment = (PdfAttachment) obj;
            //提取附件
            String fileName = attachment.getFileName();
            OutputStream fos = new FileOutputStream("extract/" + fileName);
            fos.write(attachment.getData());
        }
        pdf.dispose();
    }
}

运行结果:

Java 如何提取 PDF 文件包(Portfolio)中的文件

本文介绍使用Spire.XLS for .NET判断Excel中的指定行或列是否隐藏。

用于测试的Excel文档如图,隐藏了第3行和F列(第6列)的数据:

C#/VB.NET 读判断 Excel 行或列是否隐藏

C#
using Spire.Xls;

namespace DetectHiddenRowOrColumn_XLS
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载Excel工作簿
            Workbook wb = new Workbook();
            wb.LoadFromFile("sample.xlsx");

            //获取第一张工作表
            Worksheet sheet = wb.Worksheets[0];
          
            //判断第3行是否隐藏
            bool result = sheet.GetRowIsHide(3);
            //sheet.GetColumnIsHide(6);//判断第6列是否隐藏

            if (result == true)
            {                
                System.Console.WriteLine("隐藏");
                System.Console.ReadLine();
            }
            else
            {
                System.Console.WriteLine("未隐藏");
                System.Console.ReadLine();
            }      
            
        }
    }
}

C#/VB.NET 读判断 Excel 行或列是否隐藏

VB.NET
Imports Spire.Xls

Namespace DetectHiddenRowOrColumn_XLS
	Class Program
		Private Shared Sub Main(args As String())
			'加载Excel工作簿
			Dim wb As New Workbook()
			wb.LoadFromFile("sample.xlsx")

			'获取第一张工作表
			Dim sheet As Worksheet = wb.Worksheets(0)

			'判断第3行是否隐藏
			Dim result As Boolean = sheet.GetRowIsHide(3)
			'sheet.GetColumnIsHide(6);//判断第5列是否隐藏

			If result = True Then
				System.Console.WriteLine("隐藏")
				System.Console.ReadLine()
			Else
				System.Console.WriteLine("未隐藏")
				System.Console.ReadLine()
			End If

		End Sub
	End Class
End Namespace

本文介绍使用Spire.PDF for .NET来设置PDF表格跨页时,重复显示表头行的方法。

C#
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Grid;
using System.Drawing;

namespace RepeatTableHeaderRow
{
    class Program
    {
        static void Main(string[] args)
        {
            //新建一个PDF文档
            PdfDocument pdf = new PdfDocument();

            //添加一页
            PdfPageBase page = pdf.Pages.Add();

            //创建PdfGrid类的对象
            PdfGrid grid = new PdfGrid();

            //设置单元格填充
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

            //添加表格列数
            grid.Columns.Add(3);

            //添加表头行及表格数据
            PdfGridRow[] pdfGridRows = grid.Headers.Add(1);            
            for (int i = 0; i < pdfGridRows.Length; i++)
            {
                pdfGridRows[i].Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Regular), true);//指定字体
                pdfGridRows[i].Cells[0].Value = "NAME";
                pdfGridRows[i].Cells[1].Value = "SUBJECT";
                pdfGridRows[i].Cells[2].Value = "SCORES";
                pdfGridRows[i].Style.TextBrush = PdfBrushes.Red;

            }

            //设置重复表头(表格跨页时)
            grid.RepeatHeader = true;

            //添加数据到表格
            for (int i = 0; i < 60; i++)
            {
                PdfGridRow row = grid.Rows.Add();               
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    row.Cells[j].Value = "(Row " + i + ", column " + j + ")";
                }
            }

            //在PDF页面绘制表格
            grid.Draw(page, new PointF(0, 20));          

            //保存文档
            pdf.SaveToFile("Result.pdf");
            System.Diagnostics.Process.Start("Result.pdf");
        }
    }
}
VB.NET
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Grid
Imports System.Drawing

Namespace RepeatTableHeaderRow
	Class Program
		Private Shared Sub Main(args As String())
			'新建一个PDF文档
			Dim pdf As New PdfDocument()

			'添加一页
			Dim page As PdfPageBase = pdf.Pages.Add()

			'创建PdfGrid类的对象
			Dim grid As New PdfGrid()

			'设置单元格填充
			grid.Style.CellPadding = New PdfPaddings(1, 1, 1, 1)

			'添加表格列数
			grid.Columns.Add(3)

			'添加表头行及表格数据
			Dim pdfGridRows As PdfGridRow() = grid.Headers.Add(1)
			For i As Integer = 0 To pdfGridRows.Length - 1
				pdfGridRows(i).Style.Font = New PdfTrueTypeFont(New Font("Arial", 11F, FontStyle.Regular), True)
				'指定字体
				pdfGridRows(i).Cells(0).Value = "NAME"
				pdfGridRows(i).Cells(1).Value = "SUBJECT"
				pdfGridRows(i).Cells(2).Value = "SCORES"
				pdfGridRows(i).Style.TextBrush = PdfBrushes.Red
			Next

			'设置重复表头(表格跨页时)
			grid.RepeatHeader = True

			'添加数据到表格
			For i As Integer = 0 To 59
				Dim row As PdfGridRow = grid.Rows.Add()
				For j As Integer = 0 To grid.Columns.Count - 1
					row.Cells(j).Value = "(Row " + i + ", column " + j + ")"
				Next
			Next

			'在PDF页面绘制表格
			grid.Draw(page, New PointF(0, 20))

			'保存文档
			pdf.SaveToFile("Result.pdf")
			System.Diagnostics.Process.Start("Result.pdf")
		End Sub
	End Class
End Namespace

文档效果:

C#/VB.NET 设置 PDF 跨页表格重复显示表头行

Spire.Office 6.7.0已发布。本次更新带来2个新功能,即Spire.XLS支持判断单元格是否设置了自适应行高/列宽,以及获取.xls格式文档中的几何形状。同时,该版本还修复了一些在操作Word、PDF、Excel、PowerPoint时出现的问题。详情请阅读以下内容。

该版本涵盖了最新版的Spire.Doc, Spire.PDF, Spire.XLS, Spire.Presentation, Spire.Email, Spire.DocViewer, Spire.PDFViewer, Spire.Spreadsheet, Spire.OfficeViewer, Spire.DataExport, Spire.Barcode。

版本信息如下:

获取Spire.Office 6.7.0请点击:

https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html


Spire.Doc

问题修复:


Spire.PDF

问题修复:


Spire.Presentation

问题修复:


Spire.XLS

新功能:

问题修复:


Spire.Spreadsheet

问题修复: