com.aspose.words.document中关于设置字体颜色的属性
时间: 2023-05-15 20:07:53 浏览: 1098
您可以使用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 转pdf韩语乱码
如果在将 com.aspose.words 转换成 PDF 格式时出现韩语乱码问题,可能是因为字体缺失导致的。您可以尝试在转换前将所需的字体文件嵌入到 Word 文档中,或者在转换时指定所需的字体文件。例如,以下代码可以在转换时指定字体:
```
com.aspose.words.Document doc = new com.aspose.words.Document("input.docx");
// 设置字体文件路径
String fontPath = "C:\\Windows\\Fonts\\malgun.ttf";
// 定义字体
com.aspose.words.FontSettings fontSettings = new com.aspose.words.FontSettings();
fontSettings.setFontsFolder(fontPath, true);
// 将字体应用到文档中
doc.setFontSettings(fontSettings);
// 将文档转换为 PDF
doc.save("output.pdf");
```
这样可以确保在转换时使用指定的字体文件,从而避免韩语乱码问题。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)