Not able to open existing document(.docx-dotx-.dot)by Aspose.Words.dll as com in Delphi 2007

Hi Team,
I am not able to open existing document by invoking Aspose.words dll as com in delphi 2007.While invoking Comhelper open method in Delphi 2007,It is Throwing floating point error/Access violation error/Stack Overflow error.

Please help us to resolve this

var
 doc: _Document;
 builder: _DocumentBuilder;
 opendoc:_ComHelper;
 doc1: OleVariant;
 helper: OleVariant;
 
Begin
{this below code throws stack overflow error on opening docx and access violation error on doc file}
  doc := CoDocument.Create;
  builder := CoDocumentBuilder.Create;
  opendoc:= CoComHelper.Create;
  doc := opendoc.Open('c:\testing.dotx');

  doc.Save('c:\testing.pdf');  

{The below code Throws floating point error at open method }
 CoInitialize(nil);

  helper := CreateOleObject('Aspose.Words.ComHelper');

  doc1 := CreateOleObject('Aspose.Words.Document');

  doc1:= helper.Open('c:/testing.dotx');

  doc1.Save('c:/srcdoc.pdf');

  CoUninitialize;

Thanks
Vijaya Maruthai

Hi Vijaya,

Thanks for your inquiry. Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

I am attaching my sample document format .docx

issue is only in Delphi and it is working fine in .net application.

Kindly help us to overcome the issue.

This is urgent to complete my poc.

Thanks

Vijaya Maruthai

Hi Vijaya,

Thanks for sharing the document. Please make sure that you have registered Aspose.Words for .NET with COM Interop correctly and using latest version of Aspose.Words for .NET 17.1.0.

Form the shared detail, it seems that the issue is not related to Aspose.Words. Could you please share if you are facing this issue will all document or only with specific document? Please also share the complete stack trace of this issue. Thanks for your cooperation.

Hi,

Herewith I am attaching the complete error details.

I downloaded aspose.total for .NET and Registered the Aspose.words.dll from .net2.0 folder.

Please help us asap.After that only we can conclude whether we can use Aspose.words for our Document generation project.

Thanks

Vijaya Maruthai

Hi Vijaya,

Thanks for sharing the detail.

This issue seems not to be related to Aspose.Words. We are setting up Delphi 2007 at our end. As soon as everything is setup, we will test this issue and will post the results here for your kind reference.

Hi Vijaya,

Thanks for your patience. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14809. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Dear Team,
May I know that ticket WORDSNET-14809 is resolved from your side. We are planning to use your product for Doc to PDF conversion for better performance. Please inform us if that problem is resolved and any idea is appreciated for integration of Aspose in Delphi 2007.

Thanks

Hi Vijaya,

Thanks for your inquiry. We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. Our developers work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once our product team completes the analysis of your issue, we will then be able to provide you an estimate.

Thanks for your patience and understanding.

Dear Team,

Please provide sample code for Compressing PDF size.I am using Aspose.words as com in Delphi and when saving .doc file to pdf ,size would be double.

I am not able to use PDFsaveoptions properties like usercorefonts,PDFtextcompression in doc.Save method.

Error: Incompatible types : ‘_SaveOptions’ and ‘_PdfSaveOptions’

Below is the code tried in Delphi

var
doc: _Document;
builder: _DocumentBuilder;
Saveoptions :_PdfSaveOptions;
opendoc:_ComHelper;
dataDir :string;
l8087CW: Word;

begin

l8087CW := Default8087CW;

Set8087CW($133f);

try

doc := CoDocument.Create;

builder := CoDocumentBuilder.Create;

opendoc:=CoComHelper.Create;

Saveoptions:=CoPdfSaveOptions.Create;

dataDir := ‘c:\test3.pdf’;

doc := opendoc.Open(‘c:\test.DOC’);

Saveoptions.TextCompression:=PdfTextCompression_Flate;

Saveoptions.UseCoreFonts:=True;

doc.Save_3(dataDir,Saveoptions) ;

finally

Set8087CW(l8087CW);

end;

Hi Vijaya,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Hi Vijaya,

Thanks for your patience. We have logged this problem in our issue tracking system as WORDSNET-15019. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Vijaya,

Thanks for your patience. Please read “Creating a Wrapper Assembly” from following article:
Use Aspose.Words for .NET via COM Interop

In your case, we suggest you please create a wrapper class in C#/VB.NET and use it in your Delphi code. Please check following wrapper class for your kind reference. Hope this helps you.

namespace AsposeComWrapper
{
    class DocumentConversion
    {
        public void ExportToPdf(object inPath, object outPath)
        {
            Document doc = new Document((string)inPath);
            PdfSaveOptions saveOptions = new PdfSaveOptions();
            saveOptions.TextCompression = PdfTextCompression.Flate;
            saveOptions.UseCoreFonts = true;
            doc.Save((string)outPath, saveOptions);
        }
    }
}

Please make assembly visible for COM (On the View menu, click Solution Explorer. In Solution Explorer, right-click the project that you want to build for COM interop, and then click Properties. Click the Application node. Click to button the Assembly Information. Click to select the Make assembly COM-visible check box)

Please register assembly using regasm.exe utility.
regasm C:\AsposeComWrapper.dll /codebase

Hi Vijaya,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-14809) as ‘Not a Bug’.

The problem occurs somewhere inside Delphi (or Embarcadero) because we are using Double.NaN value in our code. You can reproduce the same problem with any other .NET assembly which uses Double.NaN inside the code.

namespace DoubleNan
{
    public class TestClass
    {
        public TestClass() { }
        public void TestMethod()
        {
            Console.WriteLine("Start1");
            double test = Double.NaN;
            Console.WriteLine("End1");
        }
    }
}

Please create a wrapper class and register it using regasm.exe utility as shared in my previous post. Try to use this assembly inside Delphi in Embarcadero RAD studio, like this:

var testClass: OleVariant;
CoInitialize(nil);
testClass := CreateOleObject('DoubleNan.TestClass');
testClass.TestMethod;
CoUninitialize;

You will get the same exception like upon using Aspose.Words. The same assembly works fine in VB via COM.

Hi Vijaya,

Further to my previous post, the exception you are getting is a well-known problem with Delphi. The reason is that Delphi run-time changes the the Floating Point Control Word (FPCW) register and .NET run-time doesn’t expect that change.

Please check following article about this problem:
Floating point exception in managed code results in Access Violation crash

The article suggests to reset FPCW before executing .NET code from Delphi. Please check the following code snippet. Hope this helps you.

procedure Foo;
var
saved8087CW : Word;
begin
saved8087CW := Default8087CW;
try
// Disable all floating-point exceptions.
Set8087CW($133F);
// Now we are ready to use Aspose.Words assembly.
// ...
finally
Set8087CW(saved8087CW);
end;
end;