PSD format is used by Adobe Photoshop in order to save the data related to graphical designs. A PSD file may consist of single or multiple layers that collectively form the graphics. However, to view or embed the PSD images directly into your web or desktop applications is not feasible. In order to cope with this issue, you can convert the PSD document to PDF or raster image formats. In accordance with that, this article provides some simple ways of converting PSD files to PDF, PNG, JPEG, GIF, and other image formats using Java.
- Java PSD Converter API
- Convert PSD File to PDF using Java
- Convert PSD File to Raster Images using Java
- Export Layer in PSD to Raster Image in Java
Java PSD Converter API – Free Download
Aspose.PSD for Java is a powerful PSD file manipulation API that lets you process, edit, and convert PSD documents from within your Java applications. The API’s converter engine allows you to convert PSD files to other formats with high fidelity. You can either download API’s JAR or install it within your Maven-based applications.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-psd</artifactId>
<version>20.9</version>
<classifier>jdk16</classifier>
</dependency>
Convert PSD File to PDF using Java
PDF is one of the most popular digital document formats that ensures the stability of the document’s layout regardless of the hardware or software. Therefore, PSD to PDF conversion can be adopted in most of the scenarios. The following are the steps to convert a PSD file to PDF.
- Load the PSD file using Image class.
- Create an instance of PdfOptions class.
- Convert PSD to PDF using Image.save(String, PdfOptions) method.
The following code sample shows how to convert a PSD file to PDF in Java.
Convert PSD File to JPEG, PNG, BMP, GIF and JP2 using Java
In case it is not suitable for you to convert PSD to PDF, you can opt for the other option; conversion of PSD to raster images. Aspose.PSD for Java allows you to convert PSD file to the following raster image formats:
- JPEG
- PNG
- BMP
- GIF
- JP2
The following are the steps to convert a PSD file to a particular raster image format.
- Load the PSD file using Image class.
- Use the appropriate image options class from the following (according to your desired output format):
- Use Image.save(String, ImageOptions) to save converted image.
The following code sample shows how to convert a PSD file to PNG, JPEG, BMP, GIF, and JPEG 2000 images using Java.
Export Each Layer in PSD to a Separate Image
You can also convert specific layers in the PSD file to the raster image. The following code sample shows how to convert each layer in a PSD file to a separate PNG image.
Conclusion
PSD is the popular file format used by Adobe Photoshop for graphics designing and development. In this article, you have learned how to convert PSD files to PDF and raster image formats including PNG, BMP, JPEG, GIF, and JPEG 2000 using Java. Furthermore, you have seen how to export each layer in PSD as a separate image. You can explore more about the Java PSD API using the documentation.