Created
March 30, 2025 03:28
Convert SVG into PDF using Java REST API. https://kb.aspose.cloud/pdf/java/convert-svg-into-pdf-using-java-rest-api/
This file contains 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.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