PDF to DOCX conversion produces "Invalid parameter used."

I’m trying to convert a bunch of PDF files to DOCX using Aspose PDF JAVA.

Even though the files are fairly similar (not to say they are identical) some of them fail with the following error:

Invalid parameter used.

Is there any way or set of parameters that guarantee the conversion from PDF to DOCX?

@amahta

When converting PDF files to DOCX format using Aspose.PDF for Java, encountering the error “Invalid parameter used” can be frustrating. This error may arise due to various reasons, including issues with the PDF file structure or unsupported features within the PDF.

To improve the chances of successful conversion, consider the following steps:

  1. Check PDF File Integrity: Ensure that the PDF files you are trying to convert are not corrupted. You can open them in a PDF viewer to verify their integrity.

  2. Use Load Options: Utilize the PdfLoadOptions class to specify how the PDF should be loaded. This can help in managing specific parameters that might be causing the error. For example, you can set the page range or handle password-protected documents.

    Here’s a simple code snippet demonstrating how to use PdfLoadOptions:

    import com.aspose.pdf.Document;
    import com.aspose.pdf.PdfLoadOptions;
    
    public class PdfToDocxConverter {
        public static void main(String[] args) {
            // Load PDF with options
            PdfLoadOptions loadOptions = new PdfLoadOptions();
            loadOptions.setPassword("your_password"); // if the PDF is password protected
    
            Document pdfDocument = new Document("input.pdf", loadOptions);
            pdfDocument.save("output.docx");
        }
    }
    
  3. Error Handling: Implement robust error handling in your code to catch exceptions and log detailed error messages. This can help you identify the specific cause of the issue.

  4. Review Documentation: Check the official Aspose documentation for any specific requirements or limitations regarding the PDF files you are converting. This can provide insights into parameters that may need adjustment.

  5. Test with Different Files: If possible, try converting different PDF files to see if the issue is isolated to specific documents. This can help determine if the problem is with the files themselves or the conversion process.

By following these steps, you can enhance the reliability of your PDF to DOCX conversions and potentially avoid the “Invalid parameter used” error.

For more detailed guidance on converting PDFs to DOCX format, you can refer to the official Aspose documentation here and here.

Sources:
[1]: Change PDFs to DOC or DOCX Format | Aspose.PDF Java PDF Processing API
[2]: PDF Conversion & Transformation | Aspose.PDF Java PDF Processing API

There’s no such a thing as com.aspose.pdf.PdfLoadOptions

1 Like

@amahta

Can you please share your sample PDF with us that is producing this error? We will test the scenario in our environment and address it accordingly.

Can you provide a way to share it privately?

@amahta

We have sent you a private message where you can send your files in reply.

Thanks. Send you the samples now.

@amahta

Thanks for sharing samples. We are checking them and will get back to you shortly.

@amahta

We tested using 24.9 API version and the below code snippet in a console application. We were not able to replicate any exceptions in our environment.

// List all PDF files in the "pdfss" folder
File folder = new File(dataDir + "pdfss");
File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".pdf"));

if (files != null) {
    for (File file : files) {
        // Load the PDF document
        Document pdfDocument = new Document(file.getAbsolutePath());

        // Set save options for converting to DOCX
        DocSaveOptions saveOptions = new DocSaveOptions();
        saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);
        saveOptions.setMode(DocSaveOptions.RecognitionMode.EnhancedFlow);

        // Save the document as DOCX
        String outputFileName = dataDir + "pdfss/" + file.getName().replace(".pdf", "") + "output.docx";
        pdfDocument.save(outputFileName, saveOptions);
    }
}

Can you please try using the latest version and let us know if you still notice any issues?

Can you please confirm the OS you are testing with?
I am using Linux.
Ubuntu 22.04 to be precise.

Also, I am testing on version 24.1, and 23.X.
When I try using 24.9 I get the following dependency issues.

[ERROR] dependency: com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 (compile)
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://git.core.objective.com/api/v4/groups/237/-/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of gitlab-maven has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://git.core.objective.com/api/v4/projects/1351/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of cs-releases has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/release during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/external during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.external has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://repository.jboss.org/nexus/content/groups/public-jboss/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://repo1.maven.org/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://maven.alfresco.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven.alfresco.com has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://packages.atlassian.com/mvn/maven-atlassian-external/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of atlassian-external-public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://maven.restlet.talend.com/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-restlet has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://packages.nuxeo.com/repository/maven-public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nuxeo.public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in https://releases.aspose.com/java/repo during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of AsposeJavaAPI has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:mscorlib:jar:23.11 was not found in file://${basedir}/misc/lib during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of aspose-repository has elapsed or updates are forced
[ERROR] dependency: com.aspose.ms.jdk.NetFramework:System:jar:23.11 (compile)
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://git.core.objective.com/api/v4/groups/237/-/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of gitlab-maven has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://git.core.objective.com/api/v4/projects/1351/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of cs-releases has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/release during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/external during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.external has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://repository.jboss.org/nexus/content/groups/public-jboss/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://repo1.maven.org/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://maven.alfresco.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven.alfresco.com has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://packages.atlassian.com/mvn/maven-atlassian-external/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of atlassian-external-public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://maven.restlet.talend.com/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-restlet has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://packages.nuxeo.com/repository/maven-public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nuxeo.public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in https://releases.aspose.com/java/repo during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of AsposeJavaAPI has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System:jar:23.11 was not found in file://${basedir}/misc/lib during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of aspose-repository has elapsed or updates are forced
[ERROR] dependency: com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 (compile)
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://git.core.objective.com/api/v4/groups/237/-/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of gitlab-maven has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://git.core.objective.com/api/v4/projects/1351/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of cs-releases has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/release during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/external during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.external has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://repository.jboss.org/nexus/content/groups/public-jboss/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://repo1.maven.org/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://maven.alfresco.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven.alfresco.com has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://packages.atlassian.com/mvn/maven-atlassian-external/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of atlassian-external-public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://maven.restlet.talend.com/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-restlet has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://packages.nuxeo.com/repository/maven-public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nuxeo.public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in https://releases.aspose.com/java/repo during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of AsposeJavaAPI has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Xml:jar:23.11 was not found in file://${basedir}/misc/lib during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of aspose-repository has elapsed or updates are forced
[ERROR] dependency: com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 (compile)
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://git.core.objective.com/api/v4/groups/237/-/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of gitlab-maven has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://git.core.objective.com/api/v4/projects/1351/packages/maven during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of cs-releases has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/release during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.release has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://repository.springsource.com/maven/bundles/external during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of com.springsource.repository.bundles.external has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://repository.jboss.org/nexus/content/groups/public-jboss/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://repo1.maven.org/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://maven.alfresco.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven.alfresco.com has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://packages.atlassian.com/mvn/maven-atlassian-external/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of atlassian-external-public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://maven.restlet.talend.com/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-restlet has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://packages.nuxeo.com/repository/maven-public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nuxeo.public has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in https://releases.aspose.com/java/repo during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of AsposeJavaAPI has elapsed or updates are forced
[ERROR]         com.aspose.ms.jdk.NetFramework:System.Net:jar:23.11 was not found in file://${basedir}/misc/lib during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of aspose-repository has elapsed or updates are forced
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 

Oh by the way, when I try your code with versions prior to 24.9 (in my case 24.1) I get this error for some files:

com.simflofy.utils.aspose.exceptions.AsposeConversionException: class com.aspose.pdf.internal.l20y.l46u cannot be cast to class com.aspose.pdf.internal.l20y.l36v (com.aspose.pdf.internal.l20y.l46u and com.aspose.pdf.internal.l20y.l36v are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @1e7ab390)

@amahta

Looks like there are dependency errors. Can you please clear your maven cache and make sure that repository URLs are correct and working? BTW, we tested in Windows Environment.

Hi did you find solution of your problem ? I also have something like this.

@Armen23023

Can you please make sure that you are using the latest version of the API and if issue is still occurring, please share some details and steps to reproduce it in our environment. We will further proceed accordingly.