3

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

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

4

2 回答 2

0

我发现最好的方法是使用 VBscripts。

如果您仍然感兴趣,请查看下面的代码。脚本(从 java 开始)采用 2 个参数:源文件和目标文件,并在将源文件保存到目标之前对源文件进行一些操作。

此脚本的限制是它依赖于“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>
于 2014-09-05T09:56:13.667 回答
0

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

C:\Program 文件 (x86)\Corel\Corel Graphics 12\Programs

PDF:dvba_pg.pdf

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

我希望这能帮到您。

于 2013-01-01T20:37:16.013 回答