Blog Archives

Cisco iOS Emulator Hardware and Software Simulations

Good article with introductory discussion:

Supported Hardware

Cisco 7200, Cisco 3600 series (3620, 3640 and 3660), 3700 series (3725, 3745) and 2600 series (2610 to 2650XM, 2691).


Dynagen/Dynamips (excellent choice and good for windows and *nix):

Boson (proprietary at least 100USD$):

pyios (not as much following as the other two):

View PDF in Objective-C Cocoa on Mac OS X using PDFKit

The code below has been tested and works clean on the latest version of Mac OS X 10.5 Leopard.

Since it applies to native Mac OS X, and not iOS, porting this to work on iPhone/iPad is a bit different, however, it is overall very easy once you have the base concept and the main functionality below is the same.

Note: If you create this as a blank new project and are new to PDFKit, first make sure to add the Quartz framework to your project. (ref)

First, create a class (and corresponding header) to utilize the PDF. (CODE IS CASE SENSITIVE)


#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@interface PDFImageView : NSImageView

- (void) loadFromPath: (NSString *) path;



#import "PDFImageView.h"
#import "DraggableScrollView.h"

@implementation PDFImageView

- (NSPDFImageRep *) pdfRep
return [[[self image] representations] lastObject];

- (void) loadFromPath: (NSString *)path
NSPDFImageRep *pdfRep;
NSImage *pdfImage;
NSRect frame;

pdfRep = [NSPDFImageRep imageRepWithContentsOfFile:path];
pdfImage = [[[NSImage alloc] init]autorelease];
[pdfImage addRepresentation: pdfRep];

frame = [pdfRep bounds];
frame.size.height *= [pdfRep pageCount];

[self setImage: pdfImage];

[super setFrame: frame];

if ([self isFlipped])
    [self scrollPoint: NSMakePoint(0,0)];
else {
    [self scrollPoint: NSMakePoint(0,frame.size.height)];

- (void) drawRect: (NSRect) rect
NSPDFImageRep *rep;
int pageCount, pageNumber;
NSRect onePageBounds;

[[NSColor whiteColor] set];
NSRectFill (rect);

rep = [self pdfRep];
pageCount = [rep pageCount];

for (pageNumber=0;pageNumber<pageCount;pageNumber++)
onePageBounds = [self rectForPage: (1+pageNumber)];
if (! NSIntersectsRect(rect, onePageBounds))

[rep setCurrentPage: pageNumber];
[rep drawInRect: onePageBounds];

- (void) mouseDown: (NSEvent *) theEvent
NSScrollView *scrollView;
scrollView=[self enclosingScrollView];
if ([scrollView respondsToSelector: @selector(dragDocumentWithMouseDown:)])
[(DraggableScrollView*)scrollView dragDocumentWithMouseDown: theEvent];
else {
[super mouseDown: theEvent];

- (void) setFrameSize: (NSSize) newSize
NSSize PDFsize;
float correctHeight;

PDFsize = [[self pdfRep] bounds].size;
correctHeight = [[self pdfRep] pageCount] * (PDfsize.height/PDFsize.width) * newSize.width;
correctHeight = ceil(correctHeight);

if (abs (correctHeight - newSize.height) > 3.0)
newSize.height = correctHeight;

[super setFrameSize: newSize];

- (BOOL) knowsPageRange: (NSRangePointer) range
range->length=[[self pdfRep] pageCount];

return YES;

- (NSRect) rectForPage: (int) pageNumber
NSPDFImageRep *rep;
int pageCount;
NSRect result;

rep = [self pdfRep];
pageCount = [rep PageCount];

result = [rep bounds];
if (! [self isFlipped])
result = NSOffsetRect(result,0.0,(pageCount-1)*result.size.height);

if ([self isFlipped])
result = NSOffsetRect (result,0.0,(pageNumber-1)*result.size.height);
else {
result = NSOffsetRect (result,0.0,-(pageNumber-1)*result.size.height);

return result;

This class is courtesy of Apple DC and used in the above PDFViewer class. You shouldn’t have to really do anything additional in this one, just plug and play. Allows user to scroll with mouse. I removed alot of comments for brevity to minimize code lines. See Apple reference at bottom for full source and additional info.


#import <Cocoa/Cocoa.h>
@interface DraggableScrollView : NSScrollView
- (BOOL) dragDocumentWithMouseDown:
    (NSEvent *) theEvent;


#import "DraggableScrollView.h"
@implementation DraggableScrollView
+ (NSCursor *) dragCursor
    static NSCursor *openHandCursor = nil;
    if (openHandCursor == nil)
        NSImage     *image;
        image = [NSImage imageNamed: @"fingerCursor"];
        openHandCursor = [[NSCursor alloc] initWithImage: image
            hotSpot: NSMakePoint (8, 8)]; // guess that the center is good
    return openHandCursor;
- (BOOL) canScroll
    if ([[self documentView] frame].size.height > [self documentVisibleRect].size.height)
        return YES;
    if ([[self documentView] frame].size.width > [self documentVisibleRect].size.width)
        return YES;
    return NO;
- (void) tile
    [super tile];
    //  If the user can scroll right now, make our document cursor reflect that.
    if ([self canScroll])
        [self setDocumentCursor: [[self class] dragCursor]];
        [self setDocumentCursor: [NSCursor arrowCursor]];
//  dragDocumentWithMouseDown: -- Given a mousedown event, which should be in
//  our document view, track the mouse to let the user drag the document.
- (BOOL) dragDocumentWithMouseDown: (NSEvent *) theEvent // RETURN: YES => user dragged (not clicked)
    NSPoint         initialLocation;
    NSRect          visibleRect;
    BOOL            keepGoing;
    BOOL            result = NO;
    initialLocation = [theEvent locationInWindow];
    visibleRect = [[self documentView] visibleRect];
    keepGoing = YES;
    while (keepGoing)
        theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask];
        switch ([theEvent type])
            case NSLeftMouseDragged:
                NSPoint newLocation;
                NSRect  newVisibleRect;
                float   xDelta, yDelta;
                newLocation = [theEvent locationInWindow];
                xDelta = initialLocation.x - newLocation.x;
                yDelta = initialLocation.y - newLocation.y;
                //  This was an amusing bug: without checking for flipped,
                //  you could drag up, and the document would sometimes move down!
                if ([[self documentView] isFlipped])
                    yDelta = -yDelta;
                //  If they drag MORE than one pixel, consider it a drag
                if ( (abs (xDelta) > 1) || (abs (yDelta) > 1) )
                    result = YES;
                newVisibleRect = NSOffsetRect (visibleRect, xDelta, yDelta);
                [[self documentView] scrollRectToVisible: newVisibleRect];
            case NSLeftMouseUp:
                keepGoing = NO;
                /* Ignore any other kind of event. */
        }                               // end of switch (event type)
    }                                   // end of mouse-tracking loop
    return result;

And now for the main class of our application which will use the above PDFImageView class and bind/map to our interface.


#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

@interface MainView : NSDocument {
IBOutlet PDFView *_pdfView;



#import "MainView.h"

@implementation MainView

//will load PDF from local filesystem in current path as .app is launched from
NSFileManager *filemgr;
filemgr = [[NsFileManager alloc]init];

NSString *currentpath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingPathExtension] stringByDeletingLastPathcomponent];

//[Util MessageBox:@"currentpath":currentpath]; //SEE MY REFERENCE BELOW FOR DEBUG UTILITY CLASS

NSString *fileName = [NSString stringWithFormat:@"%@/%@/",currentpath,@"filename.pdf"];
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:fileName]];
[_pdfView setDocument: pdfDoc];


Apple DC,
“Show Dialog Message Box in Objective-C Cocoa”,
Google CodeSearch (“_pdfView”),

Mac Sudo Password

Note: “Sudo” is short for “Substitute User Do” or “Superuser Do”

This may come as a shock if you’re new to Mac and ever used a *nix system before.. but the sudo password, is your password! If you’re administrator anyway, if not, ask your *rents, instructor or local admin to help you out. 😉

/etc/sudoers contains the permissions for who can use it, and once you have it, it is very powerful indeed.

If for any reason you need to have access to the full root account, this is actually not enabled on a Mac by default, for good reason.

To Enable Root User (see Apple KB below for reference):
1) From the Apple menu choose System Preferences….
2) From the View menu choose Accounts.
3) Click on the lock and authenticate with an administrator account.
4) Click Login Options….
5) Click the “Edit…” or “Join…” button at the bottom right.
6) Click the “Open Directory Utility…” button.
7) Click the lock in the Directory Utility window.
8) Enter an administrator account name and password, then click OK.
9) Choose Enable Root User from the Edit menu.
10) Enter the root password you wish to use in both the Password and Verify fields, then click OK.

Apple KBase,
Wikipedia (Sudo),
Wikipedia (SU),

Mac OS X Quick Reference

After writing multiple articles on a single subject, I decided to consolidate the links into a single point of reference. All links below are internal to my site and do not redirect outside of my blog.

(Tested on 10.6 Leopard.)

enable root user, or mac sudo password and settings,

install macports and/or issues with install and configuring,

converting iso images with bchunk, (discussed in my article on creating hybrid discs with toast),

open textedit from command line,

vi keyboard shortcuts Quick Reference,