STL File Viewer using Java

STL (STereoLithography) file format is vastly used for 3D CAD drawings and printing. On the other hand, many other formats are more portable than STL. Here comes the requirement to render the STL format into other formats. In this article, we will discuss how to render the STL files into PDF format using Java. In addition to this, we will convert the STL files to HTML, JPG, and PNG formats within Java application using examples.

The following topics are discussed below:

Java API to View STL Files

GroupDocs.Viewer showcases document viewer Java API that allows rendering the documents into PDF, HTML, and images within the Java application. In this article, we will it in examples to convert the STL files into different other file formats.

You can download the JAR file from the downloads section or use the latest repository and dependency Maven configurations within your Java applications.

<repository>
	<id>GroupDocsArtifactRepository</id>
	<name>GroupDocs Artifact Repository</name>
	<url>https://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-viewer</artifactId>
        <version>21.11.1</version> 
</dependency>

View STL File as PDF using Java

The high portability of PDF format often leads to the conversion of other formats to PDF. The following steps guide how to convert the STL files into PDF format in Java.

  • Load the STL file using the Viewer class.
  • Prepare the PDF rendering options using the PdfViewOptions class.
  • Render the STL file as PDF using the view() method.

The following Java code example renders the STL files into PDF format.

View STL File as HTML, JPG, or PNG using Java

Quite similarly, you can also convert the STL files into various other formats. The following steps help you to render the STL files into HTML, JPG, and PNG formats using Java.

  • Load the STL file using the Viewer class.
  • Prepare the rendering options according to the intended output format:
  • Render the STL file as HTML, JPG, or PNG using the view() method.

Below are the Java source code examples that independently render STL files into each format using the above-mentioned respective format options.

STL to HTML using Java

The following Java code converts the STL file into HTML format with embedded resources. Similarly, you can convert to HTML with external resources.

STL to JPG using Java

The following Java code renders the STL file into JPG image format.

STL to PNG using Java

The following Java code converts the STL file into PNG image format.

Get a Free API License

You can use the APIs for free by getting a temporary license.

Conclusion

To sum up, we learned to render the STL files into PDF, HTML, JPG, and PNG formats using the Java examples. Now, you can try developing your own STL viewing application like the Online App of Groupdocs.Viewer.

To learn more about GroupDocs.Viewer for Java, visit its documentation. For queries, contact us via the forum.

See Also