Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save blog-aspose-cloud/2647e2257d5d4382fb98b205e50d583f to your computer and use it in GitHub Desktop.

Select an option

Save blog-aspose-cloud/2647e2257d5d4382fb98b205e50d583f to your computer and use it in GitHub Desktop.
How to Perform DWT to PDF Conversion using Rest in Java
import com.aspose.cad.cloud.ApiException;
import com.aspose.cad.cloud.api.CadApi;
import com.aspose.cad.cloud.model.*;
import com.aspose.cad.cloud.Configuration;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class DwtToPdfConverter {
public static void main(String[] args) {
// 1. Initialize API client
Configuration config = new Configuration();
config.setClientId("YOUR_CLIENT_ID");
config.setClientSecret("YOUR_CLIENT_SECRET");
config.setBaseUrl("https://api.aspose.cloud");
config.setDebug(true); // Enable logging for troubleshooting
CadApi cadApi = new CadApi(config);
// 2. Define input and output paths
String localDwtPath = "C:/cad-files/sample.dwt";
String remoteDwtPath = "sample.dwt";
String remotePdfPath = "sample.pdf";
try {
// 3. Upload DWT file to cloud storage
byte[] dwtBytes = Files.readAllBytes(Paths.get(localDwtPath));
cadApi.uploadFile(remoteDwtPath, dwtBytes);
// 4. Set conversion options (optional)
PdfExportOptions pdfOptions = new PdfExportOptions();
pdfOptions.setDpi(300); // High‑resolution output
pdfOptions.setCompress(true);
// 5. Perform conversion
cadApi.convertDocument(
new ConvertDocumentRequest(
remoteDwtPath,
"pdf",
pdfOptions,
null, // storage name (null = default)
null // folder (null = root)
)
);
// 6. Download the resulting PDF
byte[] pdfBytes = cadApi.downloadFile(remotePdfPath);
Files.write(Paths.get("C:/cad-files/sample_converted.pdf"), pdfBytes);
System.out.println("Conversion successful! PDF saved to sample_converted.pdf");
} catch (ApiException e) {
System.err.println("API error: " + e.getResponseBody());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment