Thanks so much for the response. That was exactly what I was looking for 
and am now able to render the image in a PDF. The reason, I opted to go 
with UIWebView and then export the HTML to PDF is that this way I get to 
leverage the formatting and table and image  rendering in already present 
in UIWebView.

All this time I have been looking at the documentation at 
http://developer.couchbase.com/mobile/develop/references/couchbase-lite/index.html
 
and it doesn't mention the existence of the CBLDatabase.internalUrl 
property.

For others looking for a similar solution, I ended up doing the following 
(in Swift)
let dbUrl = doc.database.internalURL
let url = dbUrl.absoluteString?.stringByAppendingPathComponent(doc.
documentID).stringByAppendingPathComponent(imageFileName)



Thanks again!!
S

On Sunday, 16 August 2015 11:02:51 UTC+10, Jens Alfke wrote:
>
>
> On Aug 15, 2015, at 4:57 PM, Shizam <[email protected] 
> <javascript:>> wrote:
>
>     My approach thus far has been to access the image data as raw bytes 
> using Attachment.content and render it on a UIWebView as a base64 encoded 
> image and then get the UIWebView object to export the HTML data as a PDF 
> (all in memory).
>
>
> That seems like a roundabout way of doing it! CoreGraphics has a whole API 
> for reading and writing PDFs — take a look at CGPDFContext. I’ve only used 
> this for *reading* PDF files, but it looks like it goes the other way 
> too, allowing you to generate PDFs.
>
>     So my question is if there is a way to access an attachment in 
> couchbase lite as a direct URL (like file:///....)  so that one can 
> circumvent the entire base64 conversion and rendering stages.
>
>
> Hopefully you won’t need this :) but yes — use CBLDatabase.internalURL to 
> get the root URL of the database in the REST API, then append path 
> components for the docID and the attachment name. The resulting URL can be 
> used inside the app (including in a UIWebView) to read the attachment.
>
> —Jens
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/0262417d-5913-4ccf-b45f-1e40bc5767e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to