Problem with accessing PdfEncryptionDetails class

I’m using the php javabridge which is provided in the documentation to write a php application which generates a protected pdf file.
Here is the code I have to set the protection (where $ptype=‘PRINTING’):

$pdfpermissions = Java(“com.aspose.words.PdfPermissions”);
$pdfencryptiondetails = Java(“com.aspose.words.PdfEncryptionDetails”);
$permission = $pdfpermissions->{$ptype};
$pdfencryptiondetails->setPermissions($permission);
$saveoptions->setEncryptionDetails($pdfencryptiondetails);

But I get an error on the 4th line in this piece of code.
This is the error I get:

Fatal error: Uncaught [[o:Exception]:“java.lang.Exception: Invoke failed: [[c:PdfEncryptionDetails]]->setPermissions([o:Integer]). Cause: php.java.bridge.NoSuchProcedureException: static setPermissions([o:Integer]). Candidates: [] VM: 1.8.0_40@<http://java.oracle.com>/” at: #-6 php.java.bridge.JavaBridge.checkM(JavaBridge.java:1084) #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1024) #-4 php.java.bridge.Request.handleRequest(Request.java:417) #-3 php.java.bridge.Request.handleRequests(Request.java:500) #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0 /opt/tbg/apache-tomcat-7.0.42/webapps/X-PAA/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(730, ‘java.lang.Integ…’, ‘T’, true) #1 /opt/tbg/apache-tomcat-7.0.42/webapps/X-PAA/java/Java.inc(360): java_Arg->getResult(true) #2 /opt/tbg/apache-tomcat-7.0.42/webapps/X-PAA/java/Java.inc(366): java_Client->getWrappedResult(true) #3 /opt/tbg/apache-tomcat-7.0.42/webapps/X-PAA/ja in /opt/tbg/apache-tomcat-7.0.42/webapps/X-PAA/java/Java.inc on line 195

I find this very odd because when I do a java_inspect of $pdfencrypitiondetails I get this:

[class com.aspose.words.PdfEncryptionDetails: Constructors: public com.aspose.words.PdfEncryptionDetails(java.lang.String,java.lang.String,int) Fields: Methods: public void com.aspose.words.PdfEncryptionDetails.setPermissions(int) public int com.aspose.words.PdfEncryptionDetails.getEncryptionAlgorithm() public java.lang.String com.aspose.words.PdfEncryptionDetails.getOwnerPassword() public java.lang.String com.aspose.words.PdfEncryptionDetails.getUserPassword() public void com.aspose.words.PdfEncryptionDetails.setEncryptionAlgorithm(int) public void com.aspose.words.PdfEncryptionDetails.setOwnerPassword(java.lang.String) public void com.aspose.words.PdfEncryptionDetails.setUserPassword(java.lang.String) public int com.aspose.words.PdfEncryptionDetails.getPermissions() public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public java.lang.String java.lang.Object.toString() public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll() public static java.lang.Class java.lang.Class.forName(java.lang.String) throws java.lang.ClassNotFoundException public static java.lang.Class java.lang.Class.forName(java.lang.String,boolean,java.lang.ClassLoader) throws java.lang.ClassNotFoundException public java.lang.String java.lang.Class.toString() public java.security.ProtectionDomain java.lang.Class.getProtectionDomain() public native boolean java.lang.Class.isAssignableFrom(java.lang.Class) public native boolean java.lang.Class.isInstance(java.lang.Object) public native int java.lang.Class.getModifiers() public native boolean java.lang.Class.isInterface() public native boolean java.lang.Class.isArray() public native boolean java.lang.Class.isPrimitive() public native java.lang.Class java.lang.Class.getSuperclass() public native java.lang.Class java.lang.Class.getComponentType() public java.lang.String java.lang.Class.getName() public java.lang.String java.lang.Class.toGenericString() public java.lang.Object java.lang.Class.newInstance() throws java.lang.InstantiationException,java.lang.IllegalAccessException public boolean java.lang.Class.isAnnotation() public boolean java.lang.Class.isSynthetic() public java.lang.ClassLoader java.lang.Class.getClassLoader() public java.lang.reflect.TypeVariable[] java.lang.Class.getTypeParameters() public java.lang.reflect.Type java.lang.Class.getGenericSuperclass() public java.lang.Package java.lang.Class.getPackage() public java.lang.Class[] java.lang.Class.getInterfaces() public java.lang.reflect.Type[] java.lang.Class.getGenericInterfaces() public native java.lang.Object[] java.lang.Class.getSigners() public java.lang.reflect.Method java.lang.Class.getEnclosingMethod() throws java.lang.SecurityException public java.lang.reflect.Constructor java.lang.Class.getEnclosingConstructor() throws java.lang.SecurityException public java.lang.Class java.lang.Class.getDeclaringClass() throws java.lang.SecurityException public java.lang.Class java.lang.Class.getEnclosingClass() throws java.lang.SecurityException public java.lang.String java.lang.Class.getSimpleName() public java.lang.String java.lang.Class.getTypeName() public java.lang.String java.lang.Class.getCanonicalName() public boolean java.lang.Class.isAnonymousClass() public boolean java.lang.Class.isLocalClass() public boolean java.lang.Class.isMemberClass() public java.lang.Class[] java.lang.Class.getClasses() public java.lang.reflect.Field[] java.lang.Class.getFields() throws java.lang.SecurityException public java.lang.reflect.Method[] java.lang.Class.getMethods() throws java.lang.SecurityException public java.lang.reflect.Constructor[] java.lang.Class.getConstructors() throws java.lang.SecurityException public java.lang.reflect.Field java.lang.Class.getField(java.lang.String) throws java.lang.NoSuchFieldException,java.lang.SecurityException public java.lang.reflect.Method java.lang.Class.getMethod(java.lang.String,java.lang.Class[]) throws java.lang.NoSuchMethodException,java.lang.SecurityException public java.lang.reflect.Constructor java.lang.Class.getConstructor(java.lang.Class[]) throws java.lang.NoSuchMethodException,java.lang.SecurityException public java.lang.Class[] java.lang.Class.getDeclaredClasses() throws java.lang.SecurityException public java.lang.reflect.Field[] java.lang.Class.getDeclaredFields() throws java.lang.SecurityException public java.lang.reflect.Method[] java.lang.Class.getDeclaredMethods() throws java.lang.SecurityException public java.lang.reflect.Constructor[] java.lang.Class.getDeclaredConstructors() throws java.lang.SecurityException public java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String) throws java.lang.NoSuchFieldException,java.lang.SecurityException public java.lang.reflect.Method java.lang.Class.getDeclaredMethod(java.lang.String,java.lang.Class[]) throws java.lang.NoSuchMethodException,java.lang.SecurityException public java.lang.reflect.Constructor java.lang.Class.getDeclaredConstructor(java.lang.Class[]) throws java.lang.NoSuchMethodException,java.lang.SecurityException public java.io.InputStream java.lang.Class.getResourceAsStream(java.lang.String) public java.net.URL java.lang.Class.getResource(java.lang.String) public boolean java.lang.Class.desiredAssertionStatus() public boolean java.lang.Class.isEnum() public java.lang.Object[] java.lang.Class.getEnumConstants() public java.lang.Object java.lang.Class.cast(java.lang.Object) public java.lang.Class java.lang.Class.asSubclass(java.lang.Class) public java.lang.annotation.Annotation java.lang.Class.getAnnotation(java.lang.Class) public boolean java.lang.Class.isAnnotationPresent(java.lang.Class) public java.lang.annotation.Annotation[] java.lang.Class.getAnnotationsByType(java.lang.Class) public java.lang.annotation.Annotation[] java.lang.Class.getAnnotations() public java.lang.annotation.Annotation java.lang.Class.getDeclaredAnnotation(java.lang.Class) public java.lang.annotation.Annotation[] java.lang.Class.getDeclaredAnnotationsByType(java.lang.Class) public java.lang.annotation.Annotation[] java.lang.Class.getDeclaredAnnotations() public java.lang.reflect.AnnotatedType java.lang.Class.getAnnotatedSuperclass() public java.lang.reflect.AnnotatedType[] java.lang.Class.getAnnotatedInterfaces() public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll() Classes: ]

which does show the methode listed. I’ve tried to call other methodes from this class but with getEncryptionAlgorithm() and getPermissions() I get the same problem. I haven’t tried it with other methodes.

I’ve tried this with aspose words for java 16.6.0 and an older version and both have the problem.

I don’t think this is in the javabridge because I’m using this for many calls to both aspose and other API’s and none of the other methose calls fails.

Could you tell me what is going on here or if this is a bug?

Hi there,

Thanks for your inquiry. Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Included is a document which is generated by the same system but as a docx file. When trying to save this as described above the program fails as described above.

It now says evalution copy because I was testing it with the newest version and our new licence isn’t applied yet to this one, but this shouldn’t make a difference as far as I know.

Hi there,

Thanks for your inquiry. Please note that in evaluation mode there are some limitations applied. E.g. Aspose.Words injects an evaluation watermark at the top of the document. The document’s content are truncated after a certain number of paragraphs during import or export.

Please request for 30-days temporary license from here:
Get temporary license

We have tested the scenario using latest version of Aspose.Words for Java 16.7.0 with following code example and have not found the shared issue. Please use Aspose.Words for Java 16.7.0.

If you are not using ‘TEST_BEDRIJF_999_MIGRATIE_2-160809-aaaaaa.docx’ as input document, please share your input document along with complete Java code here for testing. We will investigate the issue on our side and provide you more information.

Document doc = new Document(MyDir + "TEST_BEDRIJF_999_MIGRATIE_2-160809-aaaaaa.docx");

PdfSaveOptions saveOptions = new PdfSaveOptions();
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("", "password", PdfEncryptionAlgorithm.RC_4_128);

encryptionDetails.setPermissions(PdfPermissions.PRINTING);
saveOptions.setEncryptionDetails(encryptionDetails);

doc.save(MyDir + "Out v16.7.0.pdf", saveOptions);

Hello,

Thanks for your reply. I tried it with the latest version but I still have the same problem.
Like I said before I’m using the PHP/Javabridge to program this in php in tomcat.

I’ve included a simple php script what does what you do in your post.
When set in the php javabridge this will result in the error:

HTTP Status 500 - java.lang.RuntimeException: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:PdfEncryptionDetails]]->setPermissions([o:Integer]). Cause: php.java.bridge.NoSuchProcedureException: static setPermissions([o:Integer]). Candidates: [] VM: 1.8.0_40@<http://java.oracle.com/>" at:

I don’t have any problems calling other methodes. Only the ones from PdfEncryptionDetails I can’t seem to call…

if you comment out line 17 and 18 you’ll see the script does run and it does show pdfencryptiondetails is loaded right because the javabridge does show the functions which are aviable.
It also show “public void com.aspose.words.PdfEncryptionDetails.setPermissions(int)” so thats why I don’t understand what is going wrong here…

Hi there,

Thanks for sharing the detail. We are working over your query and will update you soon.

Hi there,

Thanks for your patience. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-1428. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi

As far as I can see there is the setPermissions(int) method on the list which is good.

But JavaBridge says “php.java.bridge.NoSuchProcedureException: static setPermissions([o:Integer])

What if Unboxing doesn’t work in JavaBridge properly?

$permission = $pdfpermissions->PRINTING;

What type $permission will be?

Here I found a discussion on similar problem.

Could you please try to create java Integer/int manually?
Could you please try another method setEncryptionAlgorithm(int). Does the problem exist for this method too?

Thanks

I’ve tried other methods from this class and all (I tested) give the same problem. In other classes I don’t have this problem. Also I’ve used primitives like this in other instances in Aspose.Words and it does work.
For example this piece of code runs without problems:

$mimetype = ‘PDF’;
$saveformats = new Java("com.aspose.words.SaveFormat");
$saveoptions = new Java("com.aspose.words.PdfSaveOptions");
$saveoptions->setSaveFormat($saveformats->{$mimetype});

Try please PdfEncryptionDetails.setEncryptionAlgorithm(int).
PRINTING is 4 so could you call setPermissions(4) ?

I now did:

$permission = new Java("java.lang.Integer",4);
$pdfencryptiondetails->setEncryptionAlgorithm($permission);

which returns the same error:

HTTP Status 500 - java.lang.RuntimeException: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:PdfEncryptionDetails]]->setEncryptionAlgorithm([o:Integer]). Cause: php.java.bridge.NoSuchProcedureException: static setEncryptionAlgorithm([o:Integer]). Candidates: [] VM: 1.8.0_40@<http://java.oracle.com/>" at:

I also tried:

$int = new Java("java.lang.Integer",4);
$pdfencryptiondetails->setPermissions($int);

which also gave this error:

HTTP Status 500 - java.lang.RuntimeException: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:PdfEncryptionDetails]]->setPermissions([o:Integer]). Cause: php.java.bridge.NoSuchProcedureException: static setPermissions([o:Integer]). Candidates: [] VM: 1.8.0_40@<http://java.oracle.com/>" at:

If I used java_values($int) it will return 4.

Hi there,

Thanks for your feedback. We will inform you via this forum thread once this issue is resolved. Thanks for your patience and understanding.

Hi

Please use the “new” keyword while PdfEncryptionDetails creating

$pdfencryptiondetails = new Java("com.aspose.words.PdfEncryptionDetails","", "password", 1);

Please let us know if it helped.

Thanks

Also please have a look at following:

$saveFormat = Java("com.aspose.words.SaveFormat")->PDF; // no need to use the ‘new’ keyword
$permission = Java("com.aspose.words.PdfPermissions")->PRINTING; // also a constant

$paramAlg = new Java("java.lang.Integer", "1"); // a new instance

$saveoptions = new Java("com.aspose.words.PdfSaveOptions"); // a new instance
$saveoptions->setSaveFormat($saveFormat);

$pdfencryptiondetails = new Java("com.aspose.words.PdfEncryptionDetails","", "password", 1); // here we have to create a new instance
$pdfencryptiondetails->setPermissions($permission); // works fine
$pdfencryptiondetails->setEncryptionAlgorithm($paramAlg); 
$saveoptions->setEncryptionDetails($pdfencryptiondetails); 

hope this will help.

Thank you, it seems I have overlooked this somewhere. It is working now.

The issues you have found earlier (filed as WORDSJAVA-1428) have been fixed in this Aspose.Words for .NET 16.10.0 update and this Aspose.Words for Java 16.10.0 update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.