Mail Merge Word Document in Salesforce Showing Chinese characters as Boxes

@centris.aspose

I just checked, and it started working. Can you please check and confirm?

We are still getting storage error when loading the ’ * Aspose for Cloud Default Storage’ folder. Since all of our clients go to this folder, we believe that this has to be contributing to the font issues we see for Chinese clients. I am trying to clear out the folder but it is very tedious and time consuming to delete each folder manually. Is there any way to clear multiple folder by date?
Thank you.

CAnnot get files for selected storage 50123.PNG (37.5 KB)

@centris.aspose

Thanks for your feedback. We are looking into the server logs and will guide you accordingly.

@tilal.ahmad
As per these article (Performing Microsoft Word Mail Merge with Aspose.Words REST API overwrites template fields - #8 by tilal.ahmad).
In version 4 we have to use ‘MailMerge’ method instead of ‘ExecuteTemplate’ methods.
But when we used in AsposeService apex class to merge the document, Salesforce field are not pulled into merge pdf.

public String executeTemplateMerge(String FileName, String dataFile) {
try {
String strURI = Aspose.BaseProductUri + '/words/' + **FileName + '/MailMerge**?cleanup=ContainingFields,EmptyParagraphs,UnusedFields,UnusedRegions,RemoveTitleRow,RemoveTitleRowInInnerTables'; 

[Endpoint=https://api.aspose.cloud/v4.0/words/Invitation_new%20document.docx/MailMerge?cleanup=ContainingFields,EmptyParagraphs,UnusedFields,UnusedRegions,RemoveTitleRow,RemoveTitleRowInInnerTables&appSID=XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, Method=PUT]

Input Document:
Invitation_new document.docx (223.9 KB)
Output pdf:
image.png (183.0 KB)

Kindly guide us what we are missing.
Thanks in advance.

@centris.aspose

Please pay attention API V4.0 is using JSON Web Token(JWT) for request authentication as stated above, you do not need to sign the request. Please check this post for sample Apex code.

I am sorry that there are 2 conversations in this thread but we are still seeing the storage errors when loading the Aspose Cloud for Default folder. Can we do a mass cleanup? What is the value of the files that are in there? Some date back to 2015. Are new files being added every day?
Aspose Stotage Error 050423.PNG (94.6 KB)
We appreciate any assistance you provide.

@centris.aspose

We have double-checked the cloud storage, and it is working fine as expected. Please reset your browser’s cache and delete cookies as well. You can also try it in incognito mode.

Moreover, in reference to the storage cleanup query, you can delete old files manually or set the storage mode to retain files.

@tilal.ahmad
We need to convert document to pdf in salesforce using apex code. When we are trying to work with this build class it is not working.

public with sharing class AsposeServiceTest {
  public static string GetJWT(){
    Aspose_Credentials__c credential = Aspose_Credentials__c.getOrgDefaults();

    String grant_type = 'client_credentials';
    String client_id= credential.Aspose_App_Sid__c;
    String client_secret= credential.Aspose_App_Key__c;	
    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();
}

public static String ProcessCommand(String strURI, String strHttpCommand, String strContent, String ContentType, String accessToken) {
    try {
        HttpRequest request = new HttpRequest();
        Integer len = 0;
        if (strContent != null) {
            request.setBody(strContent);
            len = strContent.length();
        }
        system.debug('httpcommand: ' + strHttpCommand);
        request.setEndpoint(strURI);
        request.setMethod(strHttpCommand);
        
        if (ContentType.toLowerCase() == 'xml')
            request.setHeader('Content-Type', 'application/xml');
        else
            request.setHeader('Content-Type', 'application/json');
        request.setHeader('Content-Length', String.valueOf(len));
        request.setHeader('Accept', 'application/json');
        request.setHeader('Authorization', accessToken);
        request.setTimeout(120000);
        
        Http http = new Http();
        system.debug('request ' + request);
        HttpResponse res = http.send(request);
        system.debug('util response:' + res);
        return res.getBody();
        
    } catch (Exception ex) {
        system.debug('HTTP ERROR' + ex.getMessage());
        system.debug(ex.getStackTraceString());
        return null;
    }
}

public static String ExecuteMailMerege() {
    try {
        String FileName = 'TempleteCRT1349.docx';
        String outFormat = 'pdf';
        String strURl = 'https://api.aspose.cloud/v4.0' + '/words/' + FileName + '/MailMerge?destFileName=subham.docx';
        
        
        String jsonData = '{"dataSourceList":{"invitationDataSource":{"RSVPDueDate":"5/1/2023","registrationUrl":"centrisdevtso--v15crt.sandbox.my.salesforce-sites.com/Invitation/Register/INT-0054492","meetingUrl":null,"meetingDialIn":null,"intReservedShortTextMergeField9":null,"intReservedShortTextMergeField8":null,"intReservedShortTextMergeField7":null,"intReservedShortTextMergeField6":null,"intReservedShortTextMergeField5":null,"intReservedShortTextMergeField4":null,"intReservedShortTextMergeField3":null,"intReservedShortTextMergeField2":null,"intReservedShortTextMergeField10":null,"intReservedShortTextMergeField1":null,"intReservedLongTextMergeField5":null,"intReservedLongTextMergeField4":null,"intReservedLongTextMergeField3":null,"intReservedLongTextMergeField2":null,"intReservedLongTextMergeField1":null,"intReservedLongTextAreaMergeField3":null,"intReservedLongTextAreaMergeField2":null,"intReservedLongTextAreaMergeField1":null,"intReservedLongRichTextAreaMergeField1":null,"intReservedDateTimeField3":"","intReservedDateTimeField2":"","intReservedDateTimeField1":"","interactionType":"QA_CE_SBLP: Live Program_V15_Subham","interactionTimezone":"Pacific/Auckland","interactionStartTime":"12:00 PM","interactionStartDate":"5/1/2023","interactionProductTopicList":[{"topicName":"Benefits and Accuracy","topicDescription":null,"productName":"Allogerm"}],"interactionOwnerWorkPhoneExtension":null,"interactionOwnerWorkPhone":"(900) 897-3489","interactionOwnerTitle":null,"interactionOwnerNickName":null,"interactionOwnerMobilePhone":"(900) 897-3489","interactionOwnerMiddleName":null,"interactionOwnerLastName":"US.VC.SalesRep","interactionOwnerFullName":"Rep US.VC.SalesRep","interactionOwnerFirstName":"Rep","interactionOwnerEmailAddress":"us-vc.a4r1d1t1@yopmail.com","interactionName":"INT-0054492","interactionEndTime":"3:30 PM","interactionEndDate":"5/1/2023","interactionCategory":"Speaker Bureau","initiativeName":null,"externalRegistrationUrl":null,"confirmedSpeakers":[{"speakerTopic5":null,"speakerTopic4":null,"speakerTopic3":null,"speakerTopic2":null,"speakerTopic1":"Benefits and Accuracy","speakerTitle":"MR","speakerSuffix":"","speakerSalutation":"Dr.","speakerReservedShortTextMergeField2":null,"speakerReservedShortTextMergeField1":null,"speakerReservedRichLongTextMergeField1":"","speakerReservedLongTextMergeField2":null,"speakerReservedLongTextMergeField1":null,"speakerProduct5":null,"speakerProduct4":null,"speakerProduct3":null,"speakerProduct2":null,"speakerProduct1":"Allogerm","speakerLastName":"ABBAS","speakerFirstName":"ASAD","speakerCredentialsTwo":null,"speakerCredentialsThree":null,"speakerCredentials":"M.D","speakerBio":null,"speakerAffiliationName":null,"speakerAddress":null,"speakerAccountDescription":null,"participantRole":"Speaker"}],"confirmedRoomName":null,"confirmedLocationPhoneNumber":null,"confirmedLocationName":null,"confirmedAddressZip":null,"confirmedAddressState":null,"confirmedAddressNeighborhood":null,"confirmedAddressLine3":null,"confirmedAddressLine2":null,"confirmedAddressLine1":null,"confirmedAddressCountry":null,"confirmedAddressCity":null,"confirmedAddressBricCode":null,"confimedReservedShortTextMergeField3":null,"confimedReservedShortTextMergeField2":null,"confimedReservedShortTextMergeField1":null,"confimedReservedLongTextMergeField3":null,"confimedReservedLongTextMergeField2":null,"confimedReservedLongTextMergeField1":null,"collaborators":[{"workPhoneExtension":null,"workPhone":"(900) 897-3489","title":null,"nickName":null,"mobilePhone":"(900) 897-3489","middleName":null,"lastName":"US.VC.SalesRep","firstName":"Rep","emailAddress":"us-vc.a4r1d1t1@yopmail.com"}]}}}';

        String strJSON = ProcessCommand(strURl, 'PUT', jsonData, 'json', GetJWT());
        
        system.debug('strJSON @@ ' + strJSON); 
        
        String downloadURL = null;
        
        Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(strJSON);
        
        if(params.containsKey('Document')){
            Map<String, Object> doc = (Map<String, Object>)params.get('Document');
            String DocName = (String)doc.get('FileName');
            
            strURl = 'https://api.aspose.cloud/v4.0' + '/words/' + DocName + '?format=' + outFormat;
            
            downloadURL = strURl;
            System.debug('downloadURL::'+downloadURL);
        }
        return downloadURL;
        
    }
    
    catch (Exception ex) {
        system.debug(ex.getLineNumber() + '- ' + ex.getCause() + '- ' + ex.getMessage() + '- '+  ex.getStackTraceString());
        return null;
    }   
  }  
}

Input Document:
TempleteCRT1349.docx (14.5 KB)
Output Document:
subham.docx (11.9 KB)
Instead of Subham.docx if we put test.pdf in ExecuteMailMerge method of strURl URL then error comes while opening that file: image.png (29.5 KB)

Kindly guide us what we have to change or update.
Thanks in advance.

@centris.aspose

We are looking into your code and will guide you shortly.

@tilal.ahmad

We look forward to your feedback. Any update from your side.

@centris.aspose

Thanks for your patience. I am still looking into the issue and will share an update with you soon.

@centris.aspose

Please note that you are using the foreach block, so you need to set the withRegions property to true as well. Please check the sample URI for your requirements. It will help you accomplish the task.subham.docx (11.6 KB)

String strURl = 'https://api.aspose.cloud/v4.0' + '/words/' + FileName + '/MailMerge?withRegions=True&cleanup=UnusedFields&useWholeParagraphAsRegion=False&destFileName=subham.docx';

@tilal.ahmad
Got it thanks.

1 Like

A post was split to a new topic: How to Restore my Account?