iOS - Display PDF with signature - ios

I'm trying to display signed pdf in an iOS applications.
While displaying a PDF is easy (plenty of libraries, UIDocumentInteractionController, etc.), I can't seem to find how to display the signatures in the PDF.
By signature, I mean what is in this sample: http://blogs.adobe.com/security/SampleSignedPDFDocument.pdf
I've seen it done in an iOS application, but I've no idea how to do it myself. I tried poking around with CGContextDrawPDFPage, without much success.
Any hint?

The signature you saw in the PDF file is the appearance of the signature field widget. The field widget is a specific PDF annotation.
The problem with the default PDF rendering engine in iOS (used by UIDocumentInteractionController, QuickLook framework, etc) is that it does not display the annotations on the PDF page, it displays only the main page content.
The only solution is to use a 3rd party PDF rendering engine, such as MuPDF, Foxit, PDFTron, etc.

Are you converting HTML to PDF?
If yes then it may be helpful :)
UIGraphicsBeginImageContext(imgapplicationSignature.bounds.size);
[imgapplicationSignature.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self saveImage:image1 :#"imgapplicationSignature.png"];
NSString *documentsDirectory1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES)[0];
[wbView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"var imageElement = document.getElementById('img_01'); imageElement.setAttribute('src', '%#');", [NSString stringWithFormat:#"file://%#/imgapplicationSignature.png", documentsDirectory1]]];

Related

iOS create pdf from UIWebview content

In my app for iOS i need to create a pdf document from my webview content. I watched these posts: Creating PDF file from UIWebView and https://coderchrismills.wordpress.com/2011/06/25/making-a-pdf-from-a-uiwebview/
I wonder if there is a simpler way to do it. For example for my project for Mac i use this:
NSData *pdf = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame];
PDFDocument *doc = [[PDFDocument alloc] initWithData:pdf];
Is there any simple way to do this in iOS?
Which is the best option to obtain best quality pdf document from a webview content?
There isn't a method that allows this directly via the SDK like there is on Mac however you may wish to take a look at BNHtmlPdfKit which allows you to save the contents of URLs, web views and also html strings as PDFs.
For example, as follows:
self.htmlPdfKit = [BNHtmlPdfKit saveUrlAsPdf:[NSURL URLWithString:#"http://itsbrent.net"] toFile:#"...itsbrent.pdf" pageSize:BNPageSizeA6 success:^(NSString *pdfFileName) {
NSLog(#"Done");
} failure:^(NSError *err) {
NSLog(#"Failure");
}];
It makes use of a custom UIPrintPageRenderer which overrides paperRect and printableRect thus causing the UIPrintFormatter to return a pageCount as well as render the document.
I found good answer by AnderCover at
"Creating PDF file from UIWebView"
also it's not using any third party api. To create pdf from webview.
Hope it help's you.

How can I get raw data of image from UIPasteboard if it's copied by another app (such as photos, safari, etc..)

Is there a way to get raw data of image from UIPasteboard instead of UIImage if it's copied by another app such as photos or mobile safari?
I'm currently facing wired differences between IOS 6.0 and IOS 6.1(7.0 also)
In IOS 6.0, UIPasteboard's item of the copied image by photos or mobile safari contains raw data of the image.
But In IOS 6.1 and above, it contains UIImage instead of raw data.
In IOS 6.0, copied item of UIPasteboard is below
Printing description of array:
<__NSArrayM 0x8a804c0>(
{
"com.compuserve.gif" = <47494638 39614002 ...... 3b3a2000 3b>;
"public.url" = "url of the image....";
}
)
In IOS 6.1 and above, it contains UIImage instead of raw data.
Printing description of array:
<__NSArrayM 0xa25b7b0>(
{
"com.compuserve.gif" = "<UIImage: 0x9429570>";
"public.url" = "url of the image...";
}
)
If that image format is PNG or JPEG, it's not that bad.
(I still have to compress again if it's JEPG though.)
But when I try to paste animated gif image, it becomes more complicated.
I don't know even it's passible to create animated gif image from normal UIImage.
I can download again from original url, but downloading data that I already have seems not good solution I think.
And also, if it's copied from photos app, there's no such url. (there's some mysterious uri named "com.apple.mobileslideshow.asset-object-id-uri" that is undocumented instead of url)
There seems a workaround, because when I try to do exactly same action between photos and email app, It works properly
Any suggestions?
Well now, I figured it out myself.
You can simply get raw (binary)data of the image form general pasteboard by sending
dataForPasteboardType:(NSSting*)PasteboardType message to general pasteboard, if it's copied from Apple's built-in Mobile Safari or Photos App. (#"com.compuserve.gif" for the pasteboard type in my case)
I myself feel a bit foolish for not having checked all the passible methods sooner. :(
My confusion comes from items property of the UIPasteboard.
I thought that items are containing all of data of current pasteboard. So I try to save that array from pasteboard and want to use it later, but I were totally wrong.
As documented in UIPasteboard Class Reference, the items property contains dictionary with key being the representation type and the "value" the object associated with that type.
At this point of time, The "value" refers really "value" of the representation, not the data of that type. This meaning of the "value" is the same as the value of thesetValue: forPasteboardType: method.
On the other words, you cannot retrieve raw(binary) data of the image from items property, even if you set the image to the pasteboard by sending setData: forPasteboardType: message.(I tested it on IOS 7)
In addition, raw data of the image from items property in IOS 6.0 seems a bug of that OS version. (This may not true, it's just my opinion)
You can get NSData from UIPasteboard if you specify right PasteboardType:
NSData* pasteData = [[UIPasteboard generalPasteboard] dataForPasteboardType:(NSString*)kUTTypeJPEG];
Do not forget to import
<MobileCoreServices/MobileCoreServices.h>
The UIPasteBoard will contain whatever is placed in it. It's up to the app that is copying to the paste board to put the contents in the proper format. The app can place items as raw binary data or as objects such as UIImage in the paste board.
If you're getting something different between iOS versions, you're probably using different versions of the app or it's simply copying things differently.
You're right that you can't represent an animated GIF in a UIImage because a UIImage only contains a single image. Perhaps the app is just copying the first frame's bitmap data in that case?
You can convert a UIImage to raw JPEG data using UIImageJPEGRepresentation.

Issue on attaching csv & pdf file- Objective c [duplicate]

I'm working with PDF generation,it generated the PDF, viewed using QLPreviewController, all worked fine except mail forwarding, I have two attachments of type .pdf and .csv. I have the following issues while emailing.
sometimes no attachments while emailing
pdf size will be very huge when pdf contains image(10 mb for one page pdf, if it contains image)
Problem is when testing in device,in simulator it all works fine...,
I come to know some exporting or importing UTI associated issues here
since I am a starter I feel difficult to understand it, I think some UTI's I have to add somewhere.. Can anyone please help me to identify the issue and solve, please. Thanks in advance.
1. Attachment issue
set mime type as text/csv instead of application/csv or image/csv. code is as shown below
[mailComposer addAttachmentData:[NSData dataWithContentsOfFile:self.csvFilePath]
mimeType:#"text/csv" fileName:[NSString stringWithFormat:#"csvPage.csv" ]];
1. Size issue
I struggled a lot.. at last when wrote image in jpeg format to pdf page using below code, size got reduced ten times!!
UIImage *lowResImage = [UIImage imageWithData:UIImageJPEGRepresentation(plotImage, 0.02)];

Google drive API combining image and text

I am trying to upload a file and an image using the google drive api example for iOS.
It's easy to upload text and image separately but I can't figure out how to upload both.
How do you combine an image and text?
If I do this:
NSData *fileContent = [self.textView.text dataUsingEncoding:NSUTF8StringEncoding];
NSData *imageData = UIImagePNGRepresentation(self.someImage.image);
NSMutableData *uploadData = [NSMutableData dataWithData:fileContent];
[uploadData appendData:imageData];
uploadParameters = [GTLUploadParameters uploadParametersWithData:uploadData MIMEType:#"multipart/related"];
It will upload both but I can't view it on my drive.
Do I have to create a google doc?
If so, what is the format of a google doc?
I create a doc on my drive and added some text and image to it so that works, so google docs can definitely handle text and images in the same file.
I searched for Google doc format but nothing comes up there either (if this is the right approach).
If you're trying to upload a formatted document that contains both text & images, that is considered a single file and must be uploaded that way. There isn't a way to directly upload in the native Google Docs format, but you can use one of the other supported formats like DOCX, PDF, etc and convert them.

Move data/images between two iOS apps using custom URL handler

After googling around and searching SO for a while, I stil couldn't find an answer -
I've wondered, How could I transfer data between two of my apps using custom URL handlers? Specifically images or an NSData object for that matter.
I know about being able to open specific parts of my app using custom handlers such as myapp1://start , myapp2://start , but I'm not sure how to go on transferring large amounts of data (~80k) through these handlers.
Would love to hear any creative solutions :)
p.s. The solution should be iOS >= 4.3 Compatible
Use the custom URL handlers in combination with UIPasteboard. Save something from your first app (say, an image) to the general pasteboard, like so:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[[UIPasteboard generalPasteboard] setImage:myImage];
Then use the custom URL schemes to switch apps.
Then retrieve your image from within the new app when you need it:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
UIImage *tempImg = pasteboard.image;
Battle-tested. ; )
One Solution could be:
Implement a Webserver
Open up your second app via the custom url scheme with the IP-adress and the port of your custom web server included in the url
Add the route or parameters to your image also to your URL
Download and enjoy your photo :-)
Another Solution:
Start a Bonjour service
in a network the second app can find this service
do some magic to pass the data in between the apps
EDIT:
BETTER OTHER SOLUTION:
Just found another, but much more efficient way to do exchanges of larger data sets:
It is called UIPasteboard
Best reference for that:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html
And another resource:
http://kmithi.blogspot.in/2012/03/sharing-data-among-ios-applications.html
That should do it.
For a webserver: There are tons of implementations found using Google
[http://www.codeproject.com/Articles/43447/How-to-Use-UIPasteBoard-to-Implement-Custom-Copy-a][1]
As you know many of the controls in UIKit now come pre-loaded with the ability to copy and paste text. You can also use this new ability in your own apps to copy and paste other things including: images, SQLite databases, text or any file. This is a great way to share data between your apps if you want to provide users with a suite of apps with integrated functionality.
CopyFrom Source Code
-(IBAction)copyImageToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:#"CopyFrom"
create:YES];
appPasteBoard.persistent = YES;
NSData *data = UIImagePNGRepresentation([UIImage imageNamed:#"Old-Time-Photo.jpg"]);
[appPasteBoard setData:data forPasteboardType:#"com.appshop.copyfrom.imagedata"];
}
-(IBAction)copyStringToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:#"CopyFrom"
create:YES];
appPasteBoard.persistent = YES;
[appPasteBoard setString:textView.text];
}
PasteTo Source Code
-(IBAction)pasteImageToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:#"CopyFrom"
create:YES];
NSData *data = [appPasteBoard dataForPasteboardType:#"com.appshop.copyfrom.imagedata"];
imageView.image = [UIImage imageWithData:data];
}
-(IBAction)pasteStringToPasteBoard{
UIPasteboard *appPasteBoard = [UIPasteboard pasteboardWithName:#"CopyFrom"
create:YES];
textView.text = [appPasteBoard string];
}
Using UIPasteBoard in iPhone programming is amazingly simple and opens up some possibilities that we did not have a year ago. To use UIPasteBoard you simply create a instance using pasteboardWithName, put stuff into the paste board and then set the persistant property equal to YES. Then any app can get a reference to your paste board and use the data contained within. You can use it for simple strings and even data that you can put into NSData like SQLite databases.
Well, as far as I can tell ~80k is too much for a custom URL handler. But you could try to Base64-encode your data and append it to the custom URL. But I doubt that it will work with lots of data.
You could also have a look on the UIDocumentInteractionController, which is intended to open files with other applications that support them. This is what the Mail application does when you open an attachment with another app.
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009304
using custom URL handler
it is specified, so it will not meet your specification.
But if you don't care about that, I would write to internal memory (file system)the 80k image, even if 80Mb and pass the "url" for the other app.
Big ego, and 0 effort in research:
copy to images folder
IPC communication via url
and my solution doesn't work... I am not giving fish, just teaching hot to get a fish.

Resources