Corel Draw API(Java / C#)

时间:2012-06-25 22:37:39

标签: c# java api coreldraw

我想知道是否有来自Corel Draw for Java或类似的API。我的一个朋友需要一个小程序来编辑一些照片。它必须是Corel Draw,但编程语言没有限制(Java或C#优先...)

不幸的是,我没有在互联网上找到任何有用的东西。你们中的一些人可能知道更多吗?

2 个答案:

答案 0 :(得分:0)

我知道你用VB编写了一些宏。您可以在以下位置找到pdf文档中的所有信息:

C:\ Program Files(x86)\ Corel \ Corel Graphics 12 \ Programs

PDFs: dvba_pg.pdf

PP VBA对象模型.pdf: CorelDRAW VBA对象模型.pdf

我希望这会对你有所帮助。

答案 1 :(得分:0)

我发现最好的是使用VBscripts。

在cas中你仍然感兴趣,看看下面的代码。 脚本(从java开始)有两个参数:源文件和目标文件,并在将源文件保存到目标之前对源文件进行一些操作。

此脚本的限制是它依赖于“CorelDraw x6”。您可以将其编写为更通用,并查找各种CorelDraw OLE对象。

这种机制的局限在于,不能用VB完成所有工作(我从未实现过获取CorelDraw页面的大小!!!)

代码:

<package>
    <job id="Main">
        <reference object="CorelDraw.Application" version="16.0" />
        <script language="VBScript">
            Option Explicit

            Dim app

            ' Parameters
            Dim source, dest
            if ( Wscript.Arguments.count<2) Then
                    Err.Raise 2, "MakeThumb", "Invalid paremeters count"
                    Wscript.echo "Invalid paremeters count"
                    Wscript.quit -999
                    end if


            source= Wscript.Arguments.Item(0)
            dest= Wscript.Arguments.Item(1)

            'Wscript.echo source
            'Wscript.echo dest

            ' Initialisation
            set app= nothing
            On Error resume next
            ' Retrieval of an existing instance
            Set app = GetObject(, "CorelDraw.Application.16")
            On Error GoTo 0
            ' No existing instance, creatoing a new one
            If (app is nothing) Then
                    Err.Clear
                    On Error resume next
                    Set app = CreateObject("CorelDraw.Application.16")
                    On Error GoTo 0
                    End If
            If (app Is Nothing) Then
                    Err.Raise 2, "MakeThumb", "Impossible to open Corel Draw"
                    'stop
                    Wscript.quit -998
                    end if

            app.visible=true
            Dim doc
            set doc = app.OpenDocument(source)

            ' Trying to get source document's size

            'Dim cs
            'Set cs = CreateObject( "CorelDRAW.CorelScript" )
            Dim pg
            Set pg = doc.pages.Item(1)

            doc.unit=5 'unit=pixels

            Dim h0, w0

            on error resume next
            ' if it fails, I assume the dimention are an A4

            h0=pg.SizeHeight
            w0=pg.SizeWidth
            if (err<>0) then
                w0=2480
                h0=3508
                end if
            on error goto 0


            Dim h, w, s, r
            'Wscript.echo "h orig=" + CStr(h0) + ",w orig=" + CStr(w0) + " unit=" + CStr(doc.Unit)

            h = doc.ToUnits(h0, cdrPixel)
            w = doc.ToUnits(w0, cdrPixel)

            s = h * w
            r = Sqr(500990 / s)
            'Wscript.echo "h=" + CStr(h) + ",w=" + CStr(w) + ",s=" + CStr(s) + ", r=" + CStr(r)

            Dim h2, w2
            h2 = h * r
            w2 = w * r

            'Wscript.echo "h2=" + CStr(h2) + ",w2=" + CStr(w2)

            Dim exportFilter
            Set exportFilter = doc.ExportBitmap( _ 
            dest, cdrPNG, cdrCurrentPage, cdrRGBColorImage, w2, h2, 72, 72, _ 
            cdrNormalAntiAliasing, False, False, True, False, cdrCompressionNone, Nothing, Nothing)
            exportFilter.Finish

            doc.close 
            app.quit

            Set app = Nothing 
            Set doc = Nothing
            Wscript.quit 0

        </script>
    </job>
</package>
相关问题