线性化 PDF 文件是 PDF 文件的一种特殊格式,可以通过 Internet 更快速地进行查看,在页面数量很多的情况下,更能突出表现出快速浏览的优势。本文,将通过使用 Spire.PDF for Java 来展示如何将常规的 PDF 文件转换为线性 PDF 文件。以下是详细方法及步骤。
首先,您需要在 Java 程序中添加 Spire.Pdf.jar 文件作为依赖项。JAR 文件可以从此链接下载。如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而在应用程序中导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>11.11.11</version>
</dependency>
</dependencies>
Spire.PDF for Java 提供了 PdfToLinearizedPdfConverter.toLinearizedPdf() 方法将 PDF 转为线性 PDF,实现格式转换仅需两行代码即可,如下:
import com.spire.pdf.conversion.PdfToLinearizedPdfConverter;
public class ToLinerlizedPDF {
public static void main(String[] args) {
//加载PDF文档
PdfToLinearizedPdfConverter converter = new PdfToLinearizedPdfConverter("samplefile.pdf");
//转为线性PDF,保存到指定路径
converter.toLinearizedPdf("output.pdf");
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
任何文本编辑器都可以对 TXT 文件轻松进行编辑,如果你想防止其他人查看文件内容时进行更改,可以将 TXT 文件转换为 PDF 文件。本文将展示使用 Spire.PDF for Java 以编程的方式将文本文件 TXT 转换为 PDF 文件的操作步骤。
首先,您需要在 Java 程序中添加 Spire.Pdf.jar 文件作为依赖项。JAR 文件可以从此链接下载。 如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而在应用程序中导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>11.11.11</version>
</dependency>
</dependencies>
以下时使用 Spire.PDF for Java 将文本文件 TXT 转换为 PDF 的主要操作步骤:
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.Rectangle2D;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TXTToPDF {
public static void main(String[] args) throws Exception {
//从TXT文件读取文本
String text = readTextFromFile("示例.txt");
//创建PdfDocument类的对象
PdfDocument pdf = new PdfDocument();
//添加一个页面
PdfPageBase page = pdf.getPages().add();
//创建PdfFont类的对象
Font font = new Font("宋体", Font.PLAIN, 11);
PdfTrueTypeFont font1 = new PdfTrueTypeFont(font);
//创建PdfTextLayout类的对象
PdfTextLayout textLayout = new PdfTextLayout();
textLayout.setBreak(PdfLayoutBreakType.Fit_Page);
textLayout.setLayout(PdfLayoutType.Paginate);
//创建PdfStringFormat类的对象
PdfStringFormat format = new PdfStringFormat();
format.setLineSpacing(20f);
//用读取的文本创建PdfTextWidget类的对象
PdfTextWidget textWidget = new PdfTextWidget(text, font1, PdfBrushes.getBlack());
//设置字符格式
textWidget.setStringFormat(format);
//将文本添加到PDF页面的指定位置
Rectangle2D.Float bounds = new Rectangle2D.Float();
bounds.setRect(0,25,page.getCanvas().getClientSize().getWidth(),page.getCanvas().getClientSize().getHeight());
textWidget.draw(page, bounds, textLayout);
//保存结果文件
pdf.saveToFile("TXT转PDF.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);
sb.append("\n");
}
return sb.toString();
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
TXT 文件是一种纯文本文件,这种格式的文件能在几乎所有计算机上进行查看,但其功能性较弱,除了储存文件有效字符信息外,不能储存其他任何信息。如果想要在文本文件上进行更多的操作,如插入注解或表单等,可以将文本文件转换成 PDF 文件来实现。本文将展示如何用 Spire.PDF for .NET 以编程的方式将 TXT 文本文件转换为 PDF 文件。
首先,我们需要将 Spire.PDF for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。可以从此链接下载 DLL 文件,也可以通过 NuGet 安装 DLL 文件。
PM> Install-Package Spire.PDF以下是使用 Spire.PDF for .NET 将 TXT 文本文件转换为 PDF 文件的主要步骤:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.IO;
namespace ConvertTextToPdf
{
class Program
{
static void Main(string[] args)
{
//读取TXT文件中的文本内容
string text = File.ReadAllText("示例.txt");
//创建PdfDocument类的对象
PdfDocument pdf = new PdfDocument();
//添加一个页面
PdfPageBase page = pdf.Pages.Add();
//创建PdfFont类的对象
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", 11f), true);
//创建PdfTextLayout类的对象
PdfTextLayout textLayout = new PdfTextLayout();
textLayout.Break = PdfLayoutBreakType.FitPage;
textLayout.Layout = PdfLayoutType.Paginate;
//创建PdfStringFormat类的对象
PdfStringFormat format = new PdfStringFormat();
format.Alignment = PdfTextAlignment.Justify;
format.LineSpacing = 20f;
//用读取的文本创建PdfTextWidget类的对象
PdfTextWidget textWidget = new PdfTextWidget(text, font, PdfBrushes.Black);
//设置文本格式
textWidget.StringFormat = format;
//将文本添加到页面指定位置
RectangleF bounds = new RectangleF(new PointF(10, 25), page.Canvas.ClientSize);
textWidget.Draw(page, bounds, textLayout);
//保存结果文件
pdf.SaveToFile("TXT转PDF.pdf", FileFormat.PDF);
}
}
}Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing
Imports System.IO
Namespace ConvertTextToPdf
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'读取TXT文件中的文本内容
Dim text = File.ReadAllText("示例.txt")
'创建PdfDocument类的对象
Dim pdf As PdfDocument = New PdfDocument()
'添加一个页面
Dim page As PdfPageBase = pdf.Pages.Add()
'创建PdfFont类的对象
Dim font As PdfFont = New PdfFont(PdfFontFamily.Helvetica, 11)
'创建PdfTextLayout类的对象
Dim textLayout As PdfTextLayout = New PdfTextLayout()
textLayout.Break = PdfLayoutBreakType.FitPage
textLayout.Layout = PdfLayoutType.Paginate
'创建PdfStringFormat类的对象
Dim format As PdfStringFormat = New PdfStringFormat()
format.Alignment = PdfTextAlignment.Justify
format.LineSpacing = 20.0F
'用读取的文本创建PdfTextWidget类的对象
Dim textWidget As PdfTextWidget = New PdfTextWidget(text, font, PdfBrushes.Black)
'设置文本格式
textWidget.StringFormat = format
'将文本添加到页面指定位置
Dim bounds As RectangleF = New RectangleF(New PointF(10, 25), page.Canvas.ClientSize)
textWidget.Draw(page, bounds, textLayout)
'保存结果文件
pdf.SaveToFile("TXT转PDF.pdf", FileFormat.PDF)
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
线性化 PDF,也称为“Fast Web View”,是一种优化 PDF 文件的方法。 通常只有当网络浏览器从服务器下载了所有页面后,用户才能在线查看多页 PDF 文件。 但如果是线性化 PDF 文件,即使尚未完成完整下载,浏览器也可以非常快速地显示第一页。本文将以 C# 和 VB.NET 代码为例,介绍如何使用 Spire.PDF for .NET 将 PDF 转换为线性化 PDF 文件。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDF详细步骤如下:
using Spire.Pdf.Conversion;
namespace ConvertPdfToLinearized
{
class Program
{
static void Main(string[] args)
{
//加载PDF文档
PdfToLinearizedPdfConverter converter = new PdfToLinearizedPdfConverter("成都.pdf");
//将文件转为线性化PDF
converter.ToLinearizedPdf("线性化PDF.pdf");
}
}
}Imports Spire.Pdf.Conversion
Namespace ConvertPdfToLinearized
Class Program
Private Shared Sub Main(ByVal args() As String)
'加载PDF文档
Dim converter As PdfToLinearizedPdfConverter = New PdfToLinearizedPdfConverter(“成都.pdf")
'将文件转为线性化PDF
converter.ToLinearizedPdf("线性化PDF.pdf")
End Sub
End Class
End Namespace使用 PDF 阅读器打开结果文件并查看文档属性,可以看到“Fast Web View”的值为 Yes,表示文件已线性化。

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 7.8.0 已发布。本次更新包含一些新功能,如:Spire.XLS for Java支持自定义排序,并且支持将Excel 2016定义的Chart类型转换为PDF和图片;Spire.Presentation for Java支持转换PPT文档中的所有幻灯片到一个SVG文件以及删除 PPTM 格式文档中的宏,同时提供 isSlideSizeAutoFit() 方法以支持在克隆幻灯片时使内容自适应幻灯片尺寸; Spire.Doc for Java增强了 Word 和 HTML 到 PDF 的转换功能;Spire.PDF for Java增强了 PDF 到图片、OFD、PDF/A3A 及 Tiff 到 PDF 的转换。此外,该版本还修复了一些已知问题。详情请阅读以下内容。
获取Spire.Office for Java 7.8.0请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
wb.getDataSorter().getSortColumns().add(0, new String[]
{"12345","Argentina", "Area", "Chile", "Capital","USA","Ecuador","Guyana"}
); wb.getDataSorter().sort(wb.getWorksheets().get(0).getRange().get("A1:A8"));问题修复:
新功能:
Presentation presentation1 =new Presentation();
presentation1.loadFromFile(inputFile_1);
Presentation presentation2 =new Presentation();
presentation2.loadFromFile(inputFile_2);
presentation1.isSlideSizeAutoFit(true);
ILayout layout = presentation1.getSlides().get(0).getLayout();
presentation1.getSlides().append(presentation2.getSlides().get(0),layout);
presentation1.saveToFile(outputFile, FileFormat.PPTX_2013);byte[] bytes=ppt.saveToOneSVG();
try(java.io.FileOutputStream stream = new java.io.FileOutputStream(outputFile)){
stream.write(bytes);
}问题修复:
问题修复:
问题修复:
Spire.PDF for Java 8.8.0 已发布。本次更新增强了 PDF 到图片、OFD、PDF/A3A 及 Tiff 到 PDF 的转换。此外,该版本还修复了一些已知问题,如:加载PDF文档时程序抛“NullPointerException"异常的问题。详情请阅读以下内容。
问题修复:
PDF/X-1a 作为一种 PDF 文件规范标准,是制作、使用 PDF 以及印刷时所需要遵循的技术条件。由于不同应用程序对 PDF 文件版本的适配及兼容差异,PDF/X-1a 标准细分为了 PDF/X-1a:2001 和 PDF/X-1a:2003 两种,前者适用于 PDF 1.3 版本,而后者适用于 PDF 1.4 版本。通过文件转换,我们可以得到该标准的 PDF 文件。本文,将通过使用 Spire.PDF for .NET 来介绍如何实现将既有的 PDF 转为 PDF/X-1a:2001。以下,是具体的方法及步骤。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDFSpire.PDF for .NET 提供了可直接转换的方法来获得目标文件,转换为 PDF/X-1a:2001 时,可参考如下代码步骤执行:
using Spire.Pdf.Conversion;
namespace PDFtoPDFX1A
{
class Program
{
static void Main(string[] args)
{
PdfStandardsConverter converter = new PdfStandardsConverter("Sample.pdf");
converter.ToPdfX1A2001("Result.pdf");
}
}
}Imports Spire.Pdf.Conversion
Namespace PDFtoPDFX1A
Class Program
Private Shared Sub Main(args As String())
Dim converter As New PdfStandardsConverter("Sample.pdf")
converter.ToPdfX1A2001("Result.pdf")
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office 7.7.6 已发布。本次更新带来了一些新功能,如:Spire.Doc 在使用新引擎转换 Word 到 PDF 时支持保留文本方向;Spire.PDF 支持创建标签 PDF 文件;Spire.XLS 支持在导出 DataTable 时,设置是否保持数据的数字格式;Spire.Presentation 支持裁切幻灯片图片。此外,该版本还成功修复了许多已知问题。详情请阅读以下内容。
该版本涵盖了最新版的Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer, Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet, Spire.OfficeViewer, Spire.DocViewer, Spire.Barcode, Spire.DataExport。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
//Note:At present, in order to ensure the validity of the output tagged PDF file, it is necessary to add the valid license of Spire.PDF for .net to remove the red warning watermark.
//Spire.License.LicenseProvider.SetLicenseKey("valid license key");
//Create a pdf document
PdfDocument doc = new PdfDocument();
//Add page
doc.Pages.Add();
//Set tab order
doc.Pages[0].SetTabOrder(TabOrder.Structure);
//Create PdfTaggedContent
PdfTaggedContent taggedContent = new PdfTaggedContent(doc);
taggedContent.SetLanguage("en-US");
taggedContent.SetTitle("test");
//Set font
PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Times New Roman", 10), true);
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
//Append elements
PdfStructureElement article = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document);
PdfStructureElement paragraph1 = article.AppendChildElement(PdfStandardStructTypes.Paragraph);
PdfStructureElement span1 = paragraph1.AppendChildElement(PdfStandardStructTypes.Span);
span1.BeginMarkedContent(doc.Pages[0]);
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify);
doc.Pages[0].Canvas.DrawString("Spire.PDF for .NET is a professional PDF API applied to creating, writing, editing, handling and reading PDF files.",
font, brush, new Rectangle(40, 0, 480, 80), format);
span1.EndMarkedContent(doc.Pages[0]);
PdfStructureElement paragraph2 = article.AppendChildElement(PdfStandardStructTypes.Paragraph);
paragraph2.BeginMarkedContent(doc.Pages[0]); doc.Pages[0].Canvas.DrawString("Spire.PDF for .NET can be applied to easily convert Text, Image, SVG, HTML to PDF and convert PDF to Excel with C#/VB.NET in high quality.",
font, brush, new Rectangle(40, 80, 480, 60), format);
paragraph2.EndMarkedContent(doc.Pages[0]);
PdfStructureElement figure1 = article.AppendChildElement(PdfStandardStructTypes.Figure);
//Set Alternate text
figure1.Alt = "replacement text1";
figure1.BeginMarkedContent(doc.Pages[0], null);
PdfImage image = PdfImage.FromFile(@"E-logo.png");
doc.Pages[0].Canvas.DrawImage(image, new PointF(40, 200), new SizeF(100, 100));
figure1.EndMarkedContent(doc.Pages[0]);
PdfStructureElement figure2 = article.AppendChildElement(PdfStandardStructTypes.Figure);
//Set Alternate text
figure2.Alt = "replacement text2";
figure2.BeginMarkedContent(doc.Pages[0], null);
doc.Pages[0].Canvas.DrawRectangle(PdfPens.Black, new Rectangle(300, 200, 100, 100));
figure2.EndMarkedContent(doc.Pages[0]);
//Save to file
String result = "CreateTaggedFile_result.pdf";
doc.SaveToFile(result);
doc.Close();//Note:At present, in order to ensure the validity of the output PDF/UA file, it is necessary to add the valid license of Spire.PDF for .net to remove the red warning watermark.
//Spire.License.LicenseProvider.SetLicenseKey("valid license key");
//Create a pdf document
PdfDocument doc = new PdfDocument();
//Add page
doc.Pages.Add();
//Set tab order
doc.Pages[0].SetTabOrder(TabOrder.Structure);
//Create PdfTaggedContent
PdfTaggedContent taggedContent = new PdfTaggedContent(doc);
taggedContent.SetLanguage("en-US");
taggedContent.SetTitle("test");
//Set PDF/UA1 identification
taggedContent.SetPdfUA1Identification();
//Set font
PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Times New Roman", 10), true);
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
//Append elements
PdfStructureElement article = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document);
PdfStructureElement paragraph1 = article.AppendChildElement(PdfStandardStructTypes.Paragraph);
PdfStructureElement span1 = paragraph1.AppendChildElement(PdfStandardStructTypes.Span);
span1.BeginMarkedContent(doc.Pages[0]);
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify);
doc.Pages[0].Canvas.DrawString("Spire.PDF for .NET is a professional PDF API applied to creating, writing, editing, handling and reading PDF files.",
font, brush, new Rectangle(40, 0, 480, 80), format);
span1.EndMarkedContent(doc.Pages[0]);
PdfStructureElement paragraph2 = article.AppendChildElement(PdfStandardStructTypes.Paragraph);
paragraph2.BeginMarkedContent(doc.Pages[0]);
doc.Pages[0].Canvas.DrawString("Spire.PDF for .NET can be applied to easily convert Text, Image, SVG, HTML to PDF and convert PDF to Excel with C#/VB.NET in high quality.",
font, brush, new Rectangle(40, 80, 480, 60), format);
paragraph2.EndMarkedContent(doc.Pages[0]);
PdfStructureElement figure1 = article.AppendChildElement(PdfStandardStructTypes.Figure);
//Set Alternate text
figure1.Alt = "replacement text1";
figure1.BeginMarkedContent(doc.Pages[0], null);
PdfImage image = PdfImage.FromFile(@"E-logo.png");
doc.Pages[0].Canvas.DrawImage(image, new PointF(40, 200), new SizeF(100, 100));
figure1.EndMarkedContent(doc.Pages[0]);
PdfStructureElement figure2 = article.AppendChildElement(PdfStandardStructTypes.Figure);
//Set Alternate text
figure2.Alt = "replacement text2";
figure2.BeginMarkedContent(doc.Pages[0], null);
doc.Pages[0].Canvas.DrawRectangle(PdfPens.Black, new Rectangle(300, 200, 100, 100));
figure2.EndMarkedContent(doc.Pages[0]);
//Save to file
String result = "CreatePDFUAFile_result.pdf";
doc.SaveToFile(result);
doc.Close();问题修复:
新功能:
功能调整:
问题修复:
新功能:
ExportTableOptions options = new ExportTableOptions();
options.KeepDataFormat = false;
DataTable table = sheet.ExportDataTable(1, 1, sheet.LastDataRow, sheet.LastDataColumn, options);问题修复:
问题修复:
新功能:
SlidePicture slidePicture = (SlidePicture)presentation.Slides[0].Shapes[0];
slidePicture.Crop(float x, float y, float width, float height);presentation.Slides[0].Shapes[0].InsertPicture(Stream stream) public void CreateWaterFall(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.WaterFall, new RectangleF(50, 50, 500, 400), false);
chart.ChartData[0, 1].Text = "Series 1";
string[] categories = { "Category 1", "Category 2", "Category 3", "Category 4", "Category 5", "Category 6", "Category 7" };
for (int i = 0; i < categories.Length; i++)
{
chart.ChartData[i + 1, 0].Text = categories[i];
}
double[] values = { 100, 20, 50, -40, 130, -60, 70 };
for (int i = 0; i < values.Length; i++)
{
chart.ChartData[i + 1, 1].NumberValue = values[i];
}
chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, 1];
chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
chart.Series[0].Values = chart.ChartData[1, 1, values.Length, 1];
ChartDataPoint chartDataPoint = new ChartDataPoint(chart.Series[0]);
chartDataPoint.Index = 2;
chartDataPoint.SetAsTotal = true;
chart.Series[0].DataPoints.Add(chartDataPoint);
ChartDataPoint chartDataPoint2 = new ChartDataPoint(chart.Series[0]);
chartDataPoint2.Index = 5;
chartDataPoint2.SetAsTotal = true;
chart.Series[0].DataPoints.Add(chartDataPoint2);
chart.Series[0].ShowConnectorLines = true;
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.ChartLegend.Position = ChartLegendPositionType.Right;
chart.ChartTitle.TextProperties.Text = "WaterFall";
}
public void CreateTreeMap(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.TreeMap, new RectangleF(50, 50, 500, 400), false);
chart.ChartData[0, 3].Text = "Series 1";
string[,] categories = {{"Branch 1","Stem 1","Leaf 1"},{"Branch 1","Stem 1","Leaf 2"},{"Branch 1","Stem 1", "Leaf 3"},
{"Branch 1","Stem 2","Leaf 4"},{"Branch 1","Stem 2","Leaf 5"},{"Branch 1","Stem 2","Leaf 6"},{"Branch 1","Stem 2","Leaf 7"},
{"Branch 2","Stem 3","Leaf 8"},{"Branch 2","Stem 3","Leaf 9"},{"Branch 2","Stem 4","Leaf 10"},{"Branch 2","Stem 4","Leaf 11"},
{"Branch 2","Stem 5","Leaf 12"},{"Branch 3","Stem 5","Leaf 13"},{"Branch 3","Stem 6","Leaf 14"},{"Branch 3","Stem 6","Leaf 15"}};
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 3; j++)
chart.ChartData[i + 1, j].Text = categories[i, j];
}
double[] values = { 17, 23, 48, 22, 76, 54, 77, 26, 44, 63, 10, 15, 48, 15, 51 };
for (int i = 0; i < values.Length; i++)
{
chart.ChartData[i + 1, 3].NumberValue = values[i];
}
chart.Series.SeriesLabel = chart.ChartData[0, 3, 0, 3];
chart.Categories.CategoryLabels = chart.ChartData[1, 0, values.Length, 2];
chart.Series[0].Values = chart.ChartData[1, 3, values.Length, 3];
chart.Series[0].DataLabels.CategoryNameVisible = true;
chart.Series[0].TreeMapLabelOption = TreeMapLabelOption.Banner;
chart.ChartTitle.TextProperties.Text = "TreeMap";
chart.HasLegend = true;
chart.ChartLegend.Position = ChartLegendPositionType.Top;
}
public void CreateSunBurs(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.SunBurst, new RectangleF(50, 50, 500, 400), false);
chart.ChartData[0, 3].Text = "Series 1";
string[,] categories = {{"Branch 1","Stem 1","Leaf 1"},{"Branch 1","Stem 1","Leaf 2"},{"Branch 1","Stem 1", "Leaf 3"},
{"Branch 1","Stem 2","Leaf 4"},{"Branch 1","Stem 2","Leaf 5"},{"Branch 1","Leaf 6",null},{"Branch 1","Leaf 7", null},
{"Branch 2","Stem 3","Leaf 8"},{"Branch 2","Leaf 9",null},{"Branch 2","Stem 4","Leaf 10"},{"Branch 2","Stem 4","Leaf 11"},
{"Branch 2","Stem 5","Leaf 12"},{"Branch 3","Stem 5","Leaf 13"},{"Branch 3","Stem 6","Leaf 14"},{"Branch 3","Leaf 15",null}};
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 3; j++)
chart.ChartData[i + 1, j].Value = categories[i, j];
}
double[] values = { 17, 23, 48, 22, 76, 54, 77, 26, 44, 63, 10, 15, 48, 15, 51 };
for (int i = 0; i < values.Length; i++)
{
chart.ChartData[i + 1, 3].NumberValue = values[i];
}
chart.Series.SeriesLabel = chart.ChartData[0, 3, 0, 3];
chart.Categories.CategoryLabels = chart.ChartData[1, 0, values.Length, 2];
chart.Series[0].Values = chart.ChartData[1, 3, values.Length, 3];
chart.Series[0].DataLabels.CategoryNameVisible = true;
chart.ChartTitle.TextProperties.Text = "SunBurst";
chart.HasLegend = true;
chart.ChartLegend.Position = ChartLegendPositionType.Top;
}
public void CreatePareto(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Pareto, new RectangleF(50, 50, 500, 400), false);
chart.ChartData[0, 1].Text = "Series 1";
string[] categories = { "Category 1", "Category 2", "Category 4", "Category 3", "Category 4", "Category 2", "Category 1",
"Category 1", "Category 3", "Category 2", "Category 4", "Category 2", "Category 3",
"Category 1", "Category 3", "Category 2", "Category 4", "Category 1", "Category 1",
"Category 3", "Category 2", "Category 4", "Category 1", "Category 1", "Category 3",
"Category 2", "Category 4", "Category 1"};
for (int i = 0; i < categories.Length; i++)
{
chart.ChartData[i + 1, 0].Text = categories[i];
}
double[] values = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
for (int i = 0; i < values.Length; i++)
{
chart.ChartData[i + 1, 1].NumberValue = values[i];
}
chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, 1];
chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
chart.Series[0].Values = chart.ChartData[1, 1, values.Length, 1];
chart.PrimaryCategoryAxis.IsBinningByCategory = true;
chart.Series[1].Line.FillFormat.FillType = FillFormatType.Solid;
chart.Series[1].Line.FillFormat.SolidFillColor.Color = Color.Red;
chart.ChartTitle.TextProperties.Text = "Pareto";
chart.HasLegend = true;
chart.ChartLegend.Position = ChartLegendPositionType.Bottom;
}
public void CreateHistogram(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Histogram, new RectangleF(50, 50, 500, 400), false);
chart.ChartData[0, 0].Text = "Series 1";
double[] values = { 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 8, 8, 8, 9, 9, 9, 12, 12, 13, 13, 17, 17, 17, 19,
19, 19, 25, 25, 25, 25, 25, 25, 25, 25, 29, 29, 29, 29, 32, 32, 33, 33, 35, 35, 41, 41, 44, 45, 49, 49 };
for (int i = 0; i < values.Length; i++)
{
chart.ChartData[i + 1, 1].NumberValue = values[i];
}
chart.Series.SeriesLabel = chart.ChartData[0, 0, 0, 0];
chart.Series[0].Values = chart.ChartData[1, 0, values.Length, 0];
chart.PrimaryCategoryAxis.NumberOfBins = 7;
chart.PrimaryCategoryAxis.GapWidth = 20;
chart.ChartTitle.TextProperties.Text = "Histogram";
chart.ChartLegend.Position = ChartLegendPositionType.Bottom;
}
public void CreateBoxAndWhisker(Presentation ppt)
{
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.BoxAndWhisker, new RectangleF(50, 50, 500, 400), false);
string[] seriesLabel = { "Series 1", "Series 2", "Series 3" };
for (int i = 0; i < seriesLabel.Length; i++)
{
chart.ChartData[0, i + 1].Text = "Series 1";
}
string[] categories = {"Category 1", "Category 1", "Category 1", "Category 1", "Category 1", "Category 1", "Category 1",
"Category 2", "Category 2", "Category 2", "Category 2", "Category 2", "Category 2",
"Category 3", "Category 3", "Category 3", "Category 3", "Category 3"};
for (int i = 0; i < categories.Length; i++)
{
chart.ChartData[i + 1, 0].Text = categories[i];
}
double[,] values = new double[18, 3]{{-7,-3,-24},{-10,1,11},{-28,-6,34},{47,2,-21},{35,17,22},{-22,15,19},{17,-11,25},
{-30,18,25},{49,22,56},{37,22,15},{-55,25,31},{14,18,22},{18,-22,36},{-45,25,-17},
{-33,18,22},{18,2,-23},{-33,-22,10},{10,19,22}};
for (int i = 0; i < seriesLabel.Length; i++)
{
for (int j = 0; j < categories.Length; j++)
{
chart.ChartData[j + 1, i + 1].NumberValue = values[j, i];
}
}
chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, seriesLabel.Length];
chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
chart.Series[0].Values = chart.ChartData[1, 1, categories.Length, 1];
chart.Series[1].Values = chart.ChartData[1, 2, categories.Length, 2];
chart.Series[2].Values = chart.ChartData[1, 3, categories.Length, 3];
chart.Series[0].ShowInnerPoints = false;
chart.Series[0].ShowOutlierPoints = true;
chart.Series[0].ShowMeanMarkers = true;
chart.Series[0].ShowMeanLine = true;
chart.Series[0].QuartileCalculationType = QuartileCalculation.ExclusiveMedian;
chart.Series[1].ShowInnerPoints = false;
chart.Series[1].ShowOutlierPoints = true;
chart.Series[1].ShowMeanMarkers = true;
chart.Series[1].ShowMeanLine = true;
chart.Series[1].QuartileCalculationType = QuartileCalculation.InclusiveMedian;
chart.Series[2].ShowInnerPoints = false;
chart.Series[2].ShowOutlierPoints = true;
chart.Series[2].ShowMeanMarkers = true;
chart.Series[2].ShowMeanLine = true;
chart.Series[2].QuartileCalculationType = QuartileCalculation.ExclusiveMedian;
chart.HasLegend = true;
chart.ChartTitle.TextProperties.Text = "BoxAndWhisker";
chart.ChartLegend.Position = ChartLegendPositionType.Top;
}Spire.Doc 10.7.16已发布。该版本增强了 Word 到 PDF 及 HTML 到 Word的转换功能。此外,还修复了统计段落字符数目不正确等已知问题。详情请阅读以下内容。
问题修复:
Spire.Doc for Java 10.7.10 已发布。此版本增强了 Word 和 HTML 到 PDF 、HTML到图片、Word 到 HTML 的转换。同时此版本还修复了一些已知问题,如:加载和保存有密码保护的文档时密码丢失及设置 docPicture.setWidthScale 和 docPicture.setHeightScale 属性不生效等问题。详情请阅读以下内容。
问题修复: