[comp.sys.next] Printing a postscript file and text from an application

jacob@gore.com (Jacob Gore) (10/08/89)

While it is indeed quite easy to print things as they appear on the screen
(using -printPSCode: methods of Window and View), I can't figure out how to
print arbitrary (long) text from an application.  Or, for that matter, even
a Postscript file.  Let me start with the latter.

I have a conforming Postscript file which I want to print from within my
application, using a PrintPanel (so I don't want to just spawn an 'lpr file'
command).

Here is what I tried:

    #import <appkit/Application.h>
    #import <dpsclient/dpsclient.h>
    #import <stdio.h>
    {
	DPSContext printContext;
	char buffer[BUFSIZ];		 // BUFSIZ defined in <stdio.h>
	size_t charCount;
        char tmpFileName[] = "/tmp/blah.ps";

	printContext = [[NXApp printInfo] context];
        DPSSetContext(printContext);
	[self openSpoolFile:tmpFileName];
	[self beginPSOutput];
	while ((charCount = fread(buffer, sizeof(char), BUFSIZ, file)) > 0) {
	    DPSWritePostScript(printContext, buffer, charCount);
	}
	[self endPSOutput];
	[self spoolFile:tmpFileName];
        DPSSetContext([NXApp context]);
    }

Is this the right approach in the first place?  If not, what is?  If yes,
then why do I always get access violation during the -openSpoolFile: call?


My second question concerns printing of the following contents of a panel:
its title, a TextField, and the a Text (which happens to be a docView of a
ScrollView).  I can't just use the panel's -printPSCode: because I don't
want a picture of the panel.  I want the printed document to contain the
title, followed by the contents of the textField, followed by the contents
of the text.

What's the proper way to do this?  I don't even get satisfactory results
printing the text alone -- sending the text object -printPSCode: results in
a document where the right margin steps on the text (the ends of many lines
get chopped off).  I tried playing with -setMarginLeft:right:top:bottom:,
but I did not notice any effect on the result.


Jacob
--
Jacob Gore		Jacob@Gore.Com			boulder!gore!jacob