Saving Quartz drawings rendered over PDF on iphone OS
In my app I am displaying PD开发者_StackOverflowF pages and want to allow the user to "mark up" the document by freehand drawing on top of the page. I can handle the Quartz code for doing the freehand drawing, but what approach can I used to save these "mark ups" so that they can be re-displayed over the page the next time the user loads the PDF into the app?
Thanks,
//Scott
Problem:
- Given a PDF page and a series of drawing instructions,
- the app should be able to repeat those drawing instructions for that page
- when the app has been quit in between receiving the drawing instructions and viewing the page.
Solution:
- Save a reference to the PDF page and the drawing instructions to persistent storage.
- Load the drawing instructions for the viewed page.
- Render the drawing instructions.
Saving the PDF page reference could be as simple as saving the URL associated with the PDF and the current page.
Saving the drawing instructions could be as simple as archiving the UIBezierPath
s used as the drawing instructions, since UIBezierPath
conforms to NSCoding
. If you're using CGMutablePathRef
instead, you could initialize a UIBezierPath
from the CGPath
and archive the newly initialized bezier paths. You can retrieve the CGPath
from the UIBezierPath
after unarchiving.
If you do not need the user to be able to edit the drawing instructions on the following session, then you could render the drawing to a static image and just load and draw that the next time. After that session, render those instructions over the original image, save that out, and continue as before.
精彩评论