Hello,
I’m trying to insert a fax number to a bookmark inside a table in RTL document
The fax pattern is: (000) 1234567
But the result is: 1234567 (000)
when i use a bookmark outside the table it’s coming out fine (000) 1234567
I attached the doc files
This is the code I use:
Document d = new Document(@"C:\rtl-src.doc");
d.Range.Bookmarks["inside"].Text = @"(000) 1234567";
d.Range.Bookmarks["outside"].Text = @"(000) 1234567";
d.Save(@"c:\rtl-res.doc");
Can you help me out please?
Thanks,
Elad
Hi Elad,
Thanks for your inquiry. Please try using the following code snippet:
Document doc = new Document(@"C:\test\rtl-src.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("inside");
builder.Font.Bidi = false;
builder.Write(@"(000) 1234567");
builder.MoveToBookmark("outside");
builder.Font.Bidi = false;
builder.Write(@"(000) 1234567");
doc.Save(@"c:\test\out.doc");
I hope, this will help.
Best Regards,
Hi Awais,
Thank you for replying.
I probably had to explain the whole problem.
What I wrote is just an example.
I need to insert a string containing both letters and numbers to a document with bookmarks.
Sometimes the string will be in English and sometimes in Hebrew.
I can’t tell if the document is in English or Hebrew (and the string as well) so I just want to inherit the current styling of the bookmark.
It’s basically working fine, but inside a table the numbers and other special characters and spaces changing the order if they’re one after another without letters between them.
If I’ll set bidi=false, the Hebrew text won’t be displayed correctly.
What’s the different between those cases? (inside/outside table)
Are there any other similar scenarios I should know?
Is there a workaround?
Thanks,
Elad
Hi Elad,
Thanks for the additional information. I would suggest you please read the following thread:
https://forum.aspose.com/t/65706
I hope, this will help.
Best Regards,
Hi Awais,
If I understood the referred post correctly, it should be ok in one of ms word’s version and wrong in the other due to different format protocols
I tested it and it seems both ms word 2007 and 2010 display the fax wrong inside a table and right outside of it.
I don’t think I’ll be able to break the string and seperate words and numbers.
Is there another workaround or anything else I can try?
Thanks,
Elad
Hi Awais,
This issue became urgent
Is there another solution for my issue?
It’s too complex to break down the string to rtl and ltr segments with a regex
Thanks,
Elad
Hi,
I’m still waiting for a respond.
Thanks,
Elad
Hi Elad,
Thanks for the additional information. We’re investigating this scenario closely and will get back to you soon.
Best Regards,
Hi Elad,
Thanks for your patience.
I’ve taken a closer look into this issue and have found there appears to be no bug here.
Normally the font of any content replaced in the document is inherited from the inline objects such as runs inside the paragraph. However, since your paragraphs are empty the paragraph break font of the parent paragraph is used instead. If you take a look at the ParagraphBreakFont for the paragraph inside the table you can find that Bidi = true. If you look at the same property for the paragraph outside the table, Bidi = false. Therefore, Aspose.Words is indeed inheriting the correct direction from the surronding content.
The real issue is that you need a way to automatically detect whether the content being inserted is a LTR or RTL language. You can either choose to implement such a process yourself by scanning the incoming text, or we can log an issue to built this type of functionality into Aspose.Words itself. Please note that we might not be able to implement this in Aspose.Words straight away so if this is urgent we will gladly assist you in creating sample code to do this.
Thanks,
Hi,
Sorry for the delayed response. I was unavailable in the past week.
I’ve been trying to use regex to break the string into groups of and to have the same bidi value for numbers with signs and spaces between them but I could not tell if the signs should be with the letters or with the numbers in some cases
( 123 ) abc
123 ( abc )
and I have no control on the text format since it’s user input.
If you can provide me a sample code for now that I’ll use until you will be able to add this feature in Aspose.Words, that would be great
Thanks,
Elad
Hi Elad,
Thanks for your inquiry.
Could you please include your regex, sample input and desired output here and we will take a closer look into this for you.
Thanks,
This is the regex I tested
"((?:(?:\\d)|(?:\\W))+)|((?:\\D)+)"
the idea was to catch digits with non-digit\letters (= signs and spaces) in one group
and non-digits (=letters, signs, spaces) in another group
after that, for each group seek for digits and if a digit was found, i’d set bidi=false. otherwise bidi=true
sample inputs are:
טלפון (03)1234567
the 03 in the brackets should be on the left of the 1234567
טלפון (03) 1234567
same
טלפון 03-1234567 (טלפון נוסף 09-87654321)
here, the brackets should be in rtl and only the numbers and dash should be in ltr
בית (03-1234567) או נייד (050-1234567)
doesnt matter if including brackets in rtl or ltr, but they must be the same bidi for both
perhaps there should be a trace of opening and closing brackets
I can’t think of a specific definition for signs’ bidi value without seeing the context of it
Thanks,
Elad.
Hi Elad,
Thanks for the additional information. We are checking with this scenario and will get back to you ASAP.
Best Regards,
Hi Elad,
Thanks for your patience. An easy option I can offer you here is to parse your input string manually from left to right, say. During parsing, based on your pattern matching algo, you can return string tokens (e.g. you can find a good StringTokenizer here*) and then apply bidi properties accordingly before inserting these tokens to Word document.
I hope, this will help.
Best Regards,