Article View: comp.sys.next.misc
Article #181Re: Looking for a Rich-Text Format (RTF) to PS converter
From: Bill Nixon
Date: Mon, 02 Nov 1992 16:04
Date: Mon, 02 Nov 1992 16:04
240 lines
8558 bytes
8558 bytes
> Quite simply, I am looking for some type of filter program
> that will take a Microsoft RTF file and produce a
> PostScript file I can send to a printer.
>
> If it matters, I want to use this on a NeXT machine.
>
> Please respond via e-mail, since I don't keep up with
> these newsgroups, and I will post a followup.
Well, here are the top "ten" responses I got from my
inquiry. A lot of people suggested opeing the file in Edit
and select print, but I was reallyt looking for a command
line utility.
The best solution I got was using "open -p filename.rtf" -
I should have RTFM. The next best solution was using the
rtfcat program show below. Thanks for the great responses!
Bill
---------------------------------------------------From: Michael Hawley <whammo.media.mit.edu!mike@uunet.uu.net>
This should work -- but the PS part only works under 3.0
rtfcat -p *.rtf | lpr
/*
* rtfcat [-afpP] [rtf-files]
*
* Concatenate RTF files on the standard output.
* Also a handy way to convert RTF -> ascii / PostScript, etc.
* Options:
* -a stdout will be plain ascii, folded to 72-char lines
* and with some common funny characters (bullets, em dashes, etc)
* converted to a crude ascii equivalent.
* -f when converting to ascii, don't do the folding and converting.
* -p stdout will be PostScript.
* -P write output to the PasteBoard.
*
* Let me know if you make any changes.
* NB -- PS won't work with < 3.0 release. See below.
*
* M. J. Hawley
* MIT Media Laboratory
* 20 Ames Street
* Cambridge, MA 02139
* mike@media-lab.mit.edu
* Copyright (c) 1992 MIT Media Laboratory.
*/
#include <appkit/Application.h>
#include <appkit/Window.h>
#include <appkit/Text.h>
#include <streams/streams.h>
#define Case break; case
#define Default break; default
static char *_arg, *_argp; /* use by 'for_each_argument */
static char *av0; /* will hold name of the command */
#define argument (_arg=(*_argp? _argp : av[++i==ac? --i : i]),_argp+=strlen(_argp),_arg)
#define for_each_argument av0 = av[0]; for (i=1;i<ac && *av[i]=='-';i++)\
for (_argp = &av[i][1]; *_argp;)\
switch(*_argp++)
#define ASCII 0
#define RTF 1
#define PS 2
int WriteOutput = RTF;
int ToPasteboard = 0;
int Fold = 1;
e(a,b,c,d) char *a; { fprintf(stderr,a,b,c,d); fprintf(stderr,"\n"); }
use(){
e("use: %s [-apP] [-s #] [rtf-files]",av0);
e("Concatenate Rich-Text files on the standard output.");
e(" -a write output as plain ascii");
e(" -f don't fold ASCII output");
e(" -p write output as PostScript");
e(" -P send output to Pasteboard");
exit(1);
}
int folder(){
FILE *p, *popen();
if (!Fold || WriteOutput != ASCII) return fileno(stdout);
/* Be careful editing the following kludgy line if using Edit. . . */
p = popen("tr '\\320\\257\\256\\252\\272\\261\\267\' \'\\020\\006\\007\\016\\017\\261\\005\' | sed \'\ns//*/g\ns//--/g\ns//fl/g\ns//fi/g\ns//``/g\ns//\'"\'\'"\'/g\ns/\\. /.\\\n/g\' | fmt","w");
return p? fileno(p) : fileno(stdout);
}
main(ac, av)
char **av;
{
NXRect r = {36, 82, 500, 720}, b = {0,0,0,0};
NXStream *f, *o;
Text *t;
Window *w;
Pasteboard *pb;
int i, l;
NXAtom types[] = {NXAsciiPboardType, NXRTFPboardType, (NXAtom)0};
for_each_argument {
Case 'a': WriteOutput = ASCII;
Case 'f': Fold = !Fold;
Case 'p': WriteOutput = PS;
Case 'P': ToPasteboard = 1;
Default : use();
}
NXApp = [Application new];
if (ToPasteboard) pb = [Pasteboard new];
t = [[Text alloc] initFrame: &r];
if (!t) e("%s: can't create internal text object\n", av0), exit(1);
[t setMonoFont:NO];
o = NXOpenFile(folder(), NX_WRITEONLY);
if (i==ac) ac++;
for (; i<ac; i++) {
f = av[i]? NXMapFile(av[i], NX_READONLY) :
NXOpenFile(fileno(stdin), NX_READONLY);
if (!f) e("%s: couldn't open '%s'", av0, av[i]);
else {
l = [t textLength]; [t setSel:l:l];
[t replaceSelWithRichText:f];
NXClose(f);
}
}
[t calcLine];
l = [t textLength];
switch (WriteOutput){
Case ASCII: if (ToPasteboard){
[t setSel:0:l];
[t writeSelectionToPasteboard:pb types:types];
} else
[t writeText:o];
Case RTF: if (ToPasteboard){
[t setSel:0:l];
[t writeSelectionToPasteboard:pb types:types];
} else
[t writeRichText: o];
Case PS: {
NXCoord w, h;
[t getMinWidth:&w minHeight:&h
maxWidth:r.size.width maxHeight:1.0e38];
r.size.height = h;
}
w = [[Window alloc] initContent:&r
style:NX_TITLEDSTYLE
backing:NX_RETAINED
buttonMask:NX_CLOSEBUTTONMASK
defer:NO];
[t windowChanged:w];
[w setContentView:t];
r.origin.x = r.origin.y = 0.;
if (ToPasteboard)
[t writePSCodeInside:&r to:pb]; // no can do under 2.x
else
[t copyPSCodeInside:&r to:o];
}
NXClose(o);
exit(0);
}
---------------------------------------------------From: jupiter.fnbc.com!billb@uunet.uu.net (Bill Burcham)
OK Bill 1 here's a .subproj that contains an Obj-C class that you could easily use to solve the problem.
PrintRTF.subproj (the subprojects was included via NeXTMail, look on the archives for it)
---------------------------------------------------From: optilink.com!brad@uunet.uu.net (Brad Yearwood)
Unless you need literally a filter (something which can be run non-
interactively), you can run Microsoft Word (and a number of other Mac
applications) directly on your NeXT using the Executor package ($360) from:
Abacus Research & Development, Inc.
1650 University Blvd., NE
Albuquerque, NM 87102
If your document uses fonts not installed on your NeXT, printing will
do font substitution, and the output will be a bit ragged. I believe Right
Brain distributes Adobe fonts for the NeXT.
I've been using Executor with Word 4.00D for nearly a year with excellent
results. I use the wretchedly slow Mac only for final print (too lazy and
cheap to buy New Century Schoolbook font for my NeXT).
Brad Yearwood brad@optilink.com
Petaluma, CA
---------------------------------------------------From: nutmeg.cs.ntu.edu.au!malcolm@uunet.uu.net (Malcolm Caldwell)
This is a *ME TOO*!
I just found rtf2tex to day which with tex/dvips could do what you want.
>From A Readme that goes with the RTF reader package:
----------------------------------------------------
Robert Lupton (rhl@astro.princeton.edu) has an RTF -- TeX reader based
on Paul DuBois's RTF reader that you see before you. Eventually it
will be added to his RTF distribution, but while it is undergoing fast
evolution after its initial release you will need to get it
separately.
It is available by anonymous ftp from
astro.princeton.edu (128.112.24.1)
The file that you want is
pub/rtf2TeX.tar.Z
If you have problems, or enhancements, please send them to Robert.
---------------------------------------------------
From: mdixon@parc.xerox.com (Mike Dixon)
you can print an rtf file from the command line with
open -p <file>
note, however, that this simply asks Edit to do the printing, so
- you probably can't do this if you're not logged on at the console
- Edit will give you a wait cursor until it's done formatting the file
this will, however, allow you to print a batch of files:
foreach f (*.rtf)
open -p $f
end
--
email: bnixon@fnma.com (NeXT Mail Okay)
Bill Nixon, Senior Programmer Analyst, Advanced Technology
FannieMae, 3900 Wisconsin Ave NW, Washington, DC 22016 (202) 752-5468
Technical Details
Message-ID:
<1992Nov2.160443.6336@almserv.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!almserv!bnixonReferences:
<1992Oct30.045824.10992@almserv.uucp> <MALCOLM.92Nov2142214@nutmeg.cs.ntu.edu.au>Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.misc,comp.lang.postscript Path: arc1-ca.pugleaf.net!sparky!uunet!almserv!bnixon From: bnixon@fnma.com (Bill Nixon) Subject: Re: Looking for a Rich-Text Format (RTF) to PS converter Message-ID: <1992Nov2.160443.6336@almserv.uucp> Summary: Solutions Keywords: RTF, NeXT Sender: usenet@almserv.uucp Nntp-Posting-Host: loki Organization: FannieMae, Washington, DC References: <1992Oct30.045824.10992@almserv.uucp> <MALCOLM.92Nov2142214@nutmeg.cs.ntu.edu.au> Date: Mon, 2 Nov 1992 16:04:43 GMT Lines: 240