David Gelphman's Blog

1 Comment

Adding Save PDF to iBooks Support to Your Application

As I wrote recently, the ability to create a PDF document from an application’s printed content is one of my favorite features that Apple added in iOS 9. This feature leverages the printing system so that if your application can print, a user will also be able to use the new “Save PDF to iBooks” feature. Well, almost.

The key is that your application needs to offer printing by using Apple’s “Share Sheet”, instead of using the older method of using a UIPrintInteractionController. And unfortunately, as of my writing this, all of Apple’s sample code demonstrating how to implement printing in an iOS application uses the UIPrintInteractionController method of presenting printing to the user.

I ran into this recently when I emailed the developers of one of my favorite iOS applications and suggested they add support for the “Save PDF to iBooks” to their app. After all, the app already supported the Share Sheet for a number of tasks other than printing but it supported printing using the old UIPrintInteractionController. The developer was kind enough to reply to my suggestion with interest, but the response I got was: “I’d like to but I don’t know how to do that.”

Poking around Apple’s developer site, I found the handy page AirPrint for Developers. It includes a link to the 2014 WWDC session on AirPrint (there was none in 2015) which is a great presentation with tons of info for app developers getting started with printing on iOS. And the AirPrint for Developers page has four links to sample code that implement printing in various ways. Unfortunately none of these samples implement the Share Sheet method of printing.

So I grabbed one of Apple’s samples and updated it. I started with one that I myself wrote (long ago) at Apple. It demonstrates how to print content from a WebView in both a basic way and also by using some fancier techniques to add more control to the layout of content on the printed pages. Updating it to use the Share Sheet is pretty straightforward.

The only substantive change needed to make the sample app use the share sheet is to take out the use of the UIPrintInteractionController from the sample and replaced it with the use of a UIActivityViewController. This controller takes an array of “Activity Items” as part of its initialization. When the controller is presented it determines what activities (or actions) can be taken on those activity items and allows the user to choose from those actions.

The UIActivityViewController determines that printing is a supported activity if the activity items array contains both an object of the UIPrintInfo class and also a source of print data. The source of print data can be a printing item or items (e.g. a photo or photos), a UIPrintFormatter object, or a UIPrintPageRenderer subclass. For the original sample code, the source of print data was a UIPrintPageRenderer subclass that the code created and assigned to the myRenderer local variable. For fun in the new code I also added an NSURL corresponding to the URL of the web page the user is visiting. This allows the Share Sheet to show more actions for the sample app than just those associated with printing. Once the UIActivityViewController is created, all that is needed is to present it and UIKit does the rest. I mostly stole the code to present the activity view controller from this sample.

Here’s the updated code snippet that replaces the old usage of the UIActivityViewController in the original sample: 

NSURL *url = [NSURL URLWithString:[self.urlField text]];
NSArray *activityItemsArray = 
  [NSArray arrayWithObjects: myRenderer, printInfo, url, nil];
UIActivityViewController *activityViewController =
  [[UIActivityViewController alloc]

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  //iPad, present the view controller inside a popover
    self.activityPopover =
      [[UIPopoverController alloc]
  if (![self.activityPopover isPopoverVisible]) {
    //Dismiss if the button is tapped while pop over is visible
    [self.activityPopover dismissPopoverAnimated:YES];
 //iPhone, present activity view controller as is
 [self presentViewController:activityViewController animated:NO completion:nil];

Running the modified app on an iPad and touching the action icon brings up the Share Sheet instead of the Printing UI directly (as it would have if I’d not modified the original sample). From there you can see that both the Print icon as well as the “Save PDF to iBooks” icon appears on the Share Sheet. And both behave as expected! 

Operation Mincemeat

If you’ve already got printing working in your app, now’s the time to update to using the Share Sheet method instead of the older method. Without a lot of extra work on your part, users get a great new option to save your application’s content in a print ready format. And if you’ve not added printing to your application to date, the “Save PDF to iBooks” feature provides yet another reason to do so.


1 Comment

Save PDF to iBooks

New in iOS 9 is the ability to save web pages as a PDF document to iBooks. It is a feature that is near and dear to my heart, in part because it is the last major feature I worked on at Apple before I left in early 2013.

What users of iOS 9 may notice is that Safari offers a new item in the Share Sheet: “Save PDF to iBooks”. They may think of this as a Safari specific feature.

iOS 9 Share Sheet


But the Photos app also allows this, as will every iOS app that presents printing using the iOS “Share Sheet” (in iOS programming parlance, using an ActivityViewController). If an app can print via the Share Sheet then “Save PDF to iBooks” automatically appears as well.

During my career at Apple I worked primarily on the printing subsystems of Mac OS X and iOS. Much of that work was on the software plumbing needed for users to print on paper. But a portion of that work was enabling the ability to produce a PDF file corresponding to what otherwise would have been printed output. Save as PDF from the print dialog was part of OS X since version 10.0 shipped in 2001.

When creating the printing system for iOS, allowing for the ability to create a PDF reproduction of the results of printing was a goal of the design from the beginning. To me it seemed almost more important to allow users to capture content to store on their device to take with them (or email or whatever) than it was to produce pieces of paper. The design of the printing system allowed for it but the user facing feature was left out. So in the summer of 2012 I worked on an early implementation of what is now shipping. And I’m thrilled that it’s now out.

Executives at Apple talk about the desire to “surprise and delight our users”. Well I experienced that firsthand when I got a notification from Apple’s “Tips” app on my iPhone soon after updating to iOS 9. For me the (ironic) surprise was that the tips app was telling me about a feature that I worked on. And I was delighted to see that it was finally shipping. 

Save PDF to iBooks Tip

1 Comment

The Turkey Drumstick

That’s not a turkey drumstick! That’s the cover of my book!

I never thought I’d be thanking Apple product marketing for something related to my book on programming Quartz graphics. Without their “help”, the book Programming with Quartz that I wrote with Bunny Laden would have been published without our names as authors. Instead it would have listed “Apple” as the author. But thanks to a cranky person in Apple product marketing, our names are there instead.

From the very beginning of the book project there was no question: our names would never be on the book. Apple had a firm policy, instituted by Steve Jobs when he returned as iCEO, that no individual names would be on Apple products, including any Apple publications. The author of our book would be “Apple” and our names would not appear in any form. There would be author bios on the back of the book but they would omit our names.

I should mention that our publisher, Morgan Kaufmann, had already done a number of books with Apple. They hated the fact that these books were published with “Apple” as the author and that the true author names were not known. To them it was extremely valuable to have real people’s names on their publications. But they wanted to do business with Apple and those were the terms.

Writing this book was my crazy idea, I started it with this understanding, and I had absolutely no problem with not having my name on it. I was writing this book for software developers use, not for personal glory. I was (and still am) passionate about the fact that 3rd party developers need good introductory and reference documentation and I was determined to do what I could to help provide that.

While our names weren’t going to be on the book, late in the project I had an idea how we could have an easter egg in the book so that we weren’t totally anonymous. After all, this was a book about graphics! In the chapter “Image Masking” there was a code sample and accompanying graphic that showed how to draw color through 1-bit image masks using Quartz. We needed images for the graphic so I thought we might take the opportunity to sneak us in.  


By October 2005 we had finished the process of writing the book, dealing with copy- and proof-reading edits, processing the graphics, struggling with image rights issues, and handling a great many other details related to the book. The book was ready. The only thing remaining was to get final approval of the book’s cover from product marketing. Proposals for that artwork had been created by the publisher and the final selection had been made with the help of talented artists in Apple publications. This final approval seemed like a formality.

But then came the email message:

From: xxx <xxx@apple.com>
Date: October 12, 2005, 6:56:52 AM PDT
To: David Gelphman <gelphman@apple.com>
Cc: “<various@apple.com>”
Subject: Re: Need Approval for Front Cover of Morgan Kaufmann Book…

I can’t really tell what image is being used on the cover (blured drum stick?), but I don’t think this cover is really up to our standards. Is there someone in GD who can take a look and help out here?

No, that was not a “blured drum stick”, it was a crystal, a Quartz crystal. None of us could see the “blured drumstick”, even after drinking heavily (not really), taking massive quantities of drugs (not really), and more squinting than we thought possible (really). After we got this email everyone involved jokingly referred to the graphic on the cover as the “turkey drumstick”.

This helpful fellow high up in product marketing caused everything to come to a screeching halt. Of course we had been working with someone in GD (Graphic Design) and they were on board with the proposed cover. But this one person in product marketing was saying that this book had Apple’s name on it which made it an Apple product and in their opinion the cover reflected poorly on Apple.

At this point the publisher pushed back like crazy. They had a schedule for the book to be published and everything was ready. But now there was a huge roadblock that was holding things up. This was their design, so obviously they were happy with it. This was all an Apple problem. Should the design of the cover be done from scratch? How long was it going to take before “Apple” was happy with a new design? They had had plenty of previous experience with the lengthy process of getting things done with Apple.

Ultimately the proposed solution was to remove “Apple” as the author of the book and have the real author’s names appear. This would make product marketing happy since the book would no longer be an “Apple” product. The publisher was thrilled about this possible outcome. They definitely wanted our names on the book.

I don’t know for certain but I believe that Bertrand Serlet was the one to propose this solution to Steve Jobs. Amazingly Steve agreed to OK a one time exception to the Apple policy. (I would have loved to be a fly on the wall in that meeting!) The crisis was over and the book was published soon after.

Of course I was ecstatic about the result. It was totally unexpected and, as you can imagine, quite satisfying. I was extremely proud of the work I’d done on the book and was thrilled to have my name with Bunny’s on the cover. I still feel that way today, almost 9 years later.

And one more thing: Thanks again Rich.



Leave a comment


Today it was announced that the Macworld print magazine is being discontinued and virtually all of the editorial staff is being let go. Even though I don’t personally know any of the people being laid off, other than a tiny amount through Twitter, I’m quite sad for them and for the magazine. And there is something personal about it for me also.

When the Mac was introduced in 1984, my life veered from a life studying physics and went into a totally different direction. (I wrote about this previously in some detail in my post 30 Years of Macintosh.) For young people in todays world it is almost impossible to imagine how we learned about this radical new computer. There was no internet as we know it today. No World Wide Web, no Twitter, no online blogs, no RSS feeds of news stories.

The way most of us found out information about the Macintosh was through the monthly publication Macworld. I remember eagerly awaiting each new issue. It was filled with tons of information that wasn’t available anywhere else. In the early days I read every word of every issue the same day it arrived. Every word. And the Macworld conferences were must attend shows and continued to be for more than 20 years. (I still get excited thinking about that Levco 68020 board that you could put in a Mac.)

I still have two issues from the early magazine. These issues made a difference in my life. I’ve kept them for 30 years and I’ll keep them for 30 more. Macworld ceasing publication seems personal. My heart goes out to those who’ve lost their jobs. And for the Apple community that has lost an old friend.


Leave a comment

30 Years of Macintosh

Without a doubt the introduction of the Macintosh changed my life.

In 1984 I was nearing the completion of my PhD in physics. I knew I wasn’t going to continue in physics and I had no idea what I would do instead. My interest in the personal computers of the day was non-existent. In January 1984 I was out of the country so I missed the introduction of the Mac. But a colleague had a friend who worked for Apple and that friend brought a Mac over to show us. It seemed like magic.

I was totally hooked. Stanford had some Macs that you could go and spend time with, playing with MacPaint and MacWrite. When Apple offered Macs through the university at $1000 (a huge discount from the $2500 list price) I scraped together money I didn’t have and bought one.

In the early days of Macintosh the internet was just a bit different than today. A couple of people at Stanford started the “Info Mac Digest” which was a daily mass mailing that went to thousands of people. It was an incredible information source and consisted entirely of postings from people who shared excitement about this sea change in computing. For a period of time I was moderator of info-mac and through that got to meet many people in the Macintosh community, many of which are colleagues and friends today. I have to take at least partial credit for organizing the “netters dinner” that took place annually around MacWorld. I still remember the year that about 70 of us gathered at MacWorld and walked from Moscone up to Chinatown and overtook the Hunan Restaurant. (See Netter’s Dinner.)

Stanford had a users group, SMUG, that met regularly. Gus Fernandez started a developers group associated with SMUG and he seemed to have every Apple superstar come and talk about Macintosh. I don’t remember everybody but I do remember Andy Hertzfeld, Larry Kenyon, Bruce Horn, Chris Crawford, and Bill Budge coming and blowing everybody away with stories, demos, and more. I still remember Andy saying that even though the LaserWriter had a 12 MHz processor (instead of the 8 MHz of the Mac), running PostScript brought the processor to its knees!

All this motivated me to go to the Stanford library where they had a loose leaf copy of a draft of Inside Macintosh and I started reading. Everything was totally new and exciting but completely foreign to me. I’d only done programming in Fortran previously and Pascal was literally a foreign language. It was nothing like the computing I’d done on mainframes! On July 13, 1985 I went to the “MacAfrica” one day class taught by Dave Wilson (see MacAfrica) and learned a ton.

When I finished grad school and started looking for jobs I had a couple of opportunities with high tech companies doing computing work that didn’t really excite me but they were good opportunities nonetheless. Then by chance I met Dave Gustavson at SLAC who was looking for a Mac programmer to do Mac programming using FORTH on a project to control a piece of hardware. I ended up working for him in the Computation Research Group at SLAC programming the Mac using the fantastic Mach1 programming environment created by Rick Miley and others at the Palo Alto Shipping Company.

One bonus of that job was that Dave got one of the first Apple LaserWriter printers. I got a serial cable and started to learn the PostScript programming language. Since it was syntactically similar to FORTH it was a breeze to get started. This was my real first experience with computer graphics and it was a really easy way to learn. This was helpful when a friend at SLAC, Kathy Dager, put me in touch with Dick Sweet at Adobe Systems.

At Adobe I got the opportunity to do a wide range of things, including teaching PostScript programming classes to a wide range of people, working with a number of high profile software developers, including Apple, Aldus, and Quark. While Adobe was in development of a second version of the PostScript programming language (PostScript Level 2) I got to be part of the design of the language.

When Adobe decided that they needed to write a new LaserWriter driver for the Macintosh, I met Rich Blanchard and he and I co-designed and (with a team of talented people) wrote a new PostScript printer driver for Macintosh. That project became a joint project with Apple and became Apple’s LaserWriter 8 printer driver.

This led to my direct involvement with Apple Computer. Over time I worked with Rich and others from the LaserWriter 8 team at RBI Software Systems where we did contract work for Apple, Adobe, Sun, IBM, and others. After 5 years of working with Apple as a contractor, Apple decided they wanted us to work exclusively for them and our team at RBI became Apple employees. I worked at Apple almost 13 years before leaving in January 2013 to take a break from working in the world of technology.

Without my involvement with Macintosh, I would not have met my wife of 25+ years nor most of the people who are my friends today. It has influenced my career, my personal life, and many of my interests that continue to this day.

So I mean it when I say the introduction of the Macintosh changed my life.

1 Comment

On the Debug Podcast

Recently I made an appearance on the Debug podcast, hosted by Guy English and Rene Ritchie. It was terrific fun talking with them and we’ve gotten a lot of positive feedback from listeners. We had so much to talk about that they broke it up into two parts.

In Part 1 we talk about how I got into computing, working with FORTH at Stanford Linear Accelerator Center, my days at Adobe Systems in the late 1980s, working at General Magic, and then RBI Software Systems. Part 1 ends just as we are talking about RBI moving to Apple to work in the Graphics and Imaging Group in June, 2000.

Part 2 begins as I arrive at Apple and begin working on Printing and Graphics just as Mac OS X was ramping up for a beta release in the fall of 2000 and the 10.0 release in the Spring of 2001. It was a fantastic time to start at Apple and be a part of its evolution. And yes, we also talk about bagels.

If you haven’t already, I hope you listen in.

1 Comment

The Day Before the World Changed

Apple Comm Meeting – June 28, 2007 – Town Hall, 1 Infinite Loop, Cupertino, CA

Comm meetings at Apple happen a couple of times a year, with no particular schedule. While I was at Apple the meetings consisted of Steve (and later, Tim Cook) talking about the most important company news at the time. After the planned remarks, the floor was opened up for questions and if Steve or Tim could not answer the question, the entire executive team was there to provide an answer.

But the Comm meeting on June 28, 2007 was different. This Comm meeting was being held the day before the first iPhone was going on sale. I didn’t work on the iPhone development team but I could see it was going to be a game changer. A lot of people could see that at the time. Now everybody can see that it was.

Take a moment to remember what smart phones were like before the iPhone was introduced. Here’s a still frame from the iPhone introduction at Macworld in January 2007. Today’s world of mobile phones bears no resemblance to those of 2007.

Apple iPhone Intro

Town Hall at Apple’s Infinite Loop campus is a small auditorium that was used as the locus for Apple’s Comm meetings. It was where the people running the meeting were located. But these events were for all employees and because the number of employees was numerous and people were spread across multiple sites, there were a number of remote viewing locations on Apple’s campuses in Cupertino as well as other places in the world. Town Hall holds only about 300 people so essentially everyone watched the Comm meetings from one of many remote locations on various Apple campuses where it was broadcast in real time. Typically I would go to Caffé Macs which could hold a large number of people.

For this Comm meeting I wanted to be inside of Town Hall rather than watching from one of the remote viewing sites. I wanted to be in the room. That meant going very early to get in line. Even after arriving probably 2 hours early it was still hard to get in but Bunny Laden, Howard Miller, and I managed to get seats at the back of the auditorium. We’d made it in.

The buzz in the room was extreme. Steve’s arrival on stage was met with huge applause. He looked triumphant. I don’t remember a lot of details about what was said but mostly remember just the feeling of excitement about what was to come.

One big moment was when Steve announced that Apple was going to give an iPhone to every Apple employee. The excitement that was already present went up tenfold as everyone leapt out of their seats into a huge standing ovation that lasted quite a while. The cheers and yelling got even louder when Steve said that it would be the (larger) 8 GB capacity iPhone we would all be getting.

During the Q&A portion a lot of people in the audience had questions. After one or two questions about the iPhone, someone asked about something that had nothing to do with the iPhone or the whole point of the meeting. Steve was taken aback. The next question was similarly irrelevant to the meeting at hand. Annoyed, Steve answered that question with something like: “Today isn’t the day to talk about that. Today is the day to reflect on what we’ve done and what is going to happen.” THAT was why I wanted to be in that room. To hear him talk and reflect about what the team had done and what was going to happen.

If you are reading this blog, the chances are great that if you pull your phone out of your purse or pocket and look at it, you’ll see something like mine. If it isn’t an iPhone it almost certainly looks more like an iPhone than one of those phones Steve waved at during the iPhone introduction at Macworld.

Apple iPhone 5 transparent small

Of course every day is the day before the world changed because the world is constantly changing. But the feeling of anticipation and excitement I had about the future of technology that day was unlike any other I had while working at Apple. On the day before the world changed.