• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Printing issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing issues


  • Subject: Re: Printing issues
  • From: billmonk <email@hidden>
  • Date: Fri, 22 Apr 2005 20:16:48 -0500


won't know what different receipt printer manufacturers may be
calling their custom receipt page sizes.

There's no PPD, but a hexdump of the StarPM file (inside the StarPM.plugin bundle) reveals interesting names such as
"104mm x Long Receipt" and "72mm x Long Receipt" etc.


Tiger may change things, but NSPrinter doc currently says "An NSPrinter object describes a printer’s capabilities as defined in its PPD file". If there's no PPD, and you want fine control, I think you may be stuck using Carbon Print Manager, or the print dialogs (which are implemented in Carbon PM).

The code below enumerates all printers and their paper names/sizes in Carbon, then tries to do a few things with the info in Cocoa.

On printers here, Carbon reports accurate sizes for many papers for which [printer pageSizeForPaper: paperName] often return a zero size. The method is documented to return sizes for paper names **in the PPD**. "Possible values for paperName are contained in the printer’s PPD file...Returns a zero size if paperName is not recognized, or its entry in the PPD cannot be parsed."

This may explain why setting the receipt pagesize doesn't programmatically doesn't work right. The print dialogs are built on top of Carbon and are correctly extracting the paper names/sizes from the drivers, just as the code below does. But when trying to do the same thing programmatically in Cocoa, some methods silently fail because there's no PPD, so you get a default paper size which is too big for the receipt printer, and it gets scaled down to 72mm wide...

Just to take a couple of examples from a run here, (HP printer using PDE plugin files like the Star printers, no PPD)
3x5 Index
Carbon says it's 216.000000 x 360.000000
[printer pageSizeForPaper:paperName] says it's 0 x 0
[sharedPrintInfo paperSize] says it's 612.000000 x 792.000000 // close to Letter


#10 Envelope
Carbon says  297.000000 x 684.000000
printer pageSizeForPaper:paperName] says 0 x 0
[sharedPrintInfo paperSize]  says 612 x 792.000000  // close to Letter

Other small papers on 5 different printers here show the same pattern, with an accurate size from Carbon but a bogus "letter" size when the paper name is handed to Cocoa. I'm no Cocoa printing expert. But this looks like it might explain a lot about the receipt printing problems.

//
// Get name and size of every paper on every printer;
// Use the info in a few Cocoa methods and log the results.
//
OSErr EnumeratePaperInfo(void)
{
PMPrintSession printSession;
OSStatus err = PMCreateSession( &printSession );

// get a CFArray of PMPrinter structs
CFArrayRef	printerList;

err = PMServerCreatePrinterList( kPMServerLocal,
&printerList);

if ( err == noErr ) {
int i;
int numPrinters = CFArrayGetCount(printerList);
for ( i = 0; i < numPrinters; i++ ) {
// get CFArray of PMPaper, a list of papers available for this printer.
CFArrayRef paperList;
PMPrinter thisPrinter = (PMPrinter)CFArrayGetValueAtIndex( printerList, i );

NSLog( @"=========================Printer: %@==============", PMPrinterGetName( thisPrinter ) );

err = PMPrinterGetPaperList( thisPrinter, &paperList); // requires 10.3 or better
if ( err == noErr ) {
int j;
int numPapers = CFArrayGetCount(paperList);
for ( j = 0; j < numPapers; j++ ) {

PMPaper thisPaper = (PMPaper)CFArrayGetValueAtIndex( paperList, j );

CFStringRef paperName;
err = PMPaperGetName( thisPaper, &paperName );

double paperHeight;
err = PMPaperGetHeight( thisPaper, &paperHeight );

double paperWidth;
err = PMPaperGetWidth( thisPaper, &paperWidth );

NSLog( @"\tPaper name: %@", (NSString *)paperName );
NSLog( @"\t\twidth = %f", paperWidth );
NSLog( @"\t\theight = %f", paperHeight );


// try to use the printer and paper size found via Carbon to do some things in Cocoa
// and compare the results.
NSPrinter *printer = [NSPrinter printerWithName: (NSString *)PMPrinterGetName( thisPrinter )];
NSSize size = [printer pageSizeForPaper: (NSString *)paperName];
// size should match that found via Carbon, but is often and empty rect
if ( size.width != 0 || size.height != 0 ) {
NSLog( @"\t\t\t[printer imageRectForPaper:] says width = %f, height = %f", size.width, size.height );
} else {
NSLog( @"\t\t\t[printer imageRectForPaper:] returned empty size for this paper.");
}


// setPaperName: should recalc the print rect to match new paper. // docs: "This method may change either the size or orientation for consistency." [[NSPrintInfo sharedPrintInfo] setPaperName:(NSString *)paperName];
size = [[NSPrintInfo sharedPrintInfo] paperSize]; // paperSize frequently returns a much different size from the correct size Carbon reports.
if ( size.width != 0 || size.height != 0 ) {
NSLog( @"\t\t\t[sharedPrintInfo paperSize:] says width = %f, height = %f", size.width, size.height );
} else {
NSLog( @"\t\t\t[sharedPrintInfo paperSize:] returned empty size for this paper.");
}


NSLog( @"\n" );
}
}
}
}
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Printing issues
      • From: Dave Camp <email@hidden>
  • Prev by Date: Re: Java vs. Objective-C for Cocoa
  • Next by Date: Do tracking rectangles move along with their views?
  • Previous by thread: Re: Printing issues
  • Next by thread: Re: Printing issues
  • Index(es):
    • Date
    • Thread