• 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
EPS NSPrintOperation not working as set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EPS NSPrintOperation not working as set


  • Subject: EPS NSPrintOperation not working as set
  • From: Warwick Hall <email@hidden>
  • Date: Mon, 30 Apr 2007 16:55:37 +1000

i know i have bugged the list alot over the last few days, but your help is greatly appreciated.

lately i have had trouble getting NSPrintOperation to work correctly.

background: i am writing a command line tool that renders web HTML in a webView and prints the result to a postscript file (via nsdata, see below).

problem: NSPrintInfo ignores and alters my settings for no apparent reason. even when the NSPrintInfo seems to initialize correctly, NSPrintOperation ignores it! for instance, using NSLog ( [printInfo description] ) and looking at the final output i can deduce the following:

1) setting the margins is acceptable to NSPrintInfo, but NSPrintOperation pays no attention.
2) same with vertical and horizontal pagination.
3) same with page type and page size.
4) setting the job type to NSPrintSaveJob will be accepted by NSPrintInfo, but get this: it erases the path i give it from the dictionary. where is the logic in that???? moreover it refuses to allow me to use the printOperation: ... toPath:, instead i have to use the toData: message, and use the [data writeToFile:atomically:] to get it to the filesystem. i am sorry, but there must be some kind of bug there!


Finally, it appears that all printOperation does in the end is print the visible rect of the webView. ie it completely ignores all printInfo settings like pagination and margins, and all the others.

--BEGIN--
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import "webFrameDelegate.h"

void gbGenOrder( NSString * iCid, NSString * iWid, NSString * iRid, NSString * iRdate,
NSString * iOutput )
{
int loop = 0;
NSString * theHtml = @"<html><body>H<br/>e<br/>l<br/>l<br/>o<br/ >W<br/>o<br/>r<br/>l<br/>d<br/>!<br/>Hello 0<br/>H<br/>e<br/>l<br/ >l<br/>o<br/>W<br/>o<br/>r<br/>l<br/>d<br/>!<br/>Hello 1<br/>H<br/ >e<br/>l<br/>l<br/>o<br/>W<br/>o<br/>r<br/>l<br/>d<br/>!<br/>Hello 2<br/>H<br/>e<br/>l<br/>l<br/>o<br/>W<br/>o<br/>r<br/>l<br/>d<br/>! <br/>Hello 3<br/>H<br/>e<br/>l<br/>l<br/>o<br/>W<br/>o<br/>r<br/>l<br/ >d<br/>!<br/>Hello 4<br/>H<br/>e<br/>l<br/>l<br/>o<br/>W<br/>o<br/ >r<br/>l<br/>d<br/>!<br/>Hello 5<br/>H<br/>e<br/>l<br/>l<br/>o<br/ >W<br/>o<br/>r<br/>l<br/>d<br/>!<br/>Hello 6<br/>H<br/>e<br/>l<br/ >l<br/>o<br/>W<br/>o<br/>r<br/>l<br/>d<br/>!<br/>(THE END!)</body></ html>";


  NSRect bounds = NSMakeRect( 0.0, 0.0,
                              595.200012, 841.919983 );

NSWindow * theWindow =
[[NSWindow alloc] initWithContentRect : bounds
styleMask : NSBorderlessWindowMask | NSUnscaledWindowMask
backing : NSBackingStoreNonretained
defer : NO
screen : nil];


  [NSGraphicsContext setCurrentContext :
    [NSGraphicsContext graphicsContextWithWindow : theWindow]];

  NSRunLoop * theRunLoop = [NSRunLoop currentRunLoop];

  WebView * webView =
    [[WebView alloc] initWithFrame : bounds
        frameName : nil
        groupName : nil];

  webFrameDelegate * delegate = [[webFrameDelegate alloc] init];

  [webView setFrameLoadDelegate : delegate];
  [[[webView mainFrame] frameView] setAllowsScrolling : NO];
  [[theWindow contentView] addSubview : webView];

  [webView lockFocus];
  [[webView mainFrame] loadHTMLString : theHtml baseURL : nil ];
  [webView unlockFocus];

BOOL isRunning = YES;
while( isRunning )
{
isRunning =
[theRunLoop runMode : NSDefaultRunLoopMode
beforeDate : [NSDate dateWithTimeIntervalSinceNow : 0.5]];


    if( isRunning )
      isRunning = [delegate isRunning];
  }

  NSPrintInfo * printInfo = nil;
  NSPrintInfo * sharedInfo = nil;
  NSPrintOperation * printOp = nil;
  NSMutableDictionary * printInfoDict = nil;
  NSMutableDictionary * sharedDict = nil;

  sharedInfo = [NSPrintInfo sharedPrintInfo];
  sharedDict = [sharedInfo dictionary];

printInfoDict = [NSMutableDictionary dictionaryWithDictionary : sharedDict];

  [printInfoDict setObject : @"iso-a4"
                    forKey : NSPrintPaperName];

  [printInfoDict setObject : [NSValue valueWithSize :
                               NSMakeSize( 595.200012, 841.919983 ) ]
                    forKey : NSPrintPaperSize];

  [printInfoDict setObject : [NSNumber numberWithFloat : 1.0]
                    forKey : NSPrintScalingFactor];

  NSNumber * marginPoints = [NSNumber numberWithFloat : 10.0];
  [printInfoDict setObject : marginPoints
                    forKey : NSPrintTopMargin];

  [printInfoDict setObject : marginPoints
                    forKey : NSPrintRightMargin];

  [printInfoDict setObject : marginPoints
                    forKey : NSPrintLeftMargin];

  [printInfoDict setObject : marginPoints
                    forKey : NSPrintBottomMargin];

  [printInfoDict setObject : [NSNumber numberWithBool : YES]
                    forKey : NSPrintAllPages];

  [printInfoDict setObject : NSPrintSaveJob
                    forKey : NSPrintJobDisposition];

  [printInfoDict setObject : iOutput
                    forKey : NSPrintSavePath];

  printInfo = [[NSPrintInfo alloc] initWithDictionary : printInfoDict];

  [printInfo setHorizontalPagination : NSAutoPagination];
  [printInfo setVerticalPagination : NSAutoPagination];
  [printInfo setHorizontallyCentered : YES];
  [printInfo setVerticallyCentered : NO];

  NSMutableData * theData = [NSMutableData data];
  printOp = [NSPrintOperation EPSOperationWithView : webView
                                        insideRect : bounds
                                            toData : theData
                                         printInfo : printInfo];
  [printOp setShowPanels : NO];

  [printOp runOperation];
  [printOp deliverResult];

  [theData writeToFile : iOutput atomically : NO];

  [theHtml release]; theHtml = nil;
  [delegate release]; delegate = nil;
}
--END--
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSTask vs. special characters
  • Next by Date: Re: Object Hierarchies
  • Previous by thread: NSScrollView contentSize bug?
  • Next by thread: adjusting subviews : NSTextView in NSScrollView in NSTabViewItem
  • Index(es):
    • Date
    • Thread