Reputation: 25
We are trying to create a wordperfect files using Corel sdk(WPOX7 SDK) with .net (C#)frame work.
I am googling for document for that and not able to get any of the document for that.
Could any one know, please provide me a sample.
Upvotes: 1
Views: 1033
Reputation: 918
I don't think you want to go the route of using the SDK to create a WordPerfect document. I may be wrong, but when I looked through that SDK, it was more about modifying how the WordPerfect program functions. Very complex learning curve.
It is fairly simple, however, to create a WP document using .NET and the PerfectScript API that comes with WP.
I would first spend a few hours looking at this site, especially the section of using VB.NET to control WordPerfect.
Most of the examples on that site use Visual Basic, which is a bit like riding your horse to the office, but it is pretty simple to translate the ideas to C# (or IronPython).
You will also need to become familiar with the PerfectScript command set (there are hundreds of possible commands). This is the same language that macro writers use to automate WordPerfect from within WordPerfect, except that slightly different syntax is used when using the language from .NET.
The steps you will need to take to create a WP document are:
1) find the wpwin17.tlb or the wpwin17.dll--assuming you are using WP x7. This should be in the Corel/.../programs folder where WP is installed. Using the tlb is easier, if it's there, but if not, you can always create a tlb using the command-line program regasm.exe. Add a reference to your project to the tlb.
2) Add a "using WordPerfect;" and "using System.Runtime.InteropServices"; reference to any file that will use the PerfectScript commands.
3) Fire up PerfectScript and create your document!
Here is a very simple example of what you can do.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordPerfect;
using System.Runtime.InteropServices;
namespace WordPerfectBasic
{
class Program
{
static void Main(string[] args)
{
PerfectScript wp = new PerfectScript();
wp.WPActivate();
wp.AppMaximize();
wp.KeyType("Hello World!"); // note that the PS macro command is "Type", but that is a reserved keyword
// in C#, so Visual Studio modified the name to "KeyType"
wp.KeyType("\n\t");
wp.KeyType("Blah");
wp.Justification(_Justification_Justification_enum.
Center_Justification_Justification); // Instead of using the PS argument, which is
// usually a string or integer, VS provides enums.
wp.AttributeAppearanceOn(14); // Underline. Somebody forgot to provide enums for this command,
//so you have to figure out on your own
// what integer equivalent WP uses.
wp.KeyType("Blum");
Marshal.ReleaseComObject(wp); //need to release PerfectScript in order to re-gain
//access to the WordPerfect document
wp = null;
}
}
}
You also have the option of creating a WP document, without opening WordPerfect, by programmatically creating a file in the proper WP format, using what Corel calls the "WordPerfect File Specification". The problem with this route is that you would need to create a model of the specification in order to create a binary file that WordPerfect can correctly open. This can be done without too much trouble if you are only concerned with creating very simple WP documents, but creating a model of the entire file specification would be quite a project.
The folks at libwpd did something similar using C++ in order to translate .wpd files into .odf files, but as far as I know, they only created a reader, and not a writer, for WordPerfect.
It really depends on how much "crunching" of WP documents you will need to do. Piping PerfectScript commands into a WordPerfect document takes a noticeable amount of time, even for a simple document. If you need to be able to create 5-20 page documents using the more standard formatting tools, then I would use the PerfectScript API. If you need to create 200 page documents by the dozen, then your time might be well spent modeling the file specification (or using libwpd as the base to create a writer).
Upvotes: 5