What is the easiest way to create complex PDF in iOS? - ios

I am trying to generate some complex invoice data in PDF format. I know two Technique:-
By converting Data into HTML data via UIWebView and generate its PDF accordingly. But it is having issue of showing data Blur or unreadable if Zoom, when data is long in size. Cause it actually first create Image from HTML data and generate pdf.
Using QuartzCore technique mentioned in Ray-Wenderlich tutorial:-
http://www.raywenderlich.com/6818/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-2
Is there any way other then these above two? Also is it possible in the First technique to get data in UIWebView as vector based so that when it zoom it will not blur the data?
Thanks in Advance,
Vivek

Use the Quartz 2D framework as described in the tutorial. You don't want to create a pixel image from the html because it does not scale and can get large.

You can use a tableview with multi sections to create your invoice and convert it to an image(uiview----> image) and After that print that image to pdf (image--->pdf).

Related

Creating a PDF file from JSON object in Objective C

I have a webservice returning a bunch of fields about my form. The requirement is to transform this data into a PDF file with a defined format of out own choice.
When I say "own choice", it means that I want to define in which order the fields show up on the PDF, what will be the padding / margins etc.., Font size / font weight etc.. Basically I want to design a PDF via code.
I know this can be done from XML with the help of XSLT. I have done that in the past too. However, this seems to be tricky in case of JSON. I would appreciate if anyone can help / give any pointers in this regard.
You create PDFs in iOS using Core Graphics. Use
UIGraphicsBeginPDFContextToData(data, bounds, dict);
or
UIGraphicsBeginPDFContextToFile(path,bounds,dict);
to create the context, and then draw your fields where you want them.
You can drop down to the CG level if you want, but drawing text is much simpler if you stay within UI.

Export text and image in the same file

What I want to do is exporting some data from my app to a text file - say an RTF file. I found that converting text can be done through this classes, but is there a way to save an image also?
If you want to export text + images in the same document you can do it usig Core Graphics. Please search for CGPDFDocument Reference and Quartz 2D Programming Guide in Apple documentation.
However in order to do this you need to have an understanding of the PDF format and you should read the Adobe guide PDF Reference, Fourth Edition, Version 1.5
Using CGPDFContext you can create a UIView, draw your contents into it (using sub views to make life easy for text and images) and then render the views layer into the PDF context. Then save the resulting data to a file.

Best way to store and load Freehand Drawing Lines for every image

I found this post Draw Lines Load From Plist in iphone sdk about saving and loading your Freehand Drawing from plist.
In my app I am able to draw on a captured photo and save it as a new image in my photo library. But I want to just save the photo without the drawing to my photo library and be able to load my Freehand Drawing Lines manually whenever I load the original photo.
In the above named link he saves his linecoordinates in a plist. Is it effective to create for every photo a new plist?? Any ideas? Please help :(
I would really appreciate any ideas you might have! Thank you
The reason he uses line coordinates is because the mobile devices receive the data the same way (relative to previous or absolute). So unless the size of the line coordinates is bigger than a compressed pixel array (png, jpg, etc), this is the best way. For simplicity though, I would just keep that format.
If size is a problem for you, just use zlib (http://www.zlib.net/) to compress/uncompress the data - it's available on all mobile devices.
You could also use different algorithms to reduce the size of the data prior to zlib compression - for instance, if all coordinates are relative to the previous one, the values would be smaller meaning you could encode it in a smaller type of data - integer to byte for instance - or a dynamic one (ie: 1 byte + 0 if done 1 if another byte) + ....).

Generating an image using Cocoa

My iOS app needs to be able to generate an image to post to Facebook and Twitter. The image will be a representation of data added by the user. The image is not a direct representation of any view that will be displayed on screen. It is not necessary to include any other image resources in the image created - for the most part I need to format the style and layout some text, and maybe add some borders, lines, etc - but I would like the ability to add this later if it is simple.
What approach is best for something like this? Should I build a UIView and output it to a file somehow? Is there an HTML/CSS solution? Or some other approach?
Bonus points if you can recommend the file format and attributes optimized for posting to Facebook/Twitter.
Use UIGraphicsBeginImageContextWithOptions() to create a new image context.
Then, draw whatever you like into it using Core Graphics. You can draw text using Core Graphics or Core Text — the former is easier, but the latter gives you more opportunity for customisation.
Then, get a UIImage out of your context by using UIGraphicsGetImageFromCurrentImageContext().
You can then convert the UIImage into a PNG using UIImagePNGRepresentation().

Multiple PDF pages and scrollview in two dimensions in xcode

Super noob here:
I am trying to create a scrollview that will scroll through a number of pdf's in a two dimensional array for use on an iPad. As if I tiled all the pdf's and wanted to be able to scroll from page to page by scrolling up/down/left/right. How can I do that?
Any help is appreciated!
I have to read the PDF pages and write them as image contexts. The big problem here is that it you will use a mechanism to generate the pages lazily keeping a little buffer of advance.
The only thing I don't get is why you need a 2D array to store a PDF if this can be done with a 1D array?

Resources