ImageSaveOptions in COM Interop

Hi,

I’m trying to load a txt file into Aspose.Words to save it as a multi-page tif image. But I can’t seem to get the new declaration of the ImagesaveOptions to work correctly. What am I missing? I’ve checked the demos, but that code isn’t valid in VB6 using COM Interop.

Dim objAsposeCom As New Aspose\_Words.ComHelper, objAsposeDocBuilder As New Aspose\_Words.DocumentBuilder
Dim objImgOptions As Aspose\_Words.ImageSaveOptions
objAsposeDocBuilder.pagesetup.PaperSize = PaperSize\_Letter

Dim fso As New FileSystemObject, ts As TextStream, strLine As String
Set ts = fso.OpenTextFile(mstrPathAndFileName, ForReading, False)
'TODO: Encoding issues
Do Until ts.AtEndOfStream
strLine = ts.ReadLine
objAsposeDocBuilder.Writeln (strLine)
Loop

'Set objAsposeDoc = objAsposeCom.Open(mstrPathAndFileName)
If mobjJobGeneral.FileFormatTypeId = FileFormatType.Pdf Then
'TODO: grayscale
objImgOptions.SaveFormat = SaveFormat\_AsposePdf
Else
objImgOptions.SaveFormat = SaveFormat\_Tiff
objImgOptions.TiffCompression = TiffCompression\_Ccitt4
End If
objImgOptions.PageIndex = 0
'objImgOptions.PageCount = objAsposeDocBuilder.Document.BuiltinDocumentProperties.Pages
objImgOptions.resolution = 300
objImgOptions.jpegquality = 75
objAsposeDocBuilder.Document.Save\_3 mstrFilenameOutput, objImgOptions

Set objImgOptions = Nothing
Set objAsposeDocBuilder = Nothing
Set objAsposeCom = Nothing

-Kiima

Visual Basic 6, Aspose for .NET 9.2

Hi

Thanks for your request. You should follow these instructions:

  1. Run Visual Studio. Create new class library project. Let’s name the project ‘AsposeComWrapper’. Then, let’s rename the single existing class in it to ‘Methods’.

  2. Create wrapper class using the following manual.
    https://docs.aspose.com/words/net/supported-platforms/#com

Class like the following:

using Aspose.Words;
using Aspose.Words.Saving;
namespace AsposeComWrapper
{
    public class Methods
    {
        public Methods()
        {
        }

        /// COM Wrapper for Document.Save to tiff.
        public void SaveImageToTiff(object doc, object savePath)
        {
            ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.Tiff);
            opt.TiffCompression = TiffCompression.Ccitt4;
            ((Document)doc).Save((string)savePath, opt);
        }
    }
}

Also 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 Configuration Properties, and then click the Application node. Click to button the Assembly Information. Click to select the Make assembly COM-visible check box)

Also you should set strong name for assemble.

  1. Register assembly
cd C:\WINNT\Microsoft.NET\Framework\v2.0.50727

regasm C:\AsposeComWrapper.dll /codebase

Create sample .vbs as the following:

Dim lic
Set lic = CreateObject("Aspose.Words.License")
lic.SetLicense("C:\Temp\Aspose.Words.lic")
' Open document
Dim doc
Set doc = CreateObject("Aspose.Words.Document")
' Create DocumentBuilder.
Dim builder
Set builder = CreateObject("Aspose.Words.DocumentBuilder")
builder.Document = doc
builder.Write("Hello world!!!")
Dim methods
Set methods = CreateObject("AsposeComWrapper.Methods")
methods.SaveImageToTiff doc, "C:\Temp\Test.tiff" 

Best regards,

Thanks. That did the trick.