Re: Strange printing issue
Re: Strange printing issue
- Subject: Re: Strange printing issue
- From: Tom Bernard <email@hidden>
- Date: Tue, 06 Jul 2004 21:45:19 -0600
Andrew, you probably need the following lines in your NSPrintInfo setup,
along with setting the top and left margins:
[pi setHorizontallyCentered:NO];
[pi setVerticallyCentered:NO];
When I ran your code with these lines, my Epson Stylus C82 placed the text
at the top left of the page. When I removed these lines, the text was
centered on the page.
Another thought, do you want right and left margins of 0.0 and 0.0. Are
these valid inputs to the setLeftMargin and setRightMargin methods?
Sometimes, when you pass a message with invalid parameters, the message is
simply ignored, which would leave your view centered. I see also that you do
not set the top margin. Should you set it?
(When I ran your code with 0.0 for the margins, my printer placed the text
at the very top and left of the page; the top of the text and the left of
the text was clipped because the printer can only print to within about
1/10th inch of the edge of the page. So the Epson driver _will_ accept
margins of 0.0, but perhaps the Star driver needs margins of 0.1 or similar
to work.)
As for the tiny text, two thoughts: the bounds of the NSTextView need
adjustment, or the NSString returned by [transToPrint description] is
actually an NSAttributedString with font attributes specifying a tiny point
size.
May I propose an experiment:
Create a new file as an NSView subview and add it to your project (with
header) calling the object TestView.
TextView.h should need no change:
#import <AppKit/AppKit.h>
@interface TestView : NSView {
}
@end
Replace -drawRect: with the following -drawRect: method in TestView.m
- (void)drawRect:(NSRect)rect {
[[NSColor cyanColor] set]; // use blackColor if the printer does
not support color
NSFrameRect([self bounds]);
}
In the file where you implement your -printReceipt: method, add the
following line at the beginning of the file (with the other imports):
#import "TestView.h"
Add the following to your -printReceipt: method:
NSRect aRect = NSMakeRect(0.0, 0.0, 72.0, 72.0); // 72 points = 1 inch
TestView * testView = [[TestView alloc] initWithFrame:aRect];
Change the op allocation line to read
op = [NSPrintOperation printOperationWithView: testView];
run your application and print a receipt. You should print a 1 inch square
at the top left of the page if your margins are set correctly and centering
is turned off.
Best regards,
Tom Bernard
email@hidden
on 7/5/04 7:33 PM, Andrew Kinnie <email@hidden> wrote:
>
Message: 2
>
To: email@hidden
>
From: Andrew Kinnie <email@hidden>
>
Subject: Strange printing issue (again)
>
Date: Mon, 5 Jul 2004 12:52:22 -0400
>
>
I am still having strange issues getting my application to print
>
receipts to a receipt printer. I have the drivers installed, and it
>
does in fact print the receipt (based on the code below), but the text
>
is extremely tiny, and centered with huge (1 inch) margins on each
>
side. The printer paper width is 72mm, and is set for 0 margins, but
>
this doesn't seem to help.
>
>
This has been the problem for about a week now. Now, however, I seem
>
to have another problem... I have a text field in my app, and select
>
it, tell it to print, and I get the following in the console:
>
>
-[NSCFString setUpPrintOperationDefaultValues]: selector not recognized
>
-[NSCFString setUpPrintOperationDefaultValues]: selector not recognized
>
-[NSLanguageContext setUpPrintOperationDefaultValues]: selector not
>
recognized
>
-[NSLanguageContext setUpPrintOperationDefaultValues]: selector not
>
recognized
>
>
>
Any help for either of these two issues would be appreciated.
- (void)printReceipt:(Transaction *)transToPrint
{
NSPrintOperation *op;
NSRect rect = [self printAreaInScaledPaperCoordinates];
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
// NSFont *font = [NSFont userFixedPitchFontOfSize:10.0];
[printInfo setLeftMargin:0.0];
[printInfo setRightMargin:0.0];
[printInfo setBottomMargin:0.25];
NSTextView *view = [[NSTextView alloc] initWithFrame:rect];
// [view setFont:font];
[view insertText:[transToPrint description]];
op = [NSPrintOperation printOperationWithView:view];
[op setShowPanels:NO];
[op runOperation];
[view release];
[printInfo release];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.