Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions SlideExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public static void usage() {
System.out.println("Usage: slideextractor <filename> <output_image_format>");
}

public static void main (String[] args) throws FileNotFoundException, IOException, IllegalArgumentException {
if (args.length == 0) {
public static void main(String[] args) throws FileNotFoundException, IOException, IllegalArgumentException {
if (args.length == 0) {
usage();
return;
}

System.out.println(args[0]);
System.out.println("User Working Dir: " + System.getProperty("user.dir"));
String classpath = System.getProperty("java.class.path");
Expand All @@ -37,27 +37,28 @@ public static void main (String[] args) throws FileNotFoundException, IOExceptio
Dimension pgsize = pptx.getPageSize();

int idx = 1;
String output_image_format = "png";
if (args.length == 2) {
output_image_format = args[1].toLowerCase();
}

if (!output_image_format.equals("png") && !output_image_format.equals("jpeg") && !output_image_format.equals("gif")) {
String output_image_format = "jpeg";
if (args.length == 2) {
output_image_format = args[1].toLowerCase();
}

if (!output_image_format.equals("png") && !output_image_format.equals("jpeg")
&& !output_image_format.equals("gif")) {
throw new IllegalArgumentException("Invalid output format" + output_image_format);
}

for (XSLFSlide slide : pptx.getSlides()) {
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();

// clear the drawing area
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Double(0, 0, pgsize.width, pgsize.height));
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Double(0, 0, pgsize.width, pgsize.height));

//render
// render
slide.draw(graphics);
//save the output

// save the output
FileOutputStream out = new FileOutputStream("slide-" + idx + "." + output_image_format);
javax.imageio.ImageIO.write(img, output_image_format, out);
out.close();
Expand All @@ -67,5 +68,5 @@ public static void main (String[] args) throws FileNotFoundException, IOExceptio

is.close();
return;
}
}
}