Hi Team, I am trying to convert from pptx file to pdf and it fails during conversion with this error
eption: class com.groupdocs.conversion.exceptions.CorruptOrDamagedFileException: Cannot convert. The file is corrupt or damaged. {ex.Message} —> java.lang.RuntimeException: com.groupdocs.conversion.legacy.exceptions.GroupDocsException: com.groupdocs.conversion.internal.c.a.w.UnsupportedFileFormatException: Unsupported file format: Unknown
— End of inner exception stack trace —
com.groupdocs.conversion.documents.k.cA(Unknown Source)
com.groupdocs.conversion.documents.k.cz(Unknown Source)
com.groupdocs.conversion.documents.ad.getPagesCount(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation.pageNumber(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation.pageLimitWordProcessing(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation.access$400(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation$3.a(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation.limitDocumentPages(Unknown Source)
com.groupdocs.conversion.converting.operations.PagesLimitOperation.execute(Unknown Source)
com.groupdocs.conversion.pipeline.f$1$1.a(Unknown Source)
com.groupdocs.conversion.converting.operations.RemoveCommentsOperation.execute(Unknown Source)
com.groupdocs.conversion.pipeline.f$1$1.a(Unknown Source)
com.groupdocs.conversion.converting.operations.PreProcessWordProcessingDocumentOperation.execute(Unknown Source)
com.groupdocs.conversion.pipeline.f$1$1.a(Unknown Source)
com.groupdocs.conversion.pipeline.e.execute(Unknown Source)
com.groupdocs.conversion.pipeline.h.a(Unknown Source)
com.groupdocs.conversion.pipeline.h.a(Unknown Source)
com.groupdocs.conversion.b.convert(Unknown Source)
com.groupdocs.conversion.Converter.convert(Unknown Source)
com.groupdocs.conversion.Converter.convert(Unknown Source)
package com.example;
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.ConverterSettings;
import com.groupdocs.conversion.contracts.ConverterSettingsProvider;
import com.groupdocs.conversion.contracts.documentinfo.IDocumentInfo;
import com.groupdocs.conversion.internal.c.a.w.FolderFontSource;
import com.groupdocs.conversion.internal.c.a.w.FontSourceBase;
import com.groupdocs.conversion.internal.c.a.w.SystemFontSource;
import com.groupdocs.conversion.internal.c.a.w.FontSettings;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.convert.PdfDocumentInfo;
import com.groupdocs.conversion.options.convert.PdfOptions;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import static jdk.xml.internal.SecuritySupport.getClassLoader;
public class Main {
public static void main(String[] args) {
System.out.println("Hi");
String filePath = "templateGDocs.pptx"; // Replace with your file path
String outputFilePath = "output.pdf";
try {
// Create a File object
File file = new File(filePath);
// Open an InputStream for the file
try (InputStream inputStream = Main.class.getClassLoader().getResourceAsStream(filePath)) {
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
// Below is required for adding Tags in the output PDF documnet
loadOptions.setPreserveDocumentStructure(true);
try (Converter converter = new Converter(() -> inputStream, () -> loadOptions)) {
try (ByteArrayOutputStream ms = new ByteArrayOutputStream()) {
PdfConvertOptions convertOptions = new PdfConvertOptions();
PdfOptions pdfOptions = convertOptions.getPdfOptions();
pdfOptions.getFormattingOptions().setDisplayDocTitle(true);
PdfDocumentInfo pdfDocumentInfo = pdfOptions.getDocumentInfo();
pdfDocumentInfo.setTitle("Test");
converter.convert(() -> ms, convertOptions);
byte[] outputPdfBytes = ms.toByteArray();
System.out.println("Generated PDF content size in bytes: " + outputPdfBytes.length);
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFilePath)) {
fileOutputStream.write(outputPdfBytes);
System.out.println("File created successfully!");
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
System.out.println(e.getMessage());
throw e;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}```