Show PDF in iPad using CGPDF APIs [closed] - iphone

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have learned Apple has release CGPDF APIs in SDK 3.2 for drawing PDF context.
What I understand from these APIs is that you can draw a PDF to a data object or a PDF file. You can then export it, may be, to your sandbox's directory OR add as an attachment in the mail.
But I am not sure if we can use these APIs to read a PDF from application bundle and show it to the user page-by-page on the screen. What I want to do is open a PDF of a magazine in a magazine reader app.
I was also wondering if we can identify the links in a PDF file and open them in the app.
Let me know if have done OR doing anything like this.
Thanks
AJ

In API documentation there is a way to load a PDF (with Quartz):
CGPDFDocument is the object you need
and CGPDFDocumentCreateWithURL is probably the constructor you are looking for.
Here are some examples on how to do it:
http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF109
I have spent a lot of time on this - and it seems you need to use CATiledLayers to zoom those PDFs properly!
There are some good examples on the net on how to do that...
I will put a link/solution here as soon as I have something ready!

Displaying the PDF with the Quartz APIs is pretty easy. But there's no native support for link annotations. Basically, you need to parse the "Annots" dictionary inside the pdf, and then find the correct page (which can be GoTo references, or named references, or ~10 other types; see the Adobe PDF Reference 1.7 document, the section about Actions), and the calculate the coordinates to the displayed page.
I've written a [commercial] library that includes parsing link annotations, and many more features. You may wanna check out http://pspdfkit.com

Related

Working with PDF's in Objective C [duplicate]

This question already has answers here:
Insert a PDF file into Core Data?
(2 answers)
Closed 9 years ago.
I am currently building an iOS app that will be manipulating PDF documents. You will be able to type in information about yourself and the app will populate certain text fields on a document with the correct information and create a PDF that you will be able to save, share, etc.
I'm rather new to iOS programming. What are some things I should know?
Can I use Core Data with PDF's?
Can I populate a stock PDF with the info or do I have to use some other format and create a PDF from the final product.
You could use Core Data to store your information, but that would be separate to any PDF consideration that your app had. It may be best for your app to store the information and provide a view which shows the PDF layout, but not actually as PDF, and then allow the view to be exported as a PDF.
This answer shows how to save the view as a PDF.

Perl, Template-Toolkit and SEO [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm not sure how to deploy best practice for SEO in a new project.
I'm building a CMS that will be used by a group of writers to post news articles to a website. I'm developing the site using Perl and Template-Toolkit (TT2). I've also embedded an open source editor (TinyMCE) in the system that will be used for content creation.
I was planning to save the news article content to the DB as text - though I could also save it to flat files and then save the corresponding file paths to the DB.
From an SEO standpoint, I think it would be very helpful if this content could be exposed to search engines. There will be lots of links and images that could help to improve rankings.
If I put this content in the DB, it won't be discoverable ... right?
If I save this content in template files (content.tt) will the .tt files be recognized by search engines?
Note that the template files (.tt) will be displayed as content via a TT2 wrapper.
I'm also planning to generate a Google XML Sitemap using the Sitemap 0.90 standard. Perhaps this is suffiecient? Or should I try to make the actual content discoverable?
Thanks ... just not sure how the google dance deals with .tt files and such.
If I put this content in the DB, it won't be discoverable ... right?
The database is part of your backend. Google cares about what you expose to the front end.
If I save this content in template files (content.tt) will the .tt files be recognized by search engines?
Your template files are also part of your backend.
Note that the template files (.tt) will be displayed as content via a TT2 wrapper.
The wrapper takes the template files and the data in the database and produces HTML pages. The HTML pages are what Google sees.
Link to those pages.
just not sure how the google dance deals with .tt files and such
Google doesn't care at all about .tt files and the like. Google cares about URLs and the resources that they represent.
When Google is given the URL of the front page of your site, it will visit that URL. Your site will respond to that request by generating the front page, presumably in HTML. Google will then parse that HTML and extract any URLs it finds. It will then visit all of those URLs and the process will repeat. Many times.
The back-end technologies don't matter at all. What matters is that your site is made up of well-constructed HTML pages with meaningful links between them.

Tag based file system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
All OSs that exist right now work in files and folders. I was thinking that there are may other ways of storing files. Would it be a better way to store files by tags, for example:
A file called "music1" can have a tag "2013", if the music was made in 2013. The same file can have another tag called "Music", to say that the file is music, another file called "video1" could have the "2013" tag, but also have the "Video" tag instead of the "Music" one. This would be useful, because you could search for tags and generate nice-looking maps of all the files you have.
Here is an example:
In this example, files are in green. Each file has some tags(blue),and some special tags(red). Special tags contain things like the user(only the user in the tag can see files tagged USER:Username) and File type(instead of file extension). Tags in yellow are system filetypes that do not require a program to run them(like .exe in windows)
Black lines link tags to files
Red lines link special tags to files
Blue lines link what the file type(or file) is opened by. For example, the music is an ogg file. It is opened by OggViewer, which is a jar file opened by java. Java is opened by the system.
As far as I know, there is a nice file system level solution to your need called NHFS or nonhierarchical file system. Also available a FUSE based mountable file system called TMSU that may satisfy you.
It could have merit, for example I'm utterly disinterested in the file names/paths of my tens of thousands of music files; I only really care about the artist,title,album,year,etc of them, which is the way my music player (quodlibet) displays them. Choosing a set of music to put on another device or to send to someone could then be as easily as selecting an album (instead of browing to /home/me/music/who/knows/what/someartist - somealbum).
There is TagsForAll for windows. It is a file manager based on tags. Tags can have hierarchical structure. User interface is very simple but nice. Free version fully functional and save tags in database, Pro version save tags also within NTFS stream to a file.
Microsoft tried to do something like that with WinFS
but gave up on it. It would be great if they could get it to work.
There are some other (old, archived) projects implement this idea:
http://nascent.freeshell.org/programming/TagFS/
https://code.google.com/p/dhtfs/
https://code.google.com/p/tagfilesystem/
http://www.tagsistant.net/
Only the last seems to be releasing recent versions.
I think the idea has a future. I've pondered this same idea before. And tags fundamentally work better for most content than folders do; however, I wonder if the hierarchical structure of folders isn't actually better suited for files. In other words, though I like the idea of using tags on many levels I wonder if it would actually increase the overall complexity. For example, consider how tags could be used successfully to manage versioned software libraries. I'm afraid we won't know the answer until someone starts using the concept instead of folders for an entire OS. It'll be interesting to see/try.

How to implement an ePub reader for an iPad/iPhone app [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I want to implement an ePub reader for the iOS platform. Please suggest any open source code for book flipping animation, bookmarks, font-size customization and single page view (without scroll bars).
As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:
Unzip the ePub
Read the manifest file and metadata file to find the xhtml documents to display
Load the xhtml documents into a UIWebView using a file:/// URL to the unzipped document
If you want to ensure that the documents don't hit the network you'll need to implement a custom NSURLProtocol and serve the bytes for the files yourself as file:/// allows cross domain access.
That will display the content just fine, but the "hard" part is moving between the documents (which usually represent a whole chapter). This is the work that iBooks and other apps do for you.
NOTE: For the UIWebView to display the content correctly, you have to ensure that the file has a .xhtml extension when using file:/// urls. If you implement your own URL protocol handler, you need to make sure the protocol handler returns the correct xml content type for xhtml, namely:
application/xhtml+xml
Use the ePub packaging format and an open-source reader for reference:
ePub3 Packaging
fbReader Source
Readium Source
Calibre Source
Try this steps :
Source code: AePubReader
Implementation:
Step 1: Create a view with a UIWebView
Step 2: Download an EPUB file and import into your project
Step 3: Unzip EPUB file to a subdirectory in your app's documents folder.
Step 4: Parse the XML file from directory META-INF/container.xml. If this file directory doesn't exist means, your EPUB file is invalid.
Step 5: In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.
Step 6: Parse the OPF file (also XML)
Step 7: Now you need to know what the first chapter of the book is.
Each in the element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.
Look at the first in the . It has an idref attribute which corresponds to one of the ids in (Step 7a). Look up that id in the NSDictionary and you'll get an href.
this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (Step 3), plus the base NSDictionary of the OPF file in (Step 6).
Step 8: Create an NSURL using fileURLWithPath:, where the path is the full path from (Step 7c). Load this request using the UIWebView you created in (Step 1).
Step 9: You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the to work out which file to show next. Then the XML are in the order they should appear to the reader.
These step got referred from this link
Use UITextView with pageview controller . (Specify your doubts , if any)

How to import/parse SVG into UIBezierpaths, NSBezierpaths, CGPaths? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to import paths from a vector drawing program into the ios environment. I would like to get them into CGpaths or UIbezierpaths. I am most interested in importing paths from adobe illustrator. The best way seems to save as an svg and then import.
I have found some resources for parsing exported SVG files that describe the paths. However, everything I have found only deals with absolute paths and not relative paths. The path below has capital C's and lowercase C's. I know how to parse the capital C (absolute paths) but I have no idea how to parse the lowercase c's (relative paths)
I am looking for help with writing a parser for importing svg files into ios/cocoa. I think there is a big need for this judging by searching the internet for weeks.
Here, is an example of a path I would like to import into my iphone app. I am not looking to import the image, I want the path itself. So, I can manipulate it. Any help would be much appreciated.
x="0px" y="0px" width="320px" height="436px" viewBox="-1.4 -0.5 320 436"
d="M294.1,116C290.6,1.4,170.9,0.4,159.6,0.5
C148.3,0.4,28.7,1.4,25.2,116c-3.7,120.3-49.6,141.4-5.9,233.9c41.3,87.4,130.7,87,140.4,86.7c9.7,0.3,99.1,0.8,140.4-86.7
C343.7,257.4,297.8,236.3,294.1,116z
If this was all absolute paths I would be able to solve this now. It is the relative (i.e. lowecase (c) paths) that are really confusing me.
Alright folks, if you're willing to pay for it. This tool will solve all your issues. You can import svg or psd and will produce the code for you. I've used it and it is amazing!
http://www.paintcodeapp.com/
There's an open-source SVG library in ObjectiveC, specifically for iOS (and OS X, although the OS X build is a bit behind):
https://github.com/SVGKit/SVGKit/
(I've been using this on iOS projects since the start of this year, it works well)
2018 update: OSX support is now in, and SVGKit renders most SVG's fast + accurately. On the downside, advanced text features aren't all supported (e.g. yes to gradient-fill, but no to complex text-layout).
As of early 2012, it's not a 100% implementation of the SVG spec, but there's a lot of people working on getting it there.
If you're willing to do some translation from JS to ObjC, then you might find this project helpful:
https://github.com/thelonious/svg-2d
Particularly, the path.js file which includes a parseData method, taking care of relative and absolute path commands.
https://github.com/thelonious/svg-2d/blob/master/shapes/path/Path.js
I should mention that I wrote this code years ago, but I have translated it to Java and C# and have used in professional products (can't share that code, unfortunately) and it seemed to work well in those environments as well.
HTH
Kevin
Sketch 3 on Mac App Store is good at editing (can be better than PaintCode) and then exporting as SVG to PaintCode.
To get from PaintCode back to Sketch save as PDF and imports ok
https://itunes.apple.com/gb/app/sketch-3/id852320343?mt=12
Make sure canvas size in both is set to the same and in your views bounds else youll need to scale the context.
SVGgh contains a class, SVGPathGenerator, which will convert an SVG path to a CGPathRef:
+(CGPathRef) newCGPathFromSVGPath:(NSString*)anSVGPath whileApplyingTransform:(CGAffineTransform)aTransform;
You can use it to do exactly what you request.
[Swift 3 Update] If you want a pure Swift solution. My (in progress) Scalar2D library has an extension on CGPath that creates a CGPath from an SVG path.
This solution is a straight conversion of an SVG path string to UIBezierPath. It worked great for my app where I had to draw the united states as a UIView.
https://github.com/ap4y/UIBezierPath-SVG
Oneliner that adds an SVG to an NSView:
addSubView(SVGParser.svg(FileParser.xml(~/Desktop/test.svg)))
SVGLib for swift: https://github.com/eonist/swift-utils