Konvertieren Sie PS, EPS und XPS
PS-, EPS- und XPS-Konverter-API-Lösung für .NET.
Wann immer es erforderlich ist, PostScript PS- und Encapsulated PostScript EPS-Dateien sowie XPS-Dokumente programmgesteuert zu konvertieren, kann die .NET-API dies reibungslos tun und mehrere Dateien konvertieren. Für PS und EPS unterstützt die API die PostScript-Operatoren der Ebenen 1–3 und die meisten EPS-Header-Kommentare und transformiert PostScript-Dokumente mit maximaler Konformität mit Ausnahme einiger Schriftartenfälle, und die API behandelt Schriftarten wie Time New Roman.
Darüber hinaus kann die API für die Transformation von XPS-Dateien Seiten hinzufügen oder entfernen, mit Leinwänden, Pfaden und Glyphenelementen umgehen, Vektorgrafiken, Textzeichenfolgen erstellen, XPS-Gliederungselemente konvertieren und vieles mehr.
Mit der API-Lösung für .NET hier können Sie Dateien solcher PDL-Formate wie PS, EPS und XPS programmgesteuert konvertieren, aber es kann hilfreich sein, plattformübergreifende Entwicklungen auf diesen nativen APIs zu sehen und auszuprobieren.
Konvertierung von PostScript in PDF über C# .NET.
Um PostScript PS- und Encapsulated PostScript EPS-Dateien über die .NET-API in PDF zu konvertieren, müssen Sie die folgenden Schritte ausführen:
- Laden Sie die PS- oder EPS-Datei mit PsDocument Class .
- Stellen Sie die PDF-Speicherung mit PdfSaveOptions Class ein.
- Verwenden Sie FileStream Class für die PDF-Ausgabedatei.
- PdfDevice Class durch Initialisierung mit Ausgabe-PDF-Filestream-Objekt.
- Rufen Sie PsDocument.Save für die PDF-Konvertierung auf.
C#-Code für die Umwandlung von PS EPS in 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); | |
} | |
} |
Umwandlung von PostScript in Bilder über C# .NET.
Für jede EPS/PS-PostScript-zu-Bild-Konvertierungsanwendung funktioniert der folgende C#-Code gut, also führen Sie die nächsten Schritte aus:
- Laden Sie das Dokument mithilfe der PsDocument-Klasse mit dem Eingabedateistream als Parameter.
- Erstellen Sie das Objekt ImageSaveOptions Class und initialisieren Sie es mit den erforderlichen Einstellungen.
- Speichern Sie jede Eingabedateiseite als Bild PNG, JPG, TIFF, BMP usw.
C#-Code für die Umwandlung von PostScript in Bilder
// 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. Kann ich Postscript mit dieser API-Lösung konvertieren?
Aspose.Page verfügt über Funktionen, mit denen Sie PS-, XPS- und EPS-Dateien online oder programmgesteuert in andere Formate konvertieren können. Wenn Sie Ihre Dateien sofort online umwandeln müssen, können Sie die plattformübergreifende Anwendung Page Description Language Format Files Converter verwenden.
2. Welche Seitenbeschreibungssprachen werden vom Konverter unterstützt?
Diese Konvertierungsfunktion unterstützt Dateien mit den Erweiterungen .ps, .eps und .xps. So berühmte PDLs wie PDF und SVG sind als separate Lösungen in Aspose.products vertreten
3. Ist die Funktion kostenlos?
Die plattformübergreifenden Konverter sind kostenlos, wenn Sie für die API-Lösung eine kostenlose Testversion erhalten und das Produkt dann bei Bedarf kaufen können.
Konvertieren Sie XPS in Bilder JPG, PNG, BMP über C# .NET.
Die .NET-API unterstützt auch die XPS-Konvertierung in Bilder BMP, JPG, PNG, TIFF usw. und stellt die XpsDocument-Klasse für XPS-Operationen bereit. Führen Sie die folgenden Schritte aus, um XPS in Image umzuwandeln:
- XPS-Datei aus dem Stream laden.
- Initialisieren Sie die relevanten Bildspeicheroptionen, z. B. für XPS zu JPG ist es JpegSaveOptions und für XPS zu PNG seine PngSaveOptions . Hier ist eine Liste aller XPS-zu-Bilder Speicheroptionen .
- Definieren Sie relevante Einstellungen wie SmoothingMode, Resolution und PageNumbers etc. für das Rendern. Durchlaufen Sie schließlich Dokumentpartitionen, um sie in Bildern zu speichern.
C#-Code für die XPS-zu-Bild-Konvertierung
// 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
- Lernmittel
- Dokumentation
- Quellcode
- API-Referenzen
- Warum Aspose.Page für .NET?
- Kundenliste
- Erfolgsgeschichten