本文介绍如何在 Java 中创建 EPS 文件。它讨论了在 Java 中创建 EPS 文件的分步过程和可运行的代码片段。此外,您还可以根据需要自定义转换。
使用 Java 创建 EPS 文件的步骤
- 通过配置 Aspose.Page 来准备创建 PostScript 文档的环境
- 启动 PsSaveOptions 类的实例并指定自定义值
- 声明 PsDocument 类的对象
- 导出生成的EPS文件
这些步骤描述了如何在 Java 中制作 EPS 文件。首先,定义一个输出流以导出输出 PostScript 文件。接下来,设置自定义属性并将输出文件导出到指定的流,只需几个 API 调用即可完成该过程。
使用 Java 制作 EPS 文件的代码
import com.aspose.page.*; | |
import java.io.FileOutputStream; | |
public class Main | |
{ | |
public static void main(String[] args) throws Exception // Create EPS file in Java | |
{ | |
// Set the licenses | |
new License().setLicense("License.lic"); | |
// Create output stream for PostScript document | |
FileOutputStream outPsStream = new FileOutputStream("CreateDocument.eps"); | |
// Create save options with A4 size | |
com.aspose.eps.device.PsSaveOptions options = new com.aspose.eps.device.PsSaveOptions(); | |
// Set page size in options | |
options.setPageSize(com.aspose.eps.PageConstants.getSize(com.aspose.eps.PageConstants.SIZE_A4, com.aspose.eps.PageConstants.ORIENTATION_PORTRAIT)); | |
// Set page margins in options | |
options.setMargins(com.aspose.eps.PageConstants.getMargins(com.aspose.eps.PageConstants.MARGINS_ZERO)); | |
// Set variable for multi-paged file | |
boolean multiPaged = false; | |
// Create the PS Document | |
com.aspose.eps.PsDocument document = new com.aspose.eps.PsDocument(outPsStream, options, multiPaged); | |
// Close current page | |
document.closePage(); | |
// Save the document | |
document.save(); | |
System.out.println("EPS file created successfully"); | |
} | |
} |
上述示例代码演示了在 Java 中创建 EPS 的简要过程。声明 PsSaveOptions 类的一个对象,该对象可用于设置自定义选项,如页面大小、多页、页边距、嵌入字体、背景颜色等。最后,创建 PsDocument 类的一个实例并保存输出的封装 PostScript 文件。
本文详细分析了有关如何使用 Java 制作 EPS 文件的信息。此外,如果您需要将图像导出为 EPS 格式,请访问 在 Java 中将图像转换为 EPS 上的文章。