Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CorelScript/VBA 4

Status
Not open for further replies.

philote

MIS
Oct 2, 2003
861
US
I'm wanting to create a web-based application that allows users to input text that will then be placed on a template. The templates are already in .cdr format. I was planning on using CorelScript or VBA in CorelDraw 10 to do the actual placement of text and printing of the file. Has anyone done this before and would it be difficult? Also, I don't know how to get CorelDraw to be opened and get the correct text from my web-based program. Could I leave CorelDraw open and have the script running constantly, checking a folder for text files it could get the template name and text to put on the template from? Does this sound feasible or am I wanting to do too much? I'll probably ask in the VBA forum as well.

Kevin
A+, Network+, MCP
 
short answer to your question - no, can't use VBA with the web (so to speak). but i have done this with a VB 6 com and ASP.
 
Use VB, add a reference to the Corel Component and do your scripting from VB. You can then use other components to communicate with Database and Web Pages.

If you are trying to have a web page where someone enters somehting, then hits submit and a CDR gets made for them on the spot -- it is possible -- but very unstable. Corel is not a multithreaded application. So if more than one person makes a call to your web page that connects to the Corel VB/.net/component it will bomb.

If you write the web page to take the input, send tot he server and store in a database. On a another machine a VB application scans for updates in the DB, processes the infor, controls CDR to make the file, saves it to disk and emails or ftp's it. So basially each request gets queued up and the VB/CDR applicaiton does each in turn.

wbochar
 
Thanks for the info, wbochar. When you say VB, are you talking about actual VB, where I'd have to go buy the VB editor/compiler? Or can I use VBA or VB Script? I've never really programmed in any of these except a little VBA for Excel, and I'm not even sure what the differences are. Also, does VB play well with MySQL?

I am trying to allow users to enter something from a web page so your advice there is very helpful. I had in mind for it to generate the CDR as soon as the info is entered, so I'm glad you warned against that. The VB application will also be printing the CDR file, so what I may do is have a user interface on another machine in VB that allows the user to view the entries from the web page and select one to process. Then it can build the CDR and print it.

I don't know if there's a better way to do what we're attempting, but I'll explain in case someone can give other tips. Our company is a beer distributor and we make most of the signs you see in stores ( the ones with the prices and such) in house. Our salesmen are the ones who decide which signs and what price to put on them. We also have a list of sign templates we can use, which are CDR files, so the salesman will pick which template and the price to put on it. I guess our application will have to be told where the price will go, what font to use, and what if any package type to put on it ( bottles, cans, etc.). Right now we have two guys creating these signs, but one will be moved to another position withing the company. We're looking to automate what we can for the remaining guy so he can focus on custom signs.

Thanks for all the help!

 
Yes, He is referring to Visual Basic which would require the IDE. I have set up similar types of automation with VB/CorelDraw.

You can use VBA from within CorelDraw itself and script much of the functionalility within Corel. There is a pdf file on the Corel CD that describes the Corel VBA API model and how to script it. Can't remember the name of it. But it's similar in how you did it in Excel.

There is a very good web site all about Corel/VBA/Visual Basic: They have a great forum dedicated solely to it.
 
So do you think I can do what I want with VBA alone? It looks like I can access our MySQL database with VBA, so I could do what wbochar said and have it check the database and create/print any new entries. I'll be able to have a computer solely for this purpose, so it won't be a problem to just leave CorelDraw open all the time with the VBA app running. It looks to me like it could work, but I may be missing something.

Thanks for the link, bbolte. I've come across this site before when looking for info on this project, but hadn't checked out the forums. I'm sure I'll be a frequent visitor to those in the coming weeks.

 
The Forums on that Site are amazing, and the guy who runs it is soo helpful.

Generally when you code using the VB and referenced Corel 10/11 Application -- anytime your program is running so is Corel. When you close your app you close corel as corel has a lot of memory leaks and funniness when left open for long periods of time.

I have written a server type program doing what you've done.. It calls out to the DB, builds a Corel Document based on Satalite Photo's, Demographics and other networked data sources. The program when asked to do the full set of documents needs to pause and restart between docs or after 10 straight docs the memory usuage of corel goes through the roof. So do one document, close down the application and then restart it and check the next item in the queue.. do that one.. shut the app down (and corel).. restart app.. continue. Doin this insures that the mem is cleared up and garbage collection is forced. If you have corel still open and you are just opening doc, modify, closing doc -- corel will bomb after a 10-12 iteractions for no real reason (other than that corel is sometimes annoying:)).

Using VB combined with Corel you should be fine (as well as a data source). This kinda project is not for timid.. as Corel has many quirks.. and windows has many too. If you are doing .NET it works great too.

Good luck!

wbochar


 
wbochar,
so you've done this with .Net? VB .Net i assume? i've had trouble getting it to work with .Net. how did you wire it up? i could never get past the initial call out with out throwing errors. although this prolly has much to do with not knowing .Net very well yet.
 
Its pretty easy, just reference corel 11 then call it in VB here is some example code for a console app that I made a while ago.. I yanked out the most of it but left in the startup, opening, text replacing and closing/pdf output code so you can see how everything works.



Sub Main(ByVal args() As String)

Dim App As CorelDRAW.Application
Dim doc As CorelDRAW.Document

App = CreateObject("CorelDRAW.Application.11")
'App.Visible = True

App.Optimization = True

doc = App.OpenDocument("C:\templates\template7.cdr")
Dim x

' Front Page Modifcations (this template has mulitple pages)
x = TextReplacer(doc, p_name, 1, "p_name")


' File saving and output to PDF


Dim opt As New CorelDRAW.StructSaveAsOptions()

opt.EmbedICCProfile = False
opt.EmbedVBAProject = False
opt.IncludeCMXData = False
opt.Overwrite = True
opt.Range = 0
opt.ThumbnailSize = 3
opt.Version = 11

doc.SaveAs(("c:\!brochures\" & p_state & "-" & p_name & " (" & p_id & ")" & ".cdr"), opt)


' Dump to PDF



With doc.PDFSettings
.Author = "Equity One, Inc. (2003) Lores"
.ColorMode = CorelDRAW.pdfColorMode.pdfNative
.ComplexFillsAsBitmaps = True
.DownsampleColor = True
'.DownsampleGray = True
'.DownsampleMono = True
.ColorResolution = 150
'.GrayResolution = 150
'.MonoResolution = 150
.BitmapCompression = CorelDRAW.pdfBitmapCompressionType.pdfZIP
'.JPEGQualityFactor = 98
.EmbedBaseFonts = True
.EmbedFonts = True
.SubsetFonts = True
.SubsetPct = 80
.TextAsCurves = True
.TrueTypeToType1 = True
End With
doc.PublishToPDF("c:\!brochures\" & p_state & "-" & p_name & " (" & p_id & ")" & "(lo-res).pdf")

App.Optimization = False


end sub


Private Function TextReplacer(ByVal Doc As CorelDRAW.Document, ByVal NewText As String, ByVal pagenum As Long, ByVal ObjectIDx As String)
Dim s As CorelDRAW.Shape

If NewText = "" Then NewText = "N/A"
If NewText = vbNullChar Then NewText = "N/A"

For Each s In Doc.Pages(pagenum).FindShapes(Name:=ObjectIDx, Type:=CorelDRAW.cdrShapeType.cdrTextShape)

s.Text.Contents = NewText
Next s
End Function
 
No, just the standard ones for doing debug and stuff like that.

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
 
This is going to be quite a learning experience for me. I just bought an O'Reilly book on VB/VBA. The only time I've ever used VB was to create a mock gui for a class project. The only time I've used VBA was to automate a few minor things in Excel. This will be quite a challenge, but I'm up for it!

 
Stars for each of you guys for helping learn something new.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top