Free Support Forum - aspose.com

com.aspose.words.FileCorruptedException when specifying a password Aspose.Words for Java 10.4.0

Hello,

I am doing some basic testing with Aspose Words for Java to open a protected (read-only) document. I have created a fresh docx
file a set the protection to read-only with the password '123'. When opening the document with the password specfied via the
understanding junit test case, the following exception is thrown, when specifying no Loadoptions in the 'new Document' constructor,
the call succeeds.


Environment:

Aspose.Words for Java 10.4.0 (Aspose.Words.jdk16.jar)
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
Eclipse 3.5.1
JUnit 4.4

If needed i can send you the complete maven project

Regards Rob Sessink

-------- code snippit --------

package com.tenbrinke.docworks;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

import com.aspose.words.Document;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.ProtectionType;

public class DocumentSectionProtectionTest extends TestCase {

private Document doc;

private LoadOptions options;

@Before
public void setUp() throws Exception {
options = new LoadOptions("123");
options.setLoadFormat(LoadFormat.DOCX);
}

@Test
public void testOpenProtectedDocument() throws Exception {
doc = new Document("src/test/resources/templates/test_protection.docx",
options);
assertEquals(ProtectionType.READ_ONLY, doc.getProtectionType());
}

}
-------- code snippit --------

-------- stacktrace --------

com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.FileFormatUtil.a(FileFormatUtil.java:130)
at com.aspose.words.Document.b(Document.java:1283)
at com.aspose.words.Document.a(Document.java:1152)
at com.aspose.words.Document.(Document.java:149)
at org.tenbrinke.docworks.builder.aspose.DocumentSectionProtectionTest.testOpenProtecedDocument(DocumentSectionProtectionTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at com.aspose.words.ea.(DataSpaces.java:34)
at com.aspose.words.Document.b(Document.java:1237)
... 22 more

Hello

Thanks for your request. Could you please attach the document you are getting problem with? I will investigate the problem on my side and provide you more information.

Best regards,

Hello,

Please see the attached document.

Regards Rob

Hello

Thank you for additional information. Your document is not encrypted it is just protected. If the document is not encrypted, set LoadingOptions Password to null or empty string.

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/loadoptions.html#Password

In your case should use the following code to unprotect your document:

Document doc = new Document("C:\\Temp\\test_protection.docx");

doc.unprotect();

doc.save("C:\\Temp\\out.docx", SaveFormat.DOCX);

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/document.html#unprotect()

Best regards,

Thank you for your response, i mixed up the concepts of protection and encryption, everythings works correct now.

Regards Rob

Hi

Please let me know in case of any issue, I will be glad to help you.

Best regards,