Howdy…
So all you want to do is open a window, fill in a fancy form, and then print it… right? If so, there are much easier ways than what’s proposed above. It doesn’t require any html, css, or external apps. AND… when you go to print it asks you if you want to create a pdf out of it…if that’s your flavor. Saving to pdf will save the same contents it would otherwise print. Here’s what I did…
The basics…
- Create a window.
- Drag an NSBox to the window. Set the ‘box type’ to invisible in it’s attributes.
The image…
3) Create an image that looks like your form. It could be a jpg, gif, even an actual pdf file. Add it to your project with the “Add Files…” menu item in PB/xcode or by dragging it to the project.
4) Drag an image view into the box. Place your image in it. Make sure that the image is small enough to print out in one page, or you’ll have to find a way to get this to work with multiple pages (like multiple windows or form layouts).
The form…
5) Drag text fields into the box, aligning them to fit around your image, and making sure they are layered above the image. If you do the image first, and then the text fields this shouldn’t be an issue.
Essentially you are creating a regular form, with an image view containing your form’s “graphics” layed out underneath. The key to this, is that you do it all within a NSBox, for this reason…
- Create a button or other control that will signal the print action (or use the “Print…” File menu item).
- Connect the button’s ‘print:’ action TO THE BOX. Do this by holding control, clicking on the button, and dragging to the box. In the connections pane select print: and then click the “connect” button on the bottom to make the connection.
Now whenever you click the button (menu item… whatever) it will open the print dialog. Because it’s connected to the box and not the file’s owner or the window, it prints only the contents of the box. If you use the ‘print…’ menu item, make sure to disconnect the default print connection made to the file’s owner.
I tried it with an image and two text fields and got this… Click here. This is actually a screenshot of the pdf file I saved to, but it’s exactly the same as what I printed out.
Notes:
As you can see from my test image, if your image is an easy white background with black text over it, you might be able to use form-style text fields. If it’s a dark image or you want no borders, use regular text fields and make the color something contrasting… like the white that I used over the dark green (or black over white, obviously :)). I used a form-style text field on top, and a regular field on the bottom with the text color set to white. MAKE SURE to set the “Editable” attribute for any regular text fields you use to true in IB.
You might want to resize the box to snugly fit the image view, so there’s no possibility of the app trying to print anything from outside the bounds of the image area.
As for the objects themselves, you mentioned using a data source. Because the form is a regular applescript studio application, you can manipulate the text fields as usual…entering and editing data via your scripts. Just write your code that manages the fields and work with it as any other application. Make sure to add the (of box “theBox”) reference because it’s in the box, though. Note that the AS names are not even required (at least not in my test) unless you are going to use them to reference the fields for scripting purposes. If you’re just filling them in manually and printing without any script interaction, they can just be generic, nameless objects. Another nice thing, is that you can have other elements in the window, and as long as they’re not in the box, they won’t get printed.
Hope this helps…
j