Arabic Text Replace in PDF Using Aspose.PDF REST API Adds Weird Space and Font

Hello,

I am applying aspose on arabic text. I have created a pdf file and it has a custom arabic font. When I do the replace, the font becomes different and there is a weird large space inserted as displayed in images.

Fonts displayed on output pdf:
d1d8a0f277c3af53bc55b1d856cedab6.png (5.2 KB)

The output

248085320192df5d50423d72d91bcb7a.png (8.6 KB)

Code Below:
$textReplace = new TextReplace([
“old_value” => “[ARNAME]”,
“new_value” => “محمد”,
“regex” => false
]);

    $textReplaceRequest = new TextReplaceListRequest([
        "text_replaces" => [$textReplace],
    ]);

    $textReplaceRequest->text_replaces = [$textReplace];
    $response = $pdfApi->postDocumentTextReplace(
        $remoteFileName,
        $textReplaceRequest,
        null,   // Storage
        null    // Folder
    );

Any help?

@sarakat1998

Kindly share your input sample document with us. It will help us to investigate and resolve the issue.

sure
testing_font.pdf (18.2 KB)

kindly note that the first sentence will not work and that’s ok. The focus is on the second one.

@sarakat1998

Please note for Arabic text replace in PDF you need to use Font and FontFile property of TextState for custom fonts as follows. Kindly update your custom font to the cloud storage and pass its name and path in the Font and FontFile properties respectively. It will help you to accomplish the task.
testing_font.pdf (100.1 KB)

Find and Replace Arabic Text in PDF

curl -X POST "https://api.aspose.cloud/v3.0/pdf/testing_font.pdf/text/replace?folder=Temp" 
-H "accept: application/json" 
-H "authorization: Bearer [Acces_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "{ "TextReplaces": [ { "OldValue": "[ARNAME]", "NewValue": "محمد", "Regex": false, "TextState": { "Font": "Tajawal Black Regular", "FontFile": "Fonts/Tajawal Black Regular.ttf", }, } ]}"

Thank you I did that and now it takes the font but messes up the first word as show in the picture

Before

After

It also does not solve the space/gap issue.

Can I have some more help please? I am very grateful!

@sarakat1998

We are sorry for the inconvenience. I have noticed the reported issue and logged a ticket PDFCLOUD-2872 in our issue tracking system for rectification. We will notify you as soon as we fix the issue.

Thank you, any estimation on how long it could take?

@sarakat1998

I am afraid we cannot share any ETA at the moment as we recently noticed the issue. We will keep you updated about the issue resolution progress with in this forum thread.

Alright, thank you for your help.

1 Like