PS sang PDF
Chuyển đổi PS sang PDF thông qua Giải pháp API cho Java.
Công cụ chuyển đổi Aspose.Page cho PS sang PDF cung cấp chuyển đổi tệp PS sang hình ảnh PDF bằng cách sử dụng bất kỳ ngôn ngữ nào được Java hỗ trợ
API bạn thấy ở đây có thể được sử dụng để tạo ứng dụng đa nền tảng của riêng bạn hoặc được tích hợp vào dự án Java của bạn.
Để chuyển đổi XPS sang PDF, chúng tôi sẽ sử dụng:
Aspose.Page cho Java API là một API chuyển đổi và thao tác tài liệu giàu tính năng, mạnh mẽ và dễ sử dụng cho nền tảng Java. Bạn có thể tải xuống phiên bản mới nhất của nó trực tiếp từ Maven và cài đặt nó trong dự án dựa trên Maven của bạn bằng cách thêm các cấu hình sau vào pom.xml.
Mở trình quản lý gói NuGet, tìm kiếm Aspose.Page và cài đặt. Bạn cũng có thể sử dụng lệnh sau từ Bảng điều khiển Trình quản lý Gói.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-page</artifactId>
<version>version of aspose-page API</version>
<classifier>jdk17</classifier>
</dependency>
Các bước chuyển đổi PS sang PDF qua Java
Aspose.Page giúp các nhà phát triển dễ dàng tải và chuyển đổi các tệp PS sang PDF chỉ trong một vài dòng mã.
- Tải tệp nguồn vào một thể hiện của
PsDocument. - Tạo một thể hiện của
PdfSaveOptionsvà đặt các tùy chọn chuyển đổi bạn cần. - Gọi
psDocument.saveAsPdf()với đường dẫn tệp đầu ra và đối tượng tùy chọn.
yêu cầu hệ thống
Aspose.Page cho Java được hỗ trợ trên tất cả các hệ điều hành chính. Nhưng trước khi bắt đầu làm việc Chỉ cần đảm bảo rằng bạn có các điều kiện tiên quyết sau:
- Microsoft Windows hoặc hệ điều hành tương thích với Môi trường thời gian chạy Java cho Ứng dụng JSP / JSF và Ứng dụng trên máy tính để bàn.
- Môi trường phát triển như Microsoft Visual Studio.
- Tải phiên bản mới nhất của Aspose.PSD cho Java trực tiếp từ Maven.
Mã mẫu này hiển thị Chuyển đổi Java từ PS sang PDF
// Convert PS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(595x842));
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.setConvertFontsToTTF(false);
// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}PS What is PS File Format
PS (PostScript) là ngôn ngữ mô tả trang, kết hợp văn bản và đồ họa trong một tệp. Được hỗ trợ rộng rãi bởi các phần mềm chỉnh sửa ảnh và máy in, cung cấp chỉ dẫn render cho máy in.
PDF What is PDF File Format
PDF (Portable Document Format) là định dạng mở đa nền tảng cho tài liệu, hỗ trợ văn bản, vector, raster và đa phương tiện, có thể mở trên hầu hết các thiết bị.