Turning a 3D model into a PDF document opens up easy sharing and printing across any platform. Aspose.Email Cloud SDK for PHP provides a powerful cloud‑based library that handles 3D to PDF conversion in PHP with just a few API calls. In this tutorial you will see how to configure your credentials, upload an OBJ file, invoke the conversion, download the resulting PDF, and fine‑tune a few options. By the end you will have a reusable PHP script that can be integrated into any web or desktop application.
Before You Start: Prerequisites and Installation
You need a PHP development environment (PHP 8.0+ recommended) and Composer installed. Sign up for an Aspose Cloud account to obtain your Client Id and Client Secret.
Install the SDK with Composer:
composer require aspose/aspose-email-cloud
Download the SDK package if you prefer a manual install: Download URL.
The following snippet shows the configuration block that you will reuse later. Replace the placeholder values with the credentials from your Aspose Cloud dashboard.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Aspose\ThreeD\Configuration;
// -----------------------------------------------------------------------------
// Configuration – replace with your actual Aspose Cloud client credentials
// -----------------------------------------------------------------------------
$config = new Configuration();
$config->setAppSid('YOUR_CLIENT_ID'); // Client Id
$config->setAppKey('YOUR_CLIENT_SECRET'); // Client Secret
$config->setHost('https://api.aspose.cloud'); // Base URL (default)
With the SDK installed and credentials ready, you can move on to the actual conversion steps.
Building It Step by Step: 3D to PDF Conversion in PHP
Step 1: Load Configuration and Set Credentials
First, create a Configuration object and set your client ID, secret, and host. This object will be passed to all API instances.
$config = new Configuration();
$config->setAppSid('YOUR_CLIENT_ID');
$config->setAppKey('YOUR_CLIENT_SECRET');
$config->setHost('https://api.aspose.cloud');
Step 2: Initialise API Instances
Create instances of StorageApi and ThreeDApi using the configuration object.
use Aspose\ThreeD\Api\ThreeDApi;
use Aspose\ThreeD\Api\StorageApi;
$storageApi = new StorageApi(null, $config);
$threeDApi = new ThreeDApi(null, $config);
Step 3: Upload Source 3D File
Upload your local OBJ file to Aspose Cloud storage so the conversion service can access it.
use Aspose\ThreeD\Model\UploadFileRequest;
$source3DFile = 'sample.obj'; // Input 3D model file
$uploadRequest = new UploadFileRequest($source3DFile, $source3DFile);
$storageApi->uploadFile($uploadRequest);
Step 4: Convert 3D to PDF
Request the conversion from OBJ to PDF. The target file name is defined by $targetPdfFile.
use Aspose\ThreeD\Model\Convert3DRequest;
$targetPdfFile = 'sample.pdf'; // Desired output PDF name
$convertRequest = new Convert3DRequest($source3DFile, $targetPdfFile, 'pdf');
$threeDApi->convert3D($convertRequest);
Step 5: Download Resulting PDF
Retrieve the newly created PDF from cloud storage and save it locally.
use Aspose\ThreeD\Model\DownloadFileRequest;
$downloadRequest = new DownloadFileRequest($targetPdfFile);
$response = $storageApi->downloadFile($downloadRequest);
$localPdfPath = __DIR__ . '/output.pdf';
file_put_contents($localPdfPath, $response->getContent());
Step 6: Clean Up Storage
Optionally delete the source OBJ and the generated PDF from cloud storage to keep your account tidy.
$storageApi->deleteFile(new \Aspose\ThreeD\Model\DeleteFileRequest($source3DFile));
$storageApi->deleteFile(new \Aspose\ThreeD\Model\DeleteFileRequest($targetPdfFile));
With these steps completed, you have successfully performed a 3D to PDF conversion in PHP.
Full PHP Script Example: 3D to PDF Conversion in PHP - Full Script
The example below demonstrates the complete workflow in a single file. Copy it into a PHP project and adjust the credential placeholders.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Aspose\ThreeD\Configuration;
use Aspose\ThreeD\Api\ThreeDApi;
use Aspose\ThreeD\Api\StorageApi;
use Aspose\ThreeD\Model\UploadFileRequest;
use Aspose\ThreeD\Model\Convert3DRequest;
use Aspose\ThreeD\Model\DownloadFileRequest;
// -----------------------------------------------------------------------------
// Configuration – replace with your actual Aspose Cloud client credentials
// -----------------------------------------------------------------------------
$config = new Configuration();
$config->setAppSid('YOUR_CLIENT_ID'); // Client Id
$config->setAppKey('YOUR_CLIENT_SECRET'); // Client Secret
$config->setHost('https://api.aspose.cloud'); // Base URL (default)
// -----------------------------------------------------------------------------
// Initialise API instances
// -----------------------------------------------------------------------------
$storageApi = new StorageApi(null, $config);
$threeDApi = new ThreeDApi(null, $config);
// -----------------------------------------------------------------------------
// Define source 3D file and target PDF file (paths are relative to the project)
// -----------------------------------------------------------------------------
$source3DFile = 'sample.obj'; // Input 3D model file
$targetPdfFile = 'sample.pdf'; // Desired output PDF name
// -----------------------------------------------------------------------------
// Upload the 3D file to Aspose Cloud storage
// -----------------------------------------------------------------------------
$uploadRequest = new UploadFileRequest($source3DFile, $source3DFile);
$storageApi->uploadFile($uploadRequest);
// -----------------------------------------------------------------------------
// Perform the conversion: 3D → PDF
// -----------------------------------------------------------------------------
$convertRequest = new Convert3DRequest($source3DFile, $targetPdfFile, 'pdf');
$threeDApi->convert3D($convertRequest);
// -----------------------------------------------------------------------------
// Download the resulting PDF back to local storage
// -----------------------------------------------------------------------------
$downloadRequest = new DownloadFileRequest($targetPdfFile);
$response = $storageApi->downloadFile($downloadRequest);
$localPdfPath = __DIR__ . '/output.pdf';
file_put_contents($localPdfPath, $response->getContent());
// -----------------------------------------------------------------------------
// Clean‑up: optionally delete files from cloud storage
// -----------------------------------------------------------------------------
$storageApi->deleteFile(new \Aspose\ThreeD\Model\DeleteFileRequest($source3DFile));
$storageApi->deleteFile(new \Aspose\ThreeD\Model\DeleteFileRequest($targetPdfFile));
echo "3D to PDF conversion completed. PDF saved to: {$localPdfPath}\n";
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Convert 3D Models Using cURL and the REST API
If you prefer to work directly with the REST endpoints, the following cURL commands achieve the same result.
-
Authenticate and Get Access Token
Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your credentials.curl -X POST "https://api.aspose.cloud/connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"The response contains an
access_tokenused in subsequent calls. -
Upload the Source OBJ File
curl -X PUT "https://api.aspose.cloud/v3.0/3d/storage/file/sample.obj" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -T "sample.obj" -
Execute the Conversion
curl -X POST "https://api.aspose.cloud/v3.0/3d/convert/sample.obj?format=pdf&outPath=sample.pdf" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -
Download the Output PDF
curl -X GET "https://api.aspose.cloud/v3.0/3d/storage/file/sample.pdf" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -o "output.pdf"
For a complete list of parameters and error handling, see the API reference.
Conversion Options: Settings and Tweaks
The SDK exposes several properties you can adjust before calling convert3D:
- Output Format - The third argument of
Convert3DRequestdefines the target format (pdfin this tutorial). Change it topngorjpegfor image output. - Host URL - If you use a regional Aspose Cloud endpoint, modify
$config->setHost('https://api-eu.aspose.cloud');. - Timeouts - Both
StorageApiandThreeDApiaccept optional HTTP client configurations where you can set request timeouts for large files.
These options let you tailor the conversion process to your performance and compliance requirements. For a full list, refer to the API reference.
Conclusion
You have now mastered 3D to PDF conversion in PHP using the Aspose.Email Cloud SDK for PHP. The guide covered everything from environment setup to a complete, production‑ready script and a cURL alternative. Remember that the SDK is a commercial product; you can review pricing details on the product page and obtain a temporary license for evaluation at the temporary license page. Integrate this workflow into your own applications to provide seamless 3D document handling for your users.
FAQs
-
What is the easiest way to perform 3D to PDF conversion in PHP?
Using the Aspose.Email Cloud SDK for PHP is the most straightforward method. The library abstracts the REST calls and lets you convert 3D models to PDF with just a few lines of code. -
Can I convert other 3D formats besides OBJ with this library?
Yes, the SDK supports STL, FBX, 3DS and other common 3D formats. Simply change the source file name and the SDK will handle the conversion to PDF. -
How do I handle large 3D files during conversion?
Upload the file to Aspose Cloud storage first, then trigger the conversion. This keeps memory usage low on your server. For very large files consider splitting them or using the asynchronous conversion API. -
Is there a way to customize the PDF output, such as page size or orientation?
The conversion API lets you specify additional parameters in the request body. Refer to the API reference for the full list of supported options.