Skip to content

Instantly share code, notes, and snippets.

import com.aspose.pdf.cloud.sdk.ApiException;
import com.aspose.pdf.cloud.sdk.Configuration;
import com.aspose.pdf.cloud.sdk.api.PdfApi;
import com.aspose.pdf.cloud.sdk.model.FileResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PdfTasks {
public static void convertSvgToPdf() {
// Initialize API with credentials
String appKey = "key";
String appSid = "id";
// Set configuration
Configuration configuration = new Configuration(appSid, appKey);
PdfApi pdfApi = new PdfApi(configuration);
String documentName = "sample.svg";
try {
// Upload the SVG file
FileInputStream fileStream = new FileInputStream(new File(documentName));
pdfApi.uploadFile(documentName, fileStream);
// Convert SVG to PDF
FileResponse response = pdfApi.getSvgInStorageToPdf(documentName);
// Save the converted PDF to local storage
FileOutputStream fileOutputStream = new FileOutputStream("output.pdf");
response.getFileContent().writeTo(fileOutputStream);
fileOutputStream.close();
System.out.println("SVG converted to PDF successfully!");
} catch (IOException | ApiException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
convertSvgToPdf();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment