Konversi PS, EPS, dan XPS
Solusi API konverter PS, EPS, dan XPS untuk .NET.
Kapan pun ada kebutuhan untuk mengonversi File PostScript PS dan Encapsulated PostScript EPS serta dokumen XPS secara terprogram, .NET API dapat melakukannya dengan lancar dan mengonversi banyak file. Untuk PS dan EPS, API mendukung operator PostScript Level 1-3 dan sebagian besar komentar header EPS serta mengubah dokumen PostScript yang memiliki kesesuaian maksimum dengan pengecualian beberapa kasus font dan API menangani font seperti Time New Roman.
Selain itu, untuk transformasi file XPS, API dapat menambah atau menghapus halaman, menangani elemen kanvas, jalur, dan mesin terbang, membuat bentuk grafik vektor, string teks, mengonversi item garis besar XPS, dan banyak lagi.
Solusi API untuk .NET di sini memungkinkan Anda mengonversi file format PDL seperti PS, EPS, dan XPS secara terprogram, tetapi Anda mungkin merasa berguna untuk melihat dan mencoba lintas platform yang dikembangkan pada API asli ini.
Konversi PostScript ke PDF melalui C# .NET.
Untuk mengonversi file PostScript PS dan Encapsulated PostScript EPS ke PDF melalui .NET API, Anda perlu melakukan langkah-langkah berikut:
- Muat file PS atau EPS menggunakan PsDocument Class .
- Setel penyimpanan PDF menggunakan PdfSaveOptions Class .
- Gunakan FileStream Class untuk file PDF keluaran.
- PdfDevice Class dengan menginisialisasi dengan output objek filestream PDF.
- Hubungi PsDocument.Save untuk konversi PDF.
Kode C# untuk Konversi PS EPS ke PDF
// The path to the documents directory. | |
string dataDir = "definedDirectoryPath"; | |
// Initialize PsDocument with the name of PostScript file. | |
PsDocument document = new PsDocument(dataDir + "input.ps"); | |
// If you want to convert Postscript file despite of minor errors set this flag | |
bool 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.AdditionalFontsFolders = 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, Aspose.Page.Drawing.Size(595x842)); | |
// or | |
//saveOptions.Size = new Aspose.Page.Drawing.Size(595x842); | |
document.SaveAsPdf(dataDir + "outputPDF_out.pdf", options); | |
//Review errors | |
if (suppressErrors) | |
{ | |
foreach (Exception ex in options.Exceptions) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} |
Konversi PostScript ke Gambar melalui C# .NET.
Untuk aplikasi EPS/PS PostScript to image converter, kode C# berikut ini berfungsi dengan baik, jadi ikuti langkah-langkah selanjutnya:
- Muat dokumen menggunakan kelas PsDocument yang memiliki aliran file input sebagai parameter.
- Buat objek ImageSaveOptions Class dan inisialisasi dengan pengaturan yang diperlukan.
- Simpan setiap halaman file input ke gambar PNG, JPG, TIFF, BMP, dll.
Kode C# untuk Konversi PostScript ke Gambar
// The path to the documents directory. | |
string dataDir = "definedDirectoryPath"; | |
// Initialize PsDocument with the name of PostScript file. | |
PsDocument document = new PsDocument(dataDir + "inputForImage.ps"); | |
// If you want to convert Postscript file despite of minor errors set this flag | |
bool suppressErrors = true; | |
//Initialize options object with necessary parameters. | |
ImageSaveOptions options = new ImageSaveOptions(); | |
//Set output image format. | |
options.ImageFormat = Aspose.Page.Drawing.Imaging.ImageFormat.Png; | |
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" }; | |
// Save PS document as array of image bytes, one bytes array for one page. | |
byte[][] imagesBytes = document.SaveAsImage(options); | |
//Save images bytes arrays as image files. | |
int i = 0; | |
foreach (byte[] imageBytes in imagesBytes) | |
{ | |
string imagePath = Path.GetFullPath(dataDir + "out_image" + i.ToString() +"." + options.ImageFormat.ToString().ToLower()); | |
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write)) | |
{ | |
fs.Write(imageBytes, 0, imageBytes.Length); | |
} | |
i++; | |
} |
FAQ
1. Bisakah saya mengonversi Postscript dengan solusi API ini?
Aspose.Page memiliki fungsionalitas yang memungkinkan Anda mengonversi file PS, XPS, dan EPS ke format lain secara online atau terprogram. Jika Anda perlu mengubah file Anda secara instan secara online, Anda mungkin ingin menggunakan Halaman Deskripsi Bahasa format file Converter aplikasi lintas platform.
2. Apa deskripsi Halaman Bahasa yang didukung oleh konverter?
Fungsionalitas konversi ini mendukung file dengan ekstensi .ps, .eps, dan .xps. PDL terkenal seperti PDF dan SVG direpresentasikan sebagai solusi terpisah di Aspose.products
3. Apakah fungsionalitasnya gratis?
Pengonversi lintas platform gratis, sedangkan untuk solusi API Anda bisa mendapatkan Uji Coba gratis dan kemudian membeli produk jika diperlukan.
Konversi XPS ke Gambar JPG, PNG, BMP melalui C# .NET.
.NET API juga mendukung Konversi XPS ke Gambar BMP, JPG, PNG, TIFF, dll., dan menyediakan Kelas XpsDocument untuk operasi XPS. Untuk mengonversi XPS ke Gambar, lakukan langkah-langkah berikut:
- Muat file XPS dari aliran.
- Inisialisasi opsi penyimpanan gambar yang relevan misalnya untuk XPS ke JPG adalah JpegSaveOptions dan untuk XPS ke PNG PngSaveOptions . Berikut adalah daftar semua XPS ke Gambar save options .
- Tentukan pengaturan yang relevan seperti SmoothingMode, Resolution, dan PageNumbers dll untuk rendering. Terakhir, ulangi melalui partisi dokumen untuk menyimpannya ke dalam gambar.
Kode C# untuk XPS ke Konversi Gambar
// The path to the documents directory. | |
string dataDir = "definedDirectoryPath"; | |
//Outut file | |
string outputFileName = dataDir + "XPStoImage_out.jpeg"; | |
// Load XPS document form the XPS file | |
XpsDocument document = new XpsDocument(dataDir + "input.xps", new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
JpegSaveOptions options = new JpegSaveOptions() | |
{ | |
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality, | |
Resolution = 300, | |
PageNumbers = new int[] { 1, 2, 6 } | |
}; | |
// Save XPS document to the images byte arrays. The first dimension is for inner documents | |
/// and the second one is for pages within inner documents. | |
byte[][][] imagesBytes = document.SaveAsImage(options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int i = 0; i < imagesBytes.Length; i++) | |
{ | |
// Iterate through partition pages | |
for (int j = 0; j < imagesBytes[i].Length; j++) | |
{ | |
// Initialize image output stream | |
using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) + Path.DirectorySeparatorChar + | |
Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) + | |
Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write)) | |
// Write image | |
imageStream.Write(imagesBytes[i][j], 0, imagesBytes[i][j].Length); | |
} | |
} |
Support and Learning Resources
- Sumber Belajar
- Dokumentasi
- Kode sumber
- Referensi API
- Dukungan Produk
- Dukungan Gratis
- Dukungan Berbayar
- Blog
- Release Notes
- Mengapa Aspose.Page untuk .NET?
- Daftar Pelanggan
- Cerita-cerita sukses