Spire.PDF for C++ 9.11.0 已发布。本次更新新增支持 PdfMarker 类型,同时增强了 PDF 到 XPS 和 PPTX 文件的转换功能。此外,一些已知问题也在该版本中得到修复,如压缩PDF文档失败的问题。详情请阅读以下内容。
新功能:
intrusive_ptr<PdfDocument> doc = new PdfDocument();
intrusive_ptr<PdfNewPage> page = Object::Dynamic_cast<PdfNewPage>(doc->GetPages()->Add());
intrusive_ptr<PdfMarker> marker = new PdfMarker(PdfUnorderedMarkerStyle::CustomImage);
marker->SetImage(PdfImage::FromFile(inputFile_Img.c_str()));
std::wstring listContent = L"Data Structure\n";
listContent += L"Algorithm\n";
listContent += L"Computer Newworks\n";
listContent += L"Operating System\n";
listContent += L"C Programming\n";
listContent += L"Computer Organization and Architecture";
intrusive_ptr<PdfList> list = new PdfList(listContent.c_str());
list->SetIndent(2);
list->SetTextIndent(4);
list->SetMarker(marker);
((intrusive_ptr<PdfLayoutWidget>)list)->Draw(page, 100, 100);
doc->SaveToFile(outputFile.c_str(), FileFormat::PDF);
doc->Close();问题修复:
微软 Word 中的文本查找和高亮功能使用户能够轻松地浏览和搜索特定的内容。通过高亮关键词或句子,用户可以快速定位文档中所需的信息。这项功能在处理大型文档时尤为实用,因为它不仅能节省时间,还能减少手动搜索所带来的不便,使用户能够专注于真正重要的内容。在本文中,我们将演示如何使用 Spire.Doc for Python 在 Python 中查找和高亮 Word 文档中的文本。
本教程需要用到 Spire.Doc for Python 和 plum-dispatch v1.7.4。可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.Doc如果您不确定如何安装,请参考此教程:如何在 Windows 中安装 Spire.Doc for Python
你可以使用 Spire.Doc for Python 提供的 Document.FindAllString() 方法在 Word 文档中查找指定文本的所有实例,然后循环遍历这些实例,并使用 TextRange.CharacterFormat.HighlightColor 属性为每个实例设置高亮颜色。具体步骤如下:
from spire.doc import *
from spire.doc.common import *
# 指定输入和输出文档的路径
inputFile = "示例.docx"
outputFile = "高亮所有实例.docx"
# 创建一个Document类的对象
document = Document()
# 加载一个Word文档
document.LoadFromFile(inputFile)
# 查找特定文本的所有实例
textSelections = document.FindAllString("Spire.Doc", False, True)
# 遍历所有找到的实例
for selection in textSelections:
textRange = selection.GetAsOneRange()
# 为每个实例设置高亮颜色
textRange.CharacterFormat.HighlightColor = Color.get_Yellow()
# 保存结果文档
document.SaveToFile(outputFile, FileFormat.Docx2016)
document.Close()
你可以使用 Document.FindString() 方法来查找指定文本的第一个实例,并使用 TextRange.CharacterFormat.HighlightColor 属性为其设置高亮颜色。具体步骤如下:
from spire.doc import *
from spire.doc.common import *
# 指定输入和输出文档的路径
inputFile = "示例.docx"
outputFile = "高亮第一个实例.docx"
# 创建Document类的对象
document = Document()
# 加载Word文档
document.LoadFromFile(inputFile)
# 查找指定文本的第一个实例
textSelection = document.FindString("Spire.Doc", False, True)
textRange = textSelection.GetAsOneRange()
# 给该实例设置高亮颜色
textRange.CharacterFormat.HighlightColor = Color.get_Yellow()
# 保存结果文档
document.SaveToFile(outputFile, FileFormat.Docx2016)
document.Close()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 8.11.3 已发布。在该版本中,Spire.XLS for Java 新增支持从“名称管理器”中获取注释的功能;Spire.PDF for Java增强了 PDF 到 Word 以及 PPTX 的转换功能;Spire.Presentation for Java增强了从幻灯片到SVG的转换功能。 此外,一些已知问题也在该版本中得到修复。详情请阅读以下内容。
获取 Spire.Office for Java 8.11.3请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Workbook workbook = new Workbook();
workbook.loadFromFile(inputFile);
INameRanges nameManager = workbook.getNameRanges();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0;i < nameManager.getCount();i++)
{
XlsName name = (XlsName) nameManager.get(i);
stringBuilder.append("Name:" + name.getName() + ", Comment: " +name.getCommentValue() + "\r\n");
}
workbook.dispose();问题修复:
问题修复:
问题修复:
在 Word 文档中设置段落和文本的背景颜色可以显著提升内容的展示效果和可读性。设置背景颜色是强调关键信息、对内容进行分类以及增加个性化风格的有效方法,使创作者能够轻松地创建出精美且专业的文档。同时,通过精心选择和应用背景颜色,创作者可以将普通文档转变为更具视觉吸引力的作品,从而更有效地传达文档中的信息。本文将介绍如何使用 Spire.Doc for Python 来为 Word 文档中的段落和文本设置背景颜色,为文档的个性化带来新的可能性。
本教程需要用到 Spire.Doc for Python 和 plum-dispatch v1.7.4。可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.Doc如果您不确定如何安装,请参考此教程:如何在 Windows 中安装 Spire.Doc for Python
通过使用 Spire.Doc for Python,开发人员可以获取 Word 文档中任意节,以及节中的任意段落。在获取段落后,开发人员可以通过将 Color 对象分配给 Paragraph.Format.BackColor 属性来为段落应用背景颜色。下面是详细操作步骤:
from spire.doc import *
from spire.doc.common import *
# 创建Document类的实例并加载Word文档
doc = Document()
doc.LoadFromFile("示例.docx")
# 获取文档第一节
section = doc.Sections.get_Item(0)
# 获取该节第五个段落
paragraph = section.Paragraphs.get_Item(4)
# 为段落设置背景颜色
paragraph.Format.BackColor = Color.get_DarkGreen()
# 保存文档
doc.SaveToFile("output/段落背景色.docx")
doc.Close()
Spire.Doc for Python 支持通过 Document.FindAllString() 方法在 Word 文档中查找特定文本的所有出现位置。在获取查找结果后,可以通过 TextRange.CharacterFormat.TextBackgroundColor 属性为匹配项设置背景色。具体操作步骤如下:
from spire.doc import *
from spire.doc.common import *
# 创建Document类的实例并加载Word文档
doc = Document()
doc.LoadFromFile("文档.docx")
# 在Word文档中查找文本
findResults = doc.FindAllString("亮度", False, False)
# 遍历查找结果,为所有匹配项设置背景颜色
for text in findResults:
# 将匹配项转换为文本范围
textRange = text.GetAsOneRange(True)
# 设置文本范围的背景颜色
textRange.CharacterFormat.TextBackgroundColor = Color.get_LightCoral()
# 设置指定匹配项的背景颜色
# 将匹配项转换为文本范围
# textRange = findResults[1].GetAsOneRange()
# 设置文本范围的背景颜色
# textRange.CharacterFormat.TextBackgroundColor = Color.get_DarkCyan()
# 保存文档
doc.SaveToFile("output/文本背景色.docx")
doc.Close()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.XLS for Java 13.11.6 现已发布。该版本成功修复了一些在转换Excel到Html/PDF以及复制工作表时出现的问题。详情见下文。
问题修复:
Spire.XLS 13.11.4已发布。本次更新主要修复了Excel转HTML和PDF产生的问题,加强了格式转换的准确性。另外,一些已知问题得到了修复,例如:查找字符串返回的结果不正确,复制工作表时图表引用更新不正确。更多详细信息如下。
问题修复:
Spire.Doc 11.11.8已发布。该版本公开了枚举 Spire.Doc.Publics.Drawing.FontStyle。另外,PrivateFontPath 结构中的 FontStyle 的命名空间被更改为 Spire.Doc.Publics.Drawing。详情请阅读以下内容。
新功能:
Spire.PDF for Java 9.11.3 已发布。本次更新增强了 PDF 到 Word 以及 PPTX 的转换功能。此外,一些已知问题也在改版本中成功修复,如提取PDF中表格的内容失败的问题。详情请阅读以下内容。
问题修复:
PowerPoint 中的水印是以微妙的叠加形式放置在幻灯片上的。它们可以是文本或图片,常见的应用包括展示版权信息、公司徽标、保密声明或其他相关标识。通过在 PPT 幻灯片中插入水印,可以提高文档的专业性、强化品牌形象,并阻止未经授权使用或分发资料。在本文中,您将学习如何使用 Spire.Presentation for Python 在 Python 中为 PPT 文档添加文本水印或图片水印。
本教程需要用到 Spire.Presentation for Python 和 plum-dispatch v1.7.4。可以通过以下 pip 命令将它们轻松安装到 Windows 中。
pip install Spire.Presentation如果您不确定如何安装,请参考此教程:如何在 Windows 中安装 Spire.Presentation for Python
与 MS Word 不同,PowerPoint 没有内置的添加水印的功能。不过,您可以使用 ISlide.Shapes.AppendShape() 方法将带有文本或图片的形状添加到幻灯片中来模拟水印效果。为防止形状与幻灯片上的现有内容重叠,最好将其置于底层。
以下是使用 Spire.Presentation for Python 为 PPT 幻灯片添加文本水印的步骤。
from spire.presentation.common import *
from spire.presentation import *
# 创建Presentation对象
presentation = Presentation()
# 加载PPT文档
presentation.LoadFromFile("工作总结.pptx")
# 定义一个矩形
left = (presentation.SlideSize.Size.Width - 350.0) / 2
top = (presentation.SlideSize.Size.Height - 110.0) / 2
rect = RectangleF(left, top, 350.0, 110.0)
for i in range(0, presentation.Slides.Count):
# 将该矩形形状添加到幻灯片中
shape = presentation.Slides[i].Shapes.AppendShape(
ShapeType.Rectangle, rect)
# 设置形状的样式
shape.Fill.FillType = FillFormatType.none
shape.ShapeStyle.LineColor.Color = Color.get_Transparent()
shape.Rotation = -35
shape.Locking.SelectionProtection = True
shape.Line.FillType = FillFormatType.none
# 在形状中添加文字
shape.TextFrame.Text = "内部文件"
textRange = shape.TextFrame.TextRange
# 设置文本范围的样式
textRange.Fill.FillType = FillFormatType.Solid
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.get_Red().R, Color.get_Red().G, Color.get_Red().B)
textRange.FontHeight = 60
textRange.LatinFont = TextFont("微软雅黑")
# 将形状置于底层
shape.SetShapeArrange(ShapeArrange.SendToBack)
# 保存结果文件
presentation.SaveToFile("Output/添加文本水印.pptx", FileFormat.Pptx2013)
presentation.Dispose()
要添加图片水印,首先需要创建一个与图片大小相同的矩形,然后用图片填充该形状并将其置于幻灯片的中心。为防止形状与幻灯片上的现有内容重叠,还需将其置于底部。
以下是使用 Spire.Presentation for Python 为 PPT 幻灯片添加图片水印的步骤。
from spire.presentation.common import *
from spire.presentation import *
# 创建Presentation对象
presentation = Presentation()
# 加载PPT文件
presentation.LoadFromFile("工作总结.pptx")
# 加载图片
stream = Stream("图标.jpg")
image = presentation.Images.AppendStream(stream)
stream.Close()
# 获取图像的宽度和高度
width = (float)(image.Width)
height = (float)(image.Height)
# 获取幻灯片尺寸
slideSize = presentation.SlideSize.Size
# 遍历所有幻灯片
for i in range(0, presentation.Slides.Count):
# 获取指定幻灯片
slide = presentation.Slides[i]
# 在幻灯片中添加一个形状
shape = slide.Shapes.AppendShape(ShapeType.Rectangle, RectangleF((slideSize.Width - width )/2, (slideSize.Height - height)/2, width, height))
# 用图像填充形状
shape.Line.FillType = FillFormatType.none
shape.Locking.SelectionProtection = True
shape.Fill.FillType = FillFormatType.Picture
shape.Fill.PictureFill.FillType = PictureFillType.Stretch
shape.Fill.PictureFill.Picture.EmbedImage = image
# 将形状置于底层
shape.SetShapeArrange(ShapeArrange.SendToBack)
# 保存结果文件
presentation.SaveToFile("Output/添加图片水印.pptx", FileFormat.Pptx2013)
presentation.Dispose()
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office 8.11.0 已发布。在该版本中,Spire.PDF 新增支持按阅读顺序获取分栏文档的文本坐标;Spire.Doc 新增转换 Word 到 PDF 时文本整形的功能;Spire.XLS 新增支持自定义透视表字段的名称;Spire.Presentation 新增支持获取形状内文本的位置信息的功能。此外,许多已知问题也在该版本中成功修复。详情请阅读以下内容。
该版本涵盖了最新版的 Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer,Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet,Spire.OfficeViewer,Spire.Barcode,Spire.DataExport。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);
PdfPageBase pdfPageBase = doc.Pages[0];
PdfTextFinder finder = new PdfTextFinder(pdfPageBase);
finder.Options.Strategy = PdfTextStrategy.Simple;PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
string text = "Please add the code picture BehindText=true to set the picture behind text";
PdfSolidBrush solidBrush = new PdfSolidBrush (new PdfRGBColor(Color.Black));
PdfStringFormat format = new PdfStringFormat():
format.HorizontalScalingFactor = 80;
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular);
PdfGraphicsState state = page.Canvas.Save();
page.Canvas.DrawString(text, font, solidBrush, 0, 0, format);
page.Canvas.Restore(state):
doc.SaveToFile(outputFile);
doc.Close();PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFile);
doc.ConvertOptions.ApplyPermissionsOptions(true);
StringBuilder sb = new StringBuilder();
foreach (FileFormat type in Enum.GetValues(typeof(FileFormat)))
{
try
{
if (type.ToString().Equals("PDF"))
{
doc.SaveToFile(outputFile_P, type);
}
else
{
doc.SaveToFile(outputFile, type);
}
}
catch (Exception ex)
{
sb.AppendLine("save to: "+ type +" :"+ ex.Message);
}
}
File.AppendAllText(outputFile,sb.ToString());
doc.Dispose();问题修复:
新功能:
Document doc = new Document();
doc.LoadFromFile(fileName);
doc.LayoutOptions.UseHarfBuzzTextShaper = true;
doc.SaveToFile(pdfFileName, Spire.Doc.FileFormat.PDF)问题修复:
新功能:
sheet.PivotTables[0].RowFields[0].CustomName = "rowName";
sheet.PivotTables[0].ColumnFields[0].CustomName = "colName";
sheet.PivotTables[0].PivotFields[0].CustomName = "fieldName1";
sheet.PivotTables[0].DataFields[0].CustomName = "dataName";问题修复:
新功能:
Presentation ppt = new Presentation();
ppt.LoadFromFile(inputFile);
StringBuilder sb = new StringBuilder();
ISlide slide = ppt.Slides[0];
for (int i = 0; i < slide.Shapes.Count; i++)
{
IShape shape = slide.Shapes[i];
if (shape is IAutoShape)
{
IAutoShape autoshape = slide.Shapes[i] as IAutoShape;
string text = autoshape.TextFrame.Text;
//obtain the text position information
PointF point = autoshape.TextFrame.GetTextLocation();
sb.AppendLine("Shape " + i + ":" + text + "\r\n" + "location:" + point.ToString());
}
}
File.AppendAllText(outputFile, sb.ToString());
ppt.Dispose();Presentation ppt = new Presentation();
ppt.LoadFromFile(inputFile);
ISlide slide = ppt.Slides[0];
IAutoShape autoshape = slide.Shapes[0] as IAutoShape;
IList<LineText> lines = autoshape.TextFrame.GetLayoutLines();
for (int i = 0; i < lines.Count; i++)
{
float ascent= lines[i].Ascent;
float descent = lines[i].Descent;
}Presentation ppt = new Presentation();
ppt.LoadFromFile("FreeForm.pptx");
ISlide slide = ppt.Slides[0];
int num = 0;
foreach (IShape shape in slide.Shapes)
{
byte[] svgByte = shape.SaveAsSvg();
FileStream fs = new FileStream("shape_" + num + ".svg",FileMode.Create);
fs.Write(svgByte, 0, svgByte.Length);
fs.Close();
num++;
}问题修复: