Split PDF document using Aspose.Words REST API throws unable to cast object of type '\u0006 ' to type '\u0005

Hello, Has anyone seen this error message before. I am receiving this in my response when trying to split a pdf. appreciate any help.

" Unable to cast object of type '\u0006​ ’ to type '\u0005 "

Thanks

@cgsanc01

It looks like some document specific issue as API is working fine with a sample document. You may share your document with us, we will investigate the issue and will suggest you accordingly.

Hi Tilala, I replied to your email and attached the PDF as I did not see a way to attach my PDF here. Please let me know if I should send to you another way. I’ve been testing the PDF I sent to you that throws the mentioned error. However, if I add just one new pdf page to the existing PDF and then perform the same steps on that I dont get the error and it works. Very odd, have you seen that before?

@cgsanc01

You can share the PDF via text editor of the forum or via some free file sharing service like dropbox, google drive etc. However, if your document is confidential and you do not want to share it publicly then you share it via a private message by clicking on my user and using the message option.

Seems there is some structural issue that fixes silently after adding a new page. Anyhow, we will investigate it once we receive your problematic document.

Original MSA PDF.pdf (1.9 MB)

I attached via the upload button. let me know if you need anything else.

1 Like

@cgsanc01

I have tested the scenario using the following cURL command and unable to notice any issue. Please share your sample code, so we will investigate it further.split.pdf (1).zip (3.3 MB)

curl -X PUT "https://api.aspose.cloud/v4.0/words/Original%20MSA%20PDF.pdf/split?format=pdf&folder=Temp&destFileName=split.pdf&zipOutput=true" 
-H "accept: application/json" 
-H "Authorization: Bearer [JWT_Access_Token]" 

Edit: If you are using some old API Version then please use the latest API Version V4.0.

The code is contained in a large Salesforce apex classes. Do you want me to post the split the entire class?

@cgsanc01

I am afraid we do not need your apex classes. You may update your code to use API Version V4.0.

Kindly use the base URI https://api.aspose.cloud/v4.0 for the API version V4.0 instead of the old API Version. The latest API Version uses JSON Web Token(JWT) to authenticate the API requests. Please check the sample code to get the JWT Access token you may use it accordingly. And update Split API code if required as per the cURL command shared above.

public static string GetJWT(String client_id, String client_secret){
        String grant_type = 'client_credentials';
    
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://api.aspose.cloud/connect/token');
        request.setMethod('GET');                
        request.setHeader('Content-Type', 'application/x-www-form-urlencoded');              
        request.setHeader('Accept', 'application/json');
        
        String body = 'grant_type=' + grant_type + '&client_id=' + client_id + '&client_secret='+ client_secret ;
        request.setBody(body);
        
        Http http = new Http();
        HttpResponse res = http.send(request);
        String jsonInput = res.getBody();
        Map<String, Object> a =(Map<String, Object>)JSON.deserializeUntyped(jsonInput);
        system.debug('JWT Token is: '+a.get('access_token'));
        
        return a.get('access_token').ToString();
    }

Hello, When I use the new URI, it tells me authentication fails. does this url look correct? I am using GetJWT to get the access token.

image.png (2.4 KB)

@cgsanc01

We are looking into the issue and will update you shortly.

@cgsanc01

Please note if you are using Aspose.PDF Cloud to split the PDF document you can need to use v3.0 instead of v4.0. Aspose.Words Cloud is using the v4.0 API version. Hopefully, it will resolve the issue.