PPtx to Pdf conversion throws error Unknow file type conversion error

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);
        }
    }
}```

@saravanaprabhusr

The error you are encountering during the conversion of a PPTX file to PDF indicates that the file may be corrupt or damaged. This can happen for several reasons, such as an incomplete download, file corruption during transfer, or issues with the file format itself.

Here are some steps you can take to troubleshoot and resolve this issue:

  1. Check the File Integrity: Ensure that the PPTX file you are trying to convert is not corrupt. You can do this by opening the file in Microsoft PowerPoint or any compatible application to verify that it displays correctly.

  2. Use a Different File: Try converting a different PPTX file that you know is working. This will help you determine if the issue is specific to the original file.

  3. Update GroupDocs.Conversion Library: Ensure that you are using the latest version of the GroupDocs.Conversion library. Sometimes, bugs are fixed in newer releases that could resolve your issue.

  4. Review Conversion Code: Make sure that your conversion code is correctly set up. Here’s a simplified example of how to convert a PPTX file to PDF using the GroupDocs.Conversion library:

    import com.groupdocs.conversion.Converter;
    import com.groupdocs.conversion.options.convert.PdfConvertOptions;
    
    public class Main {
        public static void main(String[] args) {
            String filePath = "path/to/your/file.pptx"; // Replace with your PPTX file path
            String outputFilePath = "output.pdf";
    
            try (Converter converter = new Converter(filePath)) {
                PdfConvertOptions options = new PdfConvertOptions();
                converter.convert(outputFilePath, options);
                System.out.println("Conversion completed successfully!");
            } catch (Exception e) {
                System.err.println("Error during conversion: " + e.getMessage());
            }
        }
    }
    
  5. Check for Unsupported Features: If your PPTX file contains features that are not supported by the conversion library, it may lead to errors. Simplifying the content of the PPTX file may help.

  6. Consult Documentation and Support: If the problem persists, refer to the official documentation for any specific requirements or limitations regarding PPTX to PDF conversion. You can also seek help from the community forums for additional support.

By following these steps, you should be able to identify the cause of the conversion error and take appropriate action to resolve it.

Sources:
[1]: Convert PPTX to PDF | GroupDocs.Conversion .NET API

I would need to return it as stream instead of creating a output.pdf file. Could you please help me with that. Like the above implementation worked for the docx file conversion. But not for pptx

@saravanaprabhusr
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CONVERSIONJAVA-2502

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.