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

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)];

Related

How to copy from Storage to FileSystemStorage in Codenameone and display in BrowserComponent

I've been reading a lot of StackOverflow posts that discuss copying data from FileSystemStorage to Storage in CodenameOne, such as described in this answer from Shai, as seen below:
InputStream stream =
FileSystemStorage.getInstance().openInputStream(i);
OutputStream out =
Storage.getInstance().createOutputStream("MyImage");
Util.copy(stream, out);
Util.cleanup(stream);
Util.cleanup(out);`
I've been trying to do the reverse: save from Storage to FileSystemStorage in order to show a PDF in the BrowserComponent (while using iOS), but have not been able to do so. I need to show the PDF within the app (so I don't want to use Display.getInstance().execute()).
Basically, I'm trying to dynamically populate a Container with whatever files the user selects-- I am using the FileChooser library for CN1 from Steve Hannah. (Disclaimer: I have made slight modifications to this library as it used in the app I'm working on-- HOWEVER, when I choose images with this library and pull them from Storage to an Image via InputStream, they display perfectly in an ImageViewer so I know that all files are being saved correctly in Storage.)
Here is my code (with help from Steve Hannah's comment on GitHub):
//fileLocation and fileName are slightly different but both end with file extension
File file = new File(fileToUpload.getFileName());
FileSystemStorage fss = FileSystemStorage.getInstance();
InputStream is = Storage.getInstance().createInputStream(fileToUpload.getLocation());
OutputStream os = fss.openOutputStream(file.getAbsolutePath());
Util.copy(is, os);
ToastBar.Status status = ToastBar.getInstance().createStatus();
String message = file.exists() + " " + file.isFile() + file.getAbsolutePath();
status.setMessage(message);
status.setExpires(3000);
status.show();
NativeLogs.getNativeLogs();
if (Display.getInstance().getPlatformName().equals("ios")) {
//Log.p("in ios !!!!");
BrowserComponent browserComponent = new BrowserComponent();
browserComponent.setURL(file.getPath());
horizontalContainer.add(browserComponent);
}
The ToastBar displays true and true for file.exists() and file.isFile().
I stipulate iOS because as far as I've seen while researching previewing PDFs within an app, I've seen that Android needs to have a different implementation, like adding a NativeInterface with an Android library. I also saw in different answers on the Google Group that this functionality (using browserComponent to view PDFs) is only available for iOS and not on the simulator. In the simulator, I see a blank space. My iPhone just freezes and/or crashes after displaying the ToastBar (and I work on a Windows machine, so not much ability to see native logs....)
What can I do to access the file and show it in the BrowserComponent?
Thank you!
Simple solution -- the file had a space in it (eg. "Test page.pdf") and didn't show! When I used files that didn't have spaces this worked and after removing spaces in the file names, thankfully everything worked. I'll have to add code to handle this scenario.
Thanks for your help!

UIGraphicsBeginPDFContextToData creates PDFs unreadable by Acrobat

Im creating PDF's from iOS using a ordinary code block.
NSMutableData *pdfdata = [NSMutableData dataWithLength:2048];
CGRect newf = CGRectMake(0, 0,1024,1024);
UIGraphicsBeginPDFContextToData(pdfdata,newf,nil);
UIGraphicsBeginPDFPage();
//rendering code
UIGraphicsEndPDFContext();
iOS and OS X read these PDF's just fine but Acrobat claims they are damaged and unreadable. The interesting thing is that doing a duplicate in Preview unmangles them and makes them readable by Acrobat again.
By diff-ing the two versions I can see that the OS X PDF encoder has added a bunch of stuff (its binary so no idea what)
Anyone know the secret sauce to making my PDF's Acrobat compatible again.
EDIT
Broken file - will not open in Acrobat
The document starts with a block of 2048 bytes filled with zero and this damages all offsets in the file.
Create an empty NSMutableData without initial length and the problem should be fixed.

iOS - Display PDF with signature

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]]];

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.

Powerpoint OOXml - differentiate an image from a video?

I'm just barely getting started with ooxml, working off of someone else's code (in F# which I'm only tangentially familiar with), and on a deadline so forgive me if this is a dumb question.
I have a pptx powerpoint file with two items on it. An embedded image, and an embedded video.
As best as I can tell, when using the OpenXml SDK to parse the file, both videos and images appear as DocumentFormat.OpenXml.Presentation.Picture.
How do I differentiate which is actually a video?
Look inside the PPTX itself for a direct look at what the SDK is interpreting and passing back to you.
If you add JUST a video to an otherwise blank presentation, there'll be both the video file and an image in the \media folder of the PPTX. The image is something PPT creates from the video ... it's the posterframe, what PPT shows you when the video isn't running.
I'm not positive but suspect that if there's a media[x].wmv file there, the poster image will be image[x].png (possibly a different extension, but same number [x], I think.
You can also look in:
\ppt\slides\_rels\slide[x].xml.rels
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="../slideLayouts/slideLayout1.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Id="rId3"/>
<Relationship Target="../media/media1.wmv" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/video" Id="rId2"/>
<Relationship Target="../media/media1.wmv" Type="http://schemas.microsoft.com/office/2007/relationships/media" Id="rId1"/>
<Relationship Target="../media/image1.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Id="rId4"/></Relationships>
Notice that images and videos/media have different Type="xxx" info.

Resources