Problem with importing docx and doc

General TRichView support forum. Please post your questions here
Post Reply
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Problem with importing docx and doc

Post by saeid2016 »

Hello support,

By TRVOfficeConverter1.ImportRV I import docx and doc files to RichViewEdit. The problem is that when the file name or file path directories name is Arabic word, it doesn't work and gets error. The TRVOfficeConverter1.ErrorCode is -1 .

Is there a way to solve this problem?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with importing docx and doc

Post by Sergey Tkachenko »

Only by copying this file to a path and under a name that do not contain Arabic characters.

Converters accept paths in OEM (i.e. DOS) encoding. TRVOfficeConverter converts file names to OEM, but some characters cannot be converted.

In older days, probably the problem could be solved by converting paths to a short form, using GetShortPathName WinAPI function. However, when I
try this function on my own computer, it returns the same string as the original path, even if it is long and has Unicode characters.
So converters can load only files having only local characters in the file name.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

Thanks for help.

I found a function that converts long file names to the 8.3 DOS format and it works correctly.

Code: Select all

uses
  Windows, SysUtils;

function GetShortName(sLongName: string): string;
var
  sShortName    : string;
  nShortNameLen : integer;
begin
  SetLength(sShortName, MAX_PATH);
  nShortNameLen := GetShortPathName(
    PChar(sLongName), PChar(sShortName), MAX_PATH - 1
  );
  if (0 = nShortNameLen) then
  begin
    // handle errors...
  end;
  SetLength(sShortName, nShortNameLen);
  Result := sShortName;
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with importing docx and doc

Post by Sergey Tkachenko »

Well, probably I should add it to RVOfficeConverter...

However, as I said, it does not help on my computer (Win10, NTFS): it simply returns sLongName.
But at least it does no harm.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

Sergey Tkachenko wrote: Mon Sep 11, 2017 1:41 pm However, as I said, it does not help on my computer (Win10, NTFS): it simply returns sLongName.
Like your computer, My operating system is Win10 and my drives format is NTFS. but in my computer it works correctly. why?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with importing docx and doc

Post by Sergey Tkachenko »

AFAIK, NTFS always supports short file names, but their creation for new files may be enabled or disabled.
You can check using the system command line utility fsutil:

Code: Select all

fsutil behavior query disable8dot3 c:
It displays the value for the specified drive (c:):
0 - short file names are created,
1 - short file names are not created.

So some files may have short version of their names, some not.

I added conversion to short file names in TRVOfficeConverter, in the today's update for registered users.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

2 questions:

1. why converters accept paths in OEM (i.e. DOS) encoding? Is there a convertor that does not use OEM encoding?

2. Some of my docx files are on my server that it's OS is Linux. Is it possible to enable short file name creation on Linux?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with importing docx and doc

Post by Sergey Tkachenko »

1) I do not know why. No, the converters specification states that file names must be in OEM.
2) I recommend not changing file system options, but simply writing a code in your application that copies the specified file to a temporal location under a simple name, loading this copy, deleting this copy.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

Sergey Tkachenko wrote: Thu Sep 14, 2017 10:36 am 1) I do not know why. No, the converters specification states that file names must be in OEM.
2) I recommend not changing file system options, but simply writing a code in your application that copies the specified file to a temporal location under a simple name, loading this copy, deleting this copy.
Thanks.

Importing some doc files (not all) gives an error. it's ErrorCode is 0. what does it mean?
Last edited by saeid2016 on Mon Sep 18, 2017 2:41 pm, edited 1 time in total.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

Please see my attached sample. When I import the Doc1.doc it gives error: Division by zero.
Attachments
TestRichView.rar
(74.15 KiB) Downloaded 1542 times
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem with importing docx and doc

Post by Sergey Tkachenko »

I cannot reproduce the problem.
Do you use the newest version of TRichView and ScaleRichView?
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Re: Problem with importing docx and doc

Post by saeid2016 »

Importing some doc files (not all) gives an error. it's ErrorCode is 0. what does it mean?
Post Reply