Ouvrir des fichiers PSD, PSB et AI et les exporter en PDF, PNG, TIFF, GIF, BMP, JPEG

Contents
[ ]

Aperçu

Pour convertir des fichiers PSD, PSB et AI en différents formats en utilisant Java, vous pouvez utiliser la bibliothèque Aspose.PSD. Voici un aperçu des étapes impliquées:

  • Importez les classes et modules nécessaires de la bibliothèque Aspose.PSD.

  • Définissez diverses options pour différents formats tels que PNG, PDF, TIFF, JPEG, BMP, JPEG2000, GIF, PSB et PSD.

  • Créez un dictionnaire qui fait correspondre les extensions de fichiers à leurs options de sauvegarde respectives.

  • Chargez le fichier PSD en utilisant PsdImage.load() et itérez à travers le dictionnaire des formats pour enregistrer l’image dans chaque format désiré.

  • De même, chargez le fichier AI en utilisant AiImage.load() et itérez à travers le dictionnaire des formats pour enregistrer l’image dans chaque format désiré.

Assurez-vous de fournir les bons chemins de fichiers pour les fichiers PSD et AI sources. Voici la procédure générale pour convertir des fichiers PSD, PSB et AI en différents formats en utilisant Aspose.PSD pour Java.

Veuillez consulter l’exemple complet.

Exemple

public void exportPsdAndAIToDifferentFormatsTest() {
// Saving to PNG
PngOptions pngSaveOpt = new PngOptions();
pngSaveOpt.setColorType(PngColorType.TruecolorWithAlpha);
// Saving to PDF
PdfOptions pdfSaveOpt = new PdfOptions();
// Saving to Tiff
TiffOptions tiffSaveOpt = new TiffOptions(TiffExpectedFormat.TiffNoCompressionRgba);
// Saving to Jpeg
JpegOptions jpegSaveOpt = new JpegOptions();
jpegSaveOpt.setQuality(90);
// Saving to BMP
BmpOptions bmpSaveOpt = new BmpOptions();
// Saving to JPEG2000
Jpeg2000Options j2kSaveOpt = new Jpeg2000Options();
// Saving to GIF
GifOptions gifSaveOpt = new GifOptions();
// Saving to PSB
PsdOptions psbSaveOpt = new PsdOptions();
psbSaveOpt.setVersion(2);
// Saving to PSD
PsdOptions psdSaveOpt = new PsdOptions();
Map<String, ImageOptionsBase> formats = new HashMap<>();
formats.put("pdf", pdfSaveOpt);
formats.put("jpg", jpegSaveOpt);
formats.put("png", pngSaveOpt);
formats.put("tif", tiffSaveOpt);
formats.put("gif", gifSaveOpt);
formats.put("j2k", j2kSaveOpt);
formats.put("bmp", bmpSaveOpt);
formats.put("psb", psbSaveOpt);
formats.put("psd", psdSaveOpt);
// Saving PSD to other formats
String sourcePsd = "AllTypesLayerPsd2.psd";
try (PsdImage image = (PsdImage) com.aspose.psd.Image.load(sourcePsd)) {
for (Map.Entry<String, ImageOptionsBase> entry : formats.entrySet()) {
String format = entry.getKey();
ImageOptionsBase saveOpt = entry.getValue();
String fn = "export.psd.to." + format;
image.save(fn, saveOpt);
}
}
// Saving AI to other formats
String sourceAi = "ai_one_text_3.ai";
try (AiImage image = (AiImage) com.aspose.psd.Image.load(sourceAi)) {
for (Map.Entry<String, ImageOptionsBase> entry : formats.entrySet()) {
String format = entry.getKey();
ImageOptionsBase saveOpt = entry.getValue();
String fn = "export.ai.to." + format;
image.save(fn, saveOpt);
}
}
}