Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/d08d4435c1f1021f21cc7aa4129a4de8 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/d08d4435c1f1021f21cc7aa4129a4de8 to your computer and use it in GitHub Desktop.
Convert PPTX to PDF with Aspose.Slides for Java
import com.aspose.slides.*;
import java.io.File;
public class PptxToPdfConverter {
public static void main(String[] args) {
// Load license (replace with your license file path)
try {
License license = new License();
license.setLicense("Aspose.Slides.Java.lic");
} catch (Exception e) {
System.out.println("License could not be loaded: " + e.getMessage());
}
// Input and output paths
String inputPath = "sample.pptx";
String outputPath = "sample.pdf";
// Create presentation object
try (Presentation pres = new Presentation(inputPath)) {
// Configure PDF export options
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setCompliance(PdfCompliance.PdfA1b); // PDF/A compliance
pdfOptions.setEmbedFullFonts(true); // Embed all fonts
pdfOptions.setJpegQuality(90); // High quality images
// Save as PDF
pres.save(outputPath, SaveFormat.Pdf, pdfOptions);
System.out.println("Conversion completed. PDF saved at " + outputPath);
} catch (Exception ex) {
System.err.println("Error during conversion: " + ex.getMessage());
}
// Simple verification
File pdfFile = new File(outputPath);
if (pdfFile.exists() && pdfFile.length() > 0) {
System.out.println("PDF file verified successfully.");
} else {
System.out.println("PDF file verification failed.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment