Created
March 23, 2025 22:03
Convert TEX to PDF with Java REST API. https://kb.aspose.cloud/pdf/java/convert-tex-to-pdf-with-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.Api.PdfApi; | |
import com.aspose.pdf.cloud.sdk.Model.UploadFileResponse; | |
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 convertTexToPdf() throws IOException { | |
// Initialize API with credentials | |
PdfApi pdfApi = new PdfApi("secret", "ID"); | |
String documentName = "Sample.tex"; | |
// Upload the TeX file | |
try (FileInputStream fileInputStream = new FileInputStream(new File(documentName))) { | |
UploadFileResponse uploadResult = pdfApi.uploadFile(documentName, fileInputStream); | |
} | |
// Convert TeX to PDF | |
FileResponse response = pdfApi.getTeXInStorageToPdf(documentName); | |
// Save the output PDF | |
try (FileOutputStream fileOutputStream = new FileOutputStream(new File("output.pdf"))) { | |
response.getFileStream().transferTo(fileOutputStream); | |
} | |
} | |
public static void main(String[] args) { | |
try { | |
convertTexToPdf(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment