iOS create PDF invoice - ios

I want to create a PDF invoice inside my iOS App (either in Objective-C or Swift).
My main problem is that the invoice might have several pages, which is very difficult to realize with the existing APIs from Apple (CoreGraphics, Quartz 2D, etc).
By now, I already have a barely working solution:
I created a HTML template which is the basic structure for the invoice
The template is filled with data using GRMustache
I load the generated HTML file into a UIWebView and save it as PDF (I used NDHTMLtoPDF to do this)
So far, so good.
The problem with this solution is that page breaks don't work properly.
There are some tables and images and the page break often cut's off tables or images.
I have tried to use the page-break-inside: avoid; css property for the images and the tables but UIWebView seems to ignore them completely...
My question is:
Do you know how to fix the page break problem?
Can you recommend another solution to create PDFs on iOS?
Should I design the invoice in Storyboard and generate a PDF from the UIView? What about the page breaks here?
I would prefer to have a template (e.g. HTML), fill it with data and save it as PDF, rather than doing everything in code.

I actually wrote a PDF reporting component myself with presumably similar requirements:
templating is done via HTML / CSS
Static Header / Footer on each page
You can achieve this with UIPrintPageRenderer and UIViewPrintFormatter APIs, with the downside of probably getting your app rejected in the app store review, since you're using private Apple APIs. So this approach might only be viable in an academic setting or if your developing in-house apps.
There are some tutorials on how to do this which I'm not going to repeat, but for me these resources were quite useful:
http://www.fromdev.com/2014/06/how-to-create-a4-size-pdf-file-in-ios.html
http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer/

Related

Does ePub restrict HTML to only some subset?

I was thinking about creating an ePub reader. All the ePub files I have seen so far seemed very simple: just text paragraphs with some big font for the title, and some rectangular illustration images. So, I thought ePub provides only simple ways to describe the text content.
But it seems that an ePub file contains lots HTML and CSS. I opened a sample ePub and it contained text in <p> with the class attribute. Does it mean that it can basically be like a website archive? The author can use any advanced formatting/layout feature that are used when creating an HTML website? If so, I would have to implement a whole web browser to create an ePub reader.
Or, is the HTML allowed in ePub are somehow restricted to only certain HTML tags and attributes, like the HTML that is allowed when writing on an online forum.
PS: I did some research on my own after posting this, and my conclusion is that it is the former. I have tried some famous ePub apps on the Android market, and they all seem to be weird in terms of GUI (meaning, probably non-native),and whilst there does not seem to be a definitive way to know whether an app is native or a web-app, one trick was enabling the layout boundary, and those apps do not have boundaries inside the ePub view itself, meaningly it probably is a web-view.
I searched GitHub for ePub viewers, and they all seem to be using JavaScript or a web-view, including this Android ePub viewer.
So, probably those ePub apps are just parsing the meta data files in the ePub format, and for the rendering of the book itself, they are just delegating that to the web-view and using some sort of JavaScript framework to add a UI on the web-view.
If someone knows better, please correct me.
My understanding of previous ePub specs is that it is a web archive of sorts. A compressed archive consisting of metadata, fonts, images, and content.
It used to be that this content was only in a specially-flavored XHTML format, but it looks like they've also added SVG content documents. I've admittedly lost track of the ePub spec changes (I didn't realize they had merged efforts with the W3C), but hopefully the spec links above can give an idea of what's different between a standard html5 web page and what epub expects.
EDIT: I should also mention that a lot of the readers I worked with back in the day had the bad habit of stripping out formatting and just presenting text (not even text with embedded fonts -- a big no-no for non-English texts). Not sure if this was the reader software being "robust" and acting against ePub formatting that would break their app, or something else.

PDF4NET pdf's not showing the bound content when viewed on iOS default pdf reader

I am using Version 4.4.1.0 of O2S.Components.PDF4NET
I am using this in an MVC project to run through a series of 6 views and fill an object with the data required for the PDF.
When the PDF is bound and emailed in the last step it works great. all except for when it is viewed by default PDF reader on iOS devices.
My company purchased this product on the cheaper plan so the 90 support is over and I cannot access any sort of forums from there site.
I read a similar issue regarding a button not being displayed on iOS but there was no resolution other then to email the company.
I hope that there is a viable solution as I would prefer not to have to cut my losses and change to a different product over something as short sighted as not supporting/testing against one of the more common platforms people use to consume media.
I'm not sure what you mean by 'bound content' but I assume you are talking about form fields.
Forms fields and annotations are not displayed by the CGPDF API in iOS, only the main page content is displayed. It is not a limitation of PDF4NET, it is a limitation of the iOS PDF display engine. The workaround is to flatten the form fields thus making them part of the page content.
If this is not your situation, please send a mail to support and they will help you.
Disclaimer: I work for the company that develops PDF4NET.

How to implement an interactive PDF in iOS

Here im hitting my head againt the wall.
My client provided a pdf with buttons(just like buttons,when user tap on button,it will load next page and previous page etc.).
This buttons will work only when we open it in adobe reader.
I tried the QLpreviewview,quickview but it is not working,all what i can do is just to load the pdf in the webview.
Can anyone please help me in how to load an interactive pdf in iOS.
Thanks in advance.
Have a look at PSPDFKit, it is the most advanced framework I've found for PDFs in iOS. They have an impressive list of customers as well.
It is a bit pricy though, but you have the option to get the Source Code too if you need to modify anything. Could be worth it if your client need that kind of performance and other features as well.
(I am not in any way affiliated with PSPDFKit)
The limitations are due to the capabilities (or non-capabilities) of the PDF viewer used.
Currently the leading PDF viewer on iDevices is PDFExpert by Readdle. Adobe Reader for iDevices is weaker, but can deal to some extent with form elements.
For page navigation etc. you might use links instead of button fields (as far as you can live with the capabilities of links, and not use JavaScript). Links are said to be handled properly with many PDF viewers.
You may have to require certain PDF viewers on instructional level, because you don't have control over the viewer used by the actual user. And, as you noticed, many PDF viewers are simply too dumb do deal with active elements.
Another approach would be looking at PDF-to-HTML5 converters, and serve HTML5 from a server.

How to edit PDF Forms in iOS application?

i have a lots of PDFs forms and i want to put them on iPad and fill them up, then send it by mail. how can i edit this pdf forms in an app? i am very new with xCode and i could use lots of suggestions ...
How can I edit PDF files in an iOS application?
i found this question durring my search and the idea presented here,
"A better idea in my opinion is to create a native UI showing the data contained in the PDF file using the standard Cocoa-Touch UIKit, and create the PDF once the user is done with it so that the user can export it back. That way, you don't have to write a complicated PDF handling code." .. sounds very good just that i dont know how to start ...
Thanks
Basically, what it's saying is create a nib/screen/front end to the PDF that would allow the user to record what data they want in there, then after that run a separate piece of code to write that data into the PDF!
Some links to help you out:
Quartz-2D Programming Guide (QuartzCore Framework): https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
A tutorial (Although aimed at iOS5)
http://www.raywenderlich.com/6581/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-1
I will say, I can find information on GENERATING PDF files a lot easier/more reliably than editing them... Are the templates you have difficult? It may be worth re-creating them programatically when the data is inputted!

What's a good way to "standardize" the format of web content for importing into an app?

I'm working on a project where one of the requirements is to import articles from a website. The problem is that different websites have different formats. I could theoretically write some code that strips out extra content from known websites, but this is hardly maintainable. It sounds like there should be something already out there that can "RSS-ify" pages for me into some format, so that I can easily import content.
Is there such a service that I can just "plug" any website into? Also, what are my options here in regards to importing web content into an app, aside from this? How would you handle it?
Edit: Two things that come to mind are FeedBurner and Apple's Safari browser, which adds an "RSS" button. (Safari Mobile actually does one better and renders a neat read view in iOS 5.) Are they relevant to this question in any way?
It seems that there is none. The best I can do is work with content providers to offer RSS feeds and such.

Resources