× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Charles,

> Leave it to me to try to swim upstream...

Upstream is right!


> I have a need to print formatted text from an RTF file (or possibly XML
> saved from Word) from a well aged RPG print program using AFPDS.  I need to
> be able to create text with bold, underline, font size, etc, and then
> somehow manage to get the RTF/XML output converted to AFPDS during the print
> program.

Can I ask why you don't just print this from Windows where the software to
do the printing already exists?  Maybe have Word print it to an AFP print
driver (which will create the AFPDS) and then upload THAT instead of
uploading the Word or RTF?  That would be much easier to deal with...

> The user text is variable and will be updated regularly, so static
> overlays are out for the most part.  I'm trying to formulate a solution that
> would basically let me plop an RTF document in the middle of an RPG print
> process.

Prerequisites before even considering gettng started:

1) You have to understand the AFP data stream very well, because you'll
need to write that stream out directly -- DDS isn't going to be dynamic
enough.

2) You have to have a good grasp on manipulating stream file data.

Understanding a word document, XML or not, is no small task.  Yes, XML
will be somewhat easier than the typical OLE2 compound document format...
but there's still a ton of things to contend with.  First you have to deal
with all of the possible formatting capabilities that word has, text,
fonts, bold/italic, tables, lines/boxes, bulleting/numbering, the list
goes on and on and on...

Once you've managed to extract all of that information from the document,
you'll need to write routines to format it as output.  Remember, AFP
doesn't have the same fonts that Word does, so you'll need to translate
them.  All of Word's many, many capabilities will need to be duplicated.
This is easily 50000 lines of code.

Now that you've got that done, you'll get complaints CONSTANTLY that the
rendering isn't exactly like Word... a table won't be quite right, an
image will be missing, etc.

IMHO, RTF will be easier to deal with.  Not because it's an easier file
format -- XML would be easier to parse -- but because RTF has FAR, FAR
fewer features than Word's own file format does.


It's still not an easy task though...  You'll have to parse the RTF stream
file and write corresponding AFPDS code.

You can get the official spec for RTF from Microsoft's web site at the
following link. On that site, there's a link to an MSDN site that has an
.EXE file that you can download... when you run the EXE, it unzips a Word
document containing the RTF spec...

http://support.microsoft.com/default.aspx?kbid=86999

Make sure you look at Appendix A, which explains how to write an RTF
reader, and even gives code examples (in C, though)

Then, what I'd probably do is use the mmap() API to bring big chunks of
the RTF file into memory at once, and scan through it byte by byte to
parse out the control statements.  Control statements start with a
backslash, they look something like:
 \bullet\lquote TestTest\rquote

So, you'll have to read the document byte by byte, determine that a \
means that the following data is a control word, the control word
conttinues until you hit a non-alphabetic character... so you read the
control word byte by byte until you get a non-alphabetic character, and
when you do you look that control word up in select group and call an
appropriate routine to handle that control word.  Some of them, though,
have parameters, so you have to make sure you them properly.

Naturally, the routine that handles that particular control word will do
so by outputting AFPDS data....

Like I said... not easy, but possible.

Have a nice time :)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.