Created
April 1, 2026 06:12
-
-
Save blog-aspose-cloud/8b11b12fe169e2656559cb3a30c4327f to your computer and use it in GitHub Desktop.
How to Perform DWT to PDF Conversion using REST in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.aspose.cad.cloud.ApiClient; | |
| import com.aspose.cad.cloud.ApiException; | |
| import com.aspose.cad.cloud.Configuration; | |
| import com.aspose.cad.cloud.api.CadApi; | |
| import com.aspose.cad.cloud.model.CadConversionOptions; | |
| import com.aspose.cad.cloud.model.FileInfo; | |
| import java.io.File; | |
| import java.io.FileOutputStream; | |
| import java.io.InputStream; | |
| public class DwtToPdfConverter { | |
| public static void main(String[] args) { | |
| // 1. Configure API client with temporary credentials | |
| ApiClient defaultClient = Configuration.getDefaultApiClient(); | |
| defaultClient.setBasePath("https://api.aspose.cloud"); | |
| defaultClient.setClientId("YOUR_CLIENT_ID"); | |
| defaultClient.setClientSecret("YOUR_CLIENT_SECRET"); | |
| CadApi cadApi = new CadApi(); | |
| try { | |
| // 2. Upload DWT file to cloud storage | |
| File dwtFile = new File("input.dwt"); | |
| FileInfo uploadedFile = cadApi.uploadFile("input.dwt", dwtFile); | |
| // 3. Set conversion options (optional) | |
| CadConversionOptions options = new CadConversionOptions(); | |
| options.setDpi(300); | |
| options.setPageWidth(2100); // A4 width in points | |
| options.setPageHeight(2970); // A4 height in points | |
| // 4. Convert to PDF | |
| FileInfo result = cadApi.convertDocument( | |
| uploadedFile.getPath(), | |
| "PDF", | |
| options | |
| ); | |
| // 5. Download the resulting PDF | |
| InputStream pdfStream = cadApi.downloadFile(result.getPath()); | |
| try (FileOutputStream fos = new FileOutputStream("output.pdf")) { | |
| byte[] buffer = new byte[8192]; | |
| int bytesRead; | |
| while ((bytesRead = pdfStream.read(buffer)) != -1) { | |
| fos.write(buffer, 0, bytesRead); | |
| } | |
| } | |
| System.out.println("Conversion successful. PDF saved as output.pdf"); | |
| } catch (ApiException e) { | |
| System.err.println("API error: " + e.getMessage()); | |
| } catch (Exception ex) { | |
| ex.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment