Creating a text type Shape inside a rectangle shape in Document in c# using Interop.VGCore

54 Views Asked by At

I am trying to automate a task of creating a rectangle with text inside it programmatically using Corel Draw type library. But because of very less documentation present it is getting really tough for me.

I have already added the reference to interop.VgCore , I am able to open a new document in the CorelDraw application as well

Type pia_type = Type.GetTypeFromProgID("CorelDRAW.Application");
Application app = Activator.CreateInstance(pia_type) as Application;
app.Visible = true;

I am not able to find what to do after this . I tried creating the instance of the Shape Class but , I can't do so getting some exception :

System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {A77D0076-C6D1-4D32-9F72-F3A62CE56578} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).'

1

There are 1 best solutions below

0
bonus630 On

You can't create any instances of classes, it's all interfaces, I'll add a few lines of code as an example to get you started.



    Type pia_type = Type.GetTypeFromProgID("CorelDRAW.Application");
    Application app = Activator.CreateInstance(pia_type) as Application;
    app.Visible = true;
    
    Document doc = app.CreateDocument();
    double x = 0, y = 0, w = 10, h = 10;
    doc.Unit = cdrUnit.cdrCentimeter;
    
    Shape rectangleShape = doc.ActiveLayer.CreateRectangle2(x, y, w, h);
    Shape textShape = doc.ActiveLayer.CreateArtisticText(x, y, "text");
    
    textShape.CenterX = rectangleShape.CenterX;
    textShape.CenterY = rectangleShape.CenterY;
    
    Color red = app.CreateRGBColor(255, 0, 0);
    Color yellow = app.CreateRGBColor(240, 240, 15);
    
    rectangleShape.Fill.ApplyUniformFill(red);
    rectangleShape.Outline.PenWidth = 1.5d;
    
    Shape textShape2 = textShape.Duplicate();
    textShape.Fill.ApplyUniformFill(yellow);
    textShape.Outline.SetNoOutline();
    
    Shape textBitmap = textShape.ConvertToBitmap();
    
    if(textBitmap.Type == cdrShapeType.cdrBitmapShape)
        textBitmap.Bitmap.ApplyBitmapEffect("Blur", "GaussianBlurEffect GaussianBlurRadius=300,GaussianBlurResampled=0");