I'm working on an app for Macintosh. I want to have the user be able to click inside a PDF rendered onscreen and have an annotation appear where they clicked (or selected). Should/can I use PDFKit for this? I looked at the classes, but PDFSelection seems to deal with text, not coordinates. Specifically, I want to know which classes I should use to achieve this. I've read the PDFKit programming guide, but I'm still not quite clear as to the path forward.
Apple provides sample code, PDF Annotation Editor, its description is:
This sample application uses PDF Kit to examine, edit, and create PDF annotations. It has an inspector panel that shows various attributes of supported annotations. The inspector allows users to edit those values. Additionally, annotations can be created and the code demonstrates how to use PDF Kit to do this. Also, the sample code demonstrates subclassing of PDFAnnotationStamp in order to override the draw method and draw your own custom annotation content. Finally, the sample code demonstrates subclassing PDFView in order to overlay your own content over the PDF content being displayed.
This would appear to answer your questions, in particular look at mouseDown in PDFEditView.
HTH
Related
I would like to implement my own subclass of ImageSource. Xamarin Forms has FileImageSource, UriImageSource and several other subclasses of ImageSource, but none of them meets my needs.
To see how to implement an ImageSource subclass, I looked at implementation of FileImageSource on github (https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Core/FileImageSource.cs)
I expected to find that the subclass would override one or more ImageSource methods to actually read the image file and provide the bytes from the file to the calling platform. But source code of FileImageSource contains no such thing! In fact, they use the File only to override ImageSource.IsEmpty. How can this be? If an image is contained in a file, you need to read the file to display this image, don't you?
What am I missing? And if I want to implement my own subclass of ImageSource, how can my sublass return image data to the platform?
Edit
Thank you to everyone who proposed solving the issue in a different way and inquiring why exactly existing ImageSource subclasses do not serve my needs.
Even if there is a different way to solve my immediate issue, from an educational perspective it is still interesting to know how Xamarin Forms displays an image file without reading the file. The source code for FileImageSource is quite short and does not appear to use the file, other than to implement IsEmpty. This will bug me until I know how this works.
[Resolve the issue using converters]
Instead of creating a new ImageSource, you could create a Converter (if you are working with bindings).
So if you have something like a byte array, and you want that to be shown as an image, you can do the conversion from byte array into a StreamImageSource
[EDIT: Knowing how it works]
If you want to know how it works internally and how it transforms the File into the actual Image, you will have to go deeper into the code, and check the platform implementations.
For example here you have the android renderers. You will find the IImageSourceHandler.cs and the FontImageSourceHandler and the FileImageSourceHandler and so on.
I have a question and i am confused what strategy i should choose to solve this.
Here is the description.
I have a gallery which is managed on user authentication.
Next I have basically a simple form which saves quotes into database.
Selecting an image from gallery it is opened in a canvas. I am using Adobe Creative SDK.
Here is the demonstration image.
Next i have to select(copy) text from database to add(paste) in text field but i have no idea how to do it.
This is the task i have to do for a client. I have never seen a similar example. This is seems unique. Please provide some suggestion on doing it.
Adobe Creative SDK's editor will not allow you to pre-populate text on an image so it's out of the question for this task. You could probably find a way to overlay text on top of the Adobe editor, but then the issue with saving the image rears its head.
If you don't need any of the other editing tools, you could simply create a canvas with the image, overlay the text and allow the user to choose the font, position the text, apply stamps, etc...
Once they're done, wire up a save button to post the field with the contents of canvas.toDataURL('image/png') and have something server-side to save it.
It will be more work than using someone else's widget, but the client will be in control of their own destiny (and have a working product which they wouldn't have before).
Keep it simple and build from there.
In a nutshell, I don't want raw text, or even rich text. I want to load an xml document, which has metadata for sections of text, and I want to display that metadata in a drawer when I click on a given text section. A hyperlink is a good example; obviously trivial to do in a web app, but while I'm not that experienced with mac dev, I can't seem to find an easy way to accomplish this with cocoa.
Any suggestions as to general strategy? There doesn't seem to be an HTML view built in to Interface builder or I'd mess with that.
I'm not entirely clear on what you're trying to do. It sounds like you want to load an XML document, display the text, and display various metadata when certain bits of text are selected.
If that's the case, you should read about the Cocoa Text System. The NSTextStorage class is a subclass of NSMutableAttributedString, and you can apply arbitrary attributes to any range of text. When the selection changes, you can get the attributes in the selected range and use that to update your drawer. (By the way, drawers are really on their way out. I'd suggest a different user interface. NSSplitView-based interfaces are much more in vogue these days.)
Of course, to build up the NSTextStorage, you'd need to parse the XML with NSXMLDocument or NSXMLParser, but you'd get much more control and it would look more "Cocoa-like".
You could use a WebView, which is the Safari renderer, but I think you'd have a hard time getting it to display text the way you want. Safari has never been great at rendering XML without XSLT.
There is some tutorial about how to create a pdf using cocoa? I can't find anything. I looked for it on the web and it seems that I need Quartz to do it, but there aren't practical examples.
Can you help me? Thank you in advance.
—Albé
See Cocoa Printing Architecture documentation. Basically, any printing operation creates a PDF and, in general, the best way to create PDF documents is to implement custom printing layouts.
Alternatively, NSView has printing related methods for grabbing the PDF within a rectangle.
Is there a way to create an editable PDF programmatically? By editable, I mean you can click in a text area and type in your name, that kind of thing.
I'm using Ruby and have found PrinceXML and Princely to be nice projects. I'm wondering if they could do that?
Prince doesn't mention forms in the documentation, and renders forms as static drawings, so I doubt it.
pdfTeX can do it with the hyperref package. Here's a tutorial.
Example:
\usepackage{hyperref}
\begin{Form}
\TextField[backgroundcolor={1 1 0},value=can do forms]{hyperref}
\end{Form}
It looks like this:
screenshot http://grab.by/23nP
(Of course, then you're using TeX instead of whatever reports library you like. I'm sure there's an alternative.)