IPhone / iPad Base64-> NSData-> PDF how?

Obj-C or Monotouch.Net C #'s answers are great.

I have a Base64 string, which is a PDF document retrieved through a web service. I can get NSData.

How to take NSData and save it as a PDF?

- I get NSData this way -

byte[] encodedDataAsBytes = System.Convert.FromBase64String (myBase64String);
string decoded = System.Text.Encoding.Unicode.GetString (encodedDataAsBytes);
NSData data = NSData.FromString (decoded, NSStringEncoding.ASCIIStringEncoding);
+3
source share
3 answers

I found that using the .NET platform works better than trying to use the iOS infrastructure for this problem. It takes any file and converts it to the original, and then saves it on the iPhone / iPad device. A β€œpath” is just a folder at the bottom of the ice.

using (var f = System.IO.File.Create (path))
{
   byte[] encodedDataAsBytes = System.Convert.FromBase64String (Base64PDFString);
   f.Write (encodedDataAsBytes, 0, encodedDataAsBytes.Length);
}
0
source

The easiest way to save it is probably to use the NSData method writeToFile:options:error:.

+3

, , . PDF, base64, - .NET, PDF .

:

  • ASIHTTPRequest -.
  • TBXML xml base64 NSString.
  • , QSUtilities, decodeBase64WithString.
  • , NSData writeToFile.

I tested and successfully used this method with PDF files that are up to 25 MB. I also had some test runs with a 48 MB file, but the decodeBase64WithString method in this file took up too much memory and my application crashed. We have not found a solution yet.

If you work with several large files, be sure to free your memory from time to time. I got all my files in one loop, in which I had to use my own nsautorelease pool and merge it at the end of the loop to free up any objects with auto-implementation.

0
source