Spire.Doc 13.7.9 现已发布。该版本新增了多项功能, 如支持创建组合图表,支持在将 Word 转换为 PDF 时设置图像压缩方法。此外还修复了一个在转换Doc到PDF时标题图像被拉伸的问题。详情如下。
新功能:
- 支持创建组合图表。
- 新增‘setDefaultSubstitutionFontName’方法,支持设置默认的替换字体。
- 新增‘StructureDocumentTag.RemoveSelfOnly()’方法,支持移除SDT保留内容。
- 支持Word转PDF时设置图片压缩方式。
- 支持从OMML添加公式到Word文档。
- 支持Math公式转到Latex。
Document doc = new Document();
Paragraph paragraph = doc.AddSection().AddParagraph();
Chart chart = paragraph.AppendChart(ChartType.Column, 450, 300).Chart;
// 将'Series 3' 修改为折线图,并显示在次坐标轴上
chart.ChangeSeriesType("Series 3", ChartSeriesType.Line, true);
Console.WriteLine(chart.Series[2].ChartType);
doc.SaveToFile("组合图表.docx");
Document document = new Document();
// 设置默认替换字体
doc.DefaultSubstitutionFontName = "Arial";
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
TextRange tr = para.AppendText("test");
tr.CharacterFormat.FontName = "Helvetica";
doc.SaveToFile(outputFile, FileFormat.PDF);
doc.Close();
// 处理内联结构标记
List tagInlines = structureTags.getM_tagInlines();
for (int i = 0; i < tagInlines.Count; i++)
{
tagInlines[i].RemoveSelfOnly();
}
// 处理其他结构标记
List tags = structureTags.getM_tags();
for (int i = 0; i < tags.Count; i++)
{
tags[i].RemoveSelfOnly();
}
// 处理 StructureDocumentTagRow
List rowtags = structureTags.getM_rowtags();
for (int i = 0; i < rowtags.Count; i++)
{
rowtags[i].RemoveSelfOnly();
}
// 处理 StructureDocumentTagCell
List celltags = structureTags.getM_celltags();
for (int i = 0; i < celltags.Count; i++)
{
celltags[i].RemoveSelfOnly();
}
Document document = new Document();
document.LoadFromFile(@"Sample.docx");
ToPdfParameterList para = new ToPdfParameterList();
para.PdfImageCompression = Spire.Doc.Export.PdfImageCompression.Jpeg;
document.SaveToFile(outputFile,para);
Document document = new Document();
Section section = doc.AddSection();
foreach (string ommlCode in OmqlCodes)
{
OfficeMath officeMath = new OfficeMath(doc);
officeMath.CharacterFormat.FontSize = 14f;
officeMath.FromOMMLCode(ommlCode);
section.AddParagraph().ChildObjects.Add(officeMath);
}
doc.SaveToFile(outputFile, FileFormat.Docx2013);
doc.Dispose();
Document document = new Document();
doc.LoadFromFile(inputFile);
StringBuilder stringBuilder = new StringBuilder();
// 遍历文档中所有节
foreach (Section section in doc.Sections)
{
// 遍历每一节中的所有段落
foreach (Paragraph par in section.Body.Paragraphs)
{
// 遍历每一个段落中的子对象
foreach (DocumentObject obj in par.ChildObjects)
{
// 判断对象是否为OfficeMath 公式
OfficeMath omath = obj as OfficeMath;
if (omath == null) continue;
// 将 OfficeMath 公式转换为 LaTex 代码
string mathml = omath.ToLaTexMathCode();
// 将 MathML 代码添加到StringBuilder
stringBuilder.Append("LaTeX code" + mathml);
stringBuilder.Append("\r\n");
}
}
}
// 将 LaTex 代码写入文本文件
File.WriteAllText(outputFile, stringBuilder.ToString());
问题修复:
- 修复了 Doc 转 PDF 时,页眉的图片被拉伸的问题。
获取Spire.Doc 13.7.9,请点击: