More... apparently not-so-simple printing issues

  • I have still not been able to sort out the receipt printer issues.  I
    have a Star TSP 613 printer, which prints using a sample they created
    in OS X using Carbon, (but which prints out their sample receipt).  I
    realize I could try and use Carbon with Cocoa, but I feel as a Cocoa
    guy, I should use cocoa's methods.  However, I can't get the thing to
    print out a string of text in a legible fashion using cocoa.

    Reading the Apple docs, apparently, I need to create an
    NSPrintOperation, with a printInfo, and a view and then tell the
    operation to run.  Seems simple enough, but as I simply want to print
    our a sting of text, and I don't need to have it appear on the UI, it
    seems strange.  Nonetheless, I tried, but unfortunately, the text is
    extremely small and indented.  I therefore set the font, and margins,
    and it's still extremely small.

    I don't know what else to do.

    The thing prints, but it is so small, it is illegible.  Star, the
    printer manufacturer, says they can't help me with Cocoa.

    This is quite frustrating.

    For your edification (whatever that means), this is the complete method
    as I have it so far.  All I want to do it dump a string of text to a
    printer which prints fixed width fonts best up to a width of 72mm:

    - (void)printReceipt:(Transaction *)transToPrint
    {
    NSPrintOperation *op;
    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:[printInfo
    imageablePageBounds]];
    [view setFont:font];
    [view insertText:[transToPrint descriptionSummary]];

    op = [NSPrintOperation printOperationWithView:view];

        [op setShowPanels:NO];
        [op runOperation];
    [view release];
    [printInfo release];
    }

    If anyone has any suggestions, I'd be happy to hear them.

    Andrew
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Andrew,

    On Jun 30, 2004, at 12:24 PM, Andrew Kinnie wrote:

    > I have still not been able to sort out the receipt printer issues.  I
    > have a Star TSP 613 printer, which prints using a sample they created
    > in OS X using Carbon, (but which prints out their sample receipt).  I
    > realize I could try and use Carbon with Cocoa, but I feel as a Cocoa
    > guy, I should use cocoa's methods.  However, I can't get the thing to
    > print out a string of text in a legible fashion using cocoa.
    >
    > Reading the Apple docs, apparently, I need to create an
    > NSPrintOperation, with a printInfo, and a view and then tell the
    > operation to run.  Seems simple enough, but as I simply want to print
    > our a sting of text, and I don't need to have it appear on the UI, it
    > seems strange.  Nonetheless, I tried, but unfortunately, the text is
    > extremely small and indented.  I therefore set the font, and margins,
    > and it's still extremely small.
    >
    > I don't know what else to do.
    >
    > The thing prints, but it is so small, it is illegible.  Star, the
    > printer manufacturer, says they can't help me with Cocoa.
    >
    > This is quite frustrating.
    >
    > For your edification (whatever that means), this is the complete method
    > as I have it so far.  All I want to do it dump a string of text to a
    > printer which prints fixed width fonts best up to a width of 72mm:
    >
    > - (void)printReceipt:(Transaction *)transToPrint
    > {
    > NSPrintOperation *op;
    > 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:[printInfo
    > imageablePageBounds]];
    > [view setFont:font];
    > [view insertText:[transToPrint descriptionSummary]];
    >
    > op = [NSPrintOperation printOperationWithView:view];
    >
    > [op setShowPanels:NO];
    > [op runOperation];
    > [view release];
    > [printInfo release];
    > }
    >
    > If anyone has any suggestions, I'd be happy to hear them.

    Just a thought -- not sure if it will be useful.  (My experience is
    limited to having dealt with this recently in a document-based app, and
    doing some playing around with things to customize my print job.)

    First, are you sure that the imageablePrintBounds are appropriate?
    That is, could they be too big at this point, and what you're seeing is
    just scaling because the view is set up as being larger than the page
    ends up?

    Given the description of the imageablePageBounds method, it sounds like
    this is at least a possibility.  Because you have non-zero margins, it
    is necessarily the case that the view will have to be scaled to fit
    into the area enclosed by the margins unless the imageable area is
    smaller than the page minus the margins.  Depending on the top margin
    and/or the overall size, this could be a lot.

    Instead of imageablePageBounds, could you want to try something like
    the following (NOTE, borrowed from _Cocoa Progamming_ by Anguish, Buck
    and Yacktman, possibly directly, although I can't find it now):

    - (NSRect) printAreaInScaledPaperCoordinates;
    {
        NSPrintInfo *pi = [[NSPrintOperation currentOperation] printInfo];
    NSSize paperSize = [pi paperSize];
    float bottomMargin = [pi bottomMargin];
    float leftMargin = [pi leftMargin];
        float pageHeight = paperSize.height - [pi topMargin] - bottomMargin;
        float pageWidth = paperSize.width - leftMargin - [pi rightMargin];

    float scale = [self printingScale];
    // this just gets [[[pi dictionary] objectForKey:NSPrintScalingFactor]
    floatValue]
    // and wraps this to make sure we get a valid response or default to
    1.0.

        return NSMakeRect(leftMargin / scale, bottomMargin / scale,
    pageWidth / scale, pageHeight / scale);
    }

    Like I said, this is just a thought.  It may not be all that valuable,
    but maybe will get you headed in the right direction.

    chris
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.