|
6-27-03
Create PDF documents that contain JPEG images by
Erick Tejkowsi
This week we'll look at a significantly more advanced topic: PDF creation. In past years, I've tinkered with
building PDF by hand using REALbasic. After many head-scratching hours, I managed to tackle text and simple
drawing in a PDF document. Ever since I posted that code, though, I've been inundated with emails asking how
to embed images in a PDF document. Well, I finally got off my duff and whipped up this week's example. This
project is not your usual REALbasic tutorial on ResExcellence. It's decidely more complex and requires a lot of
research on your part if you want to understand how it really works. If you don't care and just want to use it,
it's pretty easy to adapt the code for use in your own projects.
For any serious PDF hack, the Adobe web site should be your first stop. There, you can download a PDF (naturally) copy of
the PDF specification. It is an extremely long document (Remember Steve Job's scrolling demo last week at WWDC? He was scrolling through
this very spec.) and quite technical in nature. Don't fret if you don't understand it all. You probably won't.
The basic premise behind the structure of PDF documents is the idea of an object. An object, much like an HTML tag, must adhere
to a set of rules about its format. The PDF spec describes these objects in full detail. You can download one of my earlier
PDF examples to see how the objects are strung together in a PDF file. It is a very touchy format in that the having the slightest
thing off can result in an invalid (and often unviewable) PDF file. This can be very aggravating for the fledgling PDF
newbie. Be patient. Creating PDF files by hand is a tedious task.
If you happen to be an owner of Adobe Acrobat (not just the Reader), you're in luck. Your PDF hacking job will
be much easier. Why? Because sometimes when you are piecing together your own PDF files, the format is very close to
correct, but something subtle is off by a character or two. Whereas Acrobat Reader or Preview.app will puke on the file, Acrobat can sometimes repair the file for you.
Not only is this good for viewing with the Preview, but it has an added side benefit. You can then open that repaired file
in a text editor like BBEdit and compare the output with a copy of the file that hasn't been repaired. Within seconds you can often
tell where you went wrong. Just a little tip from someone who's been there. ;)
The Interface and the Code
Because this week's example is so elaborate, we won't be discussing how it works. It's just too involved.
You are free to look at the code to see how I did it. It ain't pretty and it might not make a lick of sense to you
if you are unfamiliar with the PDF spec. You've been warned.
The interface consists of a bunch of EditFields. Each of these EditFields contains pre-written text. This text defines the
various objects in the PDF file. The code in the Action event gives the user the chance to select a JPEG file.
Then, it extracts information about that image. Using that info, the code concludes by constructing the PDF file.
It does this by writing the various objects to a file with JPEG image info interspersed where appropriate. It's not the prettiest code,
but it works. Hopefully it will give some folks a nice debugging tool for playing with PDF output themselves.
Conclusion
That's it for this time. The last couple weeks we covered some basic topics (text files, FolderItems),
so I decided that this week you deserved a change of pace.
If this one is way too tough for you, rest assured we'll return to simpler territory in coming weeks.
Download the code for this week's project here. See you next time!
6-25-03
REALbasic News
by Erick Tejkowsi
Code Examples by Seth
Seth Willits has posted some new REALbasic examples.
- FSCursorModule is a new REALbasic module for cursor routines.
- New REALbasic example for dynamic AppleScripts on OS X
- FSDictionaryToDisk is an example with a module demonstrating how to write and load a dictionary from disk.
A bunch of neat stuff. Don't miss it.
Synchronous Socket
Aaron Ballman whipped up a quick class that implements a
synchronous TCPSocket.
This is a truly synchronous socket, all calls are blocking. Not sure if this is for you? Give it a try and see for yourself.
Metrowerks + REAL Software + SolidWave = Fast Development
Metrowerks has teamed With REAL Software and SolidWave Software To Speed Creation Of Mac Applications.
Metrowerks has joined forces with REAL Software, Inc. and SolidWave Software, Inc. to create a bundled product that helps Macintosh developers boost productivity and speed time to market.
The offering, called the Productivity Bundle, includes REAL Software's REALbasic 4.5 object-oriented rapid application development (RAD) environment, SolidWave Software's RADicode 1.0 code converter, and Metrowerks' CodeWarrior Development Studio, Mac OS X Edition.
The combined offering makes it easy for developers to create high quality interface code, and then to convert it into a CodeWarrior project built on Metrowerks' PowerPlantª object-oriented C++ application framework. The project is then ready to leverage the CodeWarrior Development Studio, which is the industry-standard development environment for commercial Mac OS¨ applications.
"This bundle essentially gives developers a head start in the creation of Mac applications," said Greg Hemstreet, director of core and desktop technologies, Metrowerks. "Developers can easily prototype their applications, then convert them in a matter of minutes, allowing more time for C++ coding and other important tasks."
BitJuggler Software moves
BitJuggler Software has moved! Update your bookmarks, so you don't miss this handy REALbasic site.
6-18-03
REALbasic News
by Erick Tejkowsi
RoundSlider
Domain Softworx announces the release of RoundSlider, a Canvas subclass that mimics Cocoa's slider control with a round thumb instead of a pointed one.
RoundSlider supports most of the built-in slider's methods and properties and more. It can reverse direction, and become a "small slider". It is part of Domain Softworx's ongoing effort to make all the controls prescribed by Apple's Aqua Human Interface Guidelines available to REALbasic developers. (Any suggestions for the next one in the series?)
Download it here
dbReports 3.2
db Reports makes it very easy for REALbasic programmers to preview and print professional reports from your project.
Saves you time, and makes you look good. Check it out for free.
Shareware Article
Walter Purvis recommended this article about shareware. It discusses amateurism versus professionalism among shareware authors.
modMenu
modMenu (5.x only) is a small module with a half dozen methods to help you
deal with menus, and a couple for menu diagnostics. No rocket science, just
some handy code.
WWDC
Going to WWDC this year? Don't forget to stop by and say to the REAL Software staff. Word is they will also have a "birds of a feather" meeting as well to discuss all things REALbasic.
6-13-03
iPod Trickery with REALbasic (Part 2) by
Erick Tejkowsi
Have you ever wondered how all those neat iPod utilities work? This week
we'll continue our multi-week tutorial about using REALbasic to have some fun with your iPod.
This week we'll show you how to copy files from a connected iPod. We'll also thread the search process,
so the project doesn't lock up the machine.
If you'd like to follow along with this week's project,
download a copy of last week's finished project and
open it with REALbasic.
You can also go back and read the original tutorial in
case you missed it.
Enhance the Interface
Open Window1 and add a PushButton, a ProgressBar, and a StaticText control to the interface.
The new button will be used to trigger a copy operation from the iPod to your Mac. The ProgressBar and StaticText controls
will be used to display information as the project searches for music files on the iPod. While you're staring at the interface,
press and hold Cmd-Shift on your keyboard. Then, drag from the new PushButton to the Listbox control. When you let go of the mouse,
a dialog appears allowing you to select a Control Binding operation. Select the only option and click "OK". This will
cause the PushButton to become enabled when the Listbox has a selection. Otherwise, it remains disabled.
Rearrange the interface
however you like. I've left the default "Label:" text setting for the StaticText control so you can see its location.
My interface looks like this:
Next, double click Window1 to open its Code Editor. Scroll down to the Properties, and
double-click iPods(0) as folderItem property to edit it. Make sure that the Private checkbox
is NOT checked. This will give our Thread object (later in this tutorial) access to the array of iPod FolderItems.
Finally, return to the Project Window and click on the File-New Class menu item. Name the new
class "iPodThread" by editing its Name property and then change its Super property
to "Thread" (ignore quotes for both Name and Super). Double-click the new Thread class to open its Code Editor.
Choose Edit-New Property and create a new property named "caller as Window1".
Again, uncheck the Private checkbox.
Add the Code
Last week we created some code to locate the music files on an iPod.
The code was fairly simple, but it had one drawback. Because an iPod might have
thousands of music files, it takes awhile to find them all. Furthermore, our
code was inelegant. It used a "brute force" method that caused the application
to overtake the CPU. A user can't do anything until the process is over. To remedy this
problem, all you have to do is use a Thread (which you created earlier in this tutorial).
Code that runs in a thread won't lock up the CPU. Instead, the user can continue to use the interface,
switch applications, and everything else they expect to be able to do. You can also provide visual feedback
in a thread a lot easier than you can in non-threaded code. The trade-off is
that your threaded code will run a little slower. For long operations like this one, users will
appreciate feedback. Another advantage of a thread is that you can easily permit the user to cancel.
To create and run the thread, replace the Code in the Action event of PushButton2 with the following code:
In the Action event of PushButton3 enter the following code to copy the selected file on the iPod to the desktop.
Next, open the iPodThread class and add the following code to the Run event. If you're
following along from last week, you'll recognize much of the code. Most of it is code that we used
within the PushButton2 control last time. We've also added some feedback via the ProgressBar and StaticText
control. Finally, we give the user the chance to cancel the operation by holding Escape or Cmd-Period.
Another difference is that this time we are displaying each file name in the first column of the Listbox,
and its path in the second column. Because we give the first column 100% of the Listbox width, you won't see the
paths displayed. We effectively "hid" them. (They're long and messy anyway)
Conclusion
We're done! Choose Debug-Run to see your work. Don't forget to mount an iPod before
you test it, otherwise this project won't do much. Your Mac doesn't have FireWire, but the one in the other room does?
You can always share an iPod over the network just like any other hard drive.
Download the code for this week's project here. See you next time!
|