com.aspose.words.document中关于设置字体颜色的属性
时间: 2023-05-15 13:07:53 浏览: 1605
您可以使用Aspose.Words中的Font.Color属性来设置字体颜色。以下是一个示例代码片段:
Document doc = new Document("input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// 设置字体颜色为红色
builder.Font.Color = Color.Red;
// 插入文本
builder.Write("Hello World!");
doc.Save("output.docx");
这将在文档中插入一个红色的“Hello World!”文本。
相关问题
com.aspose.words中docx转pdf设置字体
在使用Aspose.Words将DOCX文档转换为PDF时,可以使用以下代码设置字体:
```java
// 加载DOCX文档
Document doc = new Document("input.docx");
// 创建PDF的Options对象
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
// 设置嵌入字体
pdfSaveOptions.setEmbedFullFonts(true);
// 设置字体子集化
pdfSaveOptions.setSubsetFonts(true);
// 设置嵌入的字体格式
pdfSaveOptions.setEmbedStandardWindowsFonts(true);
// 设置PDF的输出路径
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);
doc.save("output.pdf", pdfSaveOptions);
```
在这个例子中,我们创建了一个`PdfSaveOptions`对象并设置了字体的相关选项。`setEmbedFullFonts`方法指定是否嵌入完整字体集,`setSubsetFonts`方法指定是否启用字体子集化,`setEmbedStandardWindowsFonts`方法指定是否嵌入标准Windows字体。最后,我们将PDF的保存格式设置为`PDF`并将其保存到指定的输出路径中。
com.aspose.words Document 如何获取文件中的文字及格式
要从Aspose.Words `Document` 对象中获取文件中的文字及其格式,你可以按照以下步骤操作:
1. **打开文档**[^1]:
使用`Document`类的构造函数加载Word文档,如示例中所示:
```csharp
// Open the Word document
Aspose.Words.Document doc = new Aspose.Words.Document("demo.doc");
```
2. **遍历文本范围**:
使用`DocumentBuilder`对象可以方便地访问和修改文档中的文本。通过调用`MoveTo`和`ReadText`方法,你可以逐行读取并处理文本:
```csharp
DocumentBuilder builder = new DocumentBuilder(doc);
// Move to the start of the document
builder.MoveToStart();
// Read text in chunks while there's more content
while (!builder.AtEndOfDocument)
{
string line = builder.ReadText(UnitType.Paragraph); // Read a paragraph at a time
Console.WriteLine(line); // Process the text as needed, including formatting
}
```
3. **处理格式**:
在循环内部,你可以使用`Run.Font`, `ParagraphFormat`等属性来访问文本的字体、字号、颜色等格式信息。例如:
```csharp
Run run = builder.CurrentRun;
Font font = run.Font; // Get the font properties
ParagraphFormat pf = builder.ParagraphFormat; // Get paragraph-level formatting
```
阅读全文
相关推荐
















