STP/STEP to PDF or Raster Image conversion

Hi,
our general goal is to create preview images (could be a raster image or PDF) for STP/STEP files with the Java SDK, but I struggle to do so.
Here Aspose.CAD Java API | Process and Convert CAD and BIM Files | products.aspose.com it says, that there is Bi-directional support for “Standard for the Exchange of Product Model Data (STEP/STP)”.
In the Aspose.CAD for Java documentation there is no single reference for STEP/STP files (Aspose.CAD for Java|Documentation).
Any working sample code to convert a STEP/STP file to JPEG or PDF?
Thanks in advance.

BR Alex

@abacelum

To convert STP/STEP files to JPEG or PDF using the Aspose.CAD for Java SDK, you can utilize the library’s capabilities for handling various CAD formats, including STEP files. Below is a sample code snippet that demonstrates how to perform this conversion.

Sample Code to Convert STEP to JPEG

import com.aspose.cad.Image;
import com.aspose.cad.ImageOptions;
import com.aspose.cad.fileformats.stp.STPImage;
import com.aspose.cad.imageoptions.JpegOptions;

import java.io.File;

public class StepToJpegConverter {
    public static void main(String[] args) {
        // Load the STEP file
        String stepFilePath = "path/to/your/file.stp";
        String jpegOutputPath = "path/to/output/file.jpeg";

        // Load the STP image
        try (Image image = Image.load(stepFilePath)) {
            // Create JPEG options
            JpegOptions jpegOptions = new JpegOptions();
            jpegOptions.setQuality(100); // Set quality to maximum

            // Save the image as JPEG
            image.save(jpegOutputPath, jpegOptions);
            System.out.println("Conversion to JPEG completed successfully.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Sample Code to Convert STEP to PDF

import com.aspose.cad.Image;
import com.aspose.cad.imageoptions.PdfOptions;

public class StepToPdfConverter {
    public static void main(String[] args) {
        // Load the STEP file
        String stepFilePath = "path/to/your/file.stp";
        String pdfOutputPath = "path/to/output/file.pdf";

        // Load the STP image
        try (Image image = Image.load(stepFilePath)) {
            // Create PDF options
            PdfOptions pdfOptions = new PdfOptions();

            // Save the image as PDF
            image.save(pdfOutputPath, pdfOptions);
            System.out.println("Conversion to PDF completed successfully.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Notes:

  • Make sure to replace "path/to/your/file.stp" and "path/to/output/file.jpeg" or "path/to/output/file.pdf" with the actual paths to your files.
  • The Aspose.CAD library must be included in your project dependencies to run this code.

This should help you create preview images or PDFs from STP/STEP files using the Aspose.CAD for Java SDK. If you have any further questions or need additional assistance, feel free to ask!

Sources:
[1]: Aspose.CAD Product Family

1 Like