How to store a PDFDocument fast? - ios

Problem1 : I have a PDF document containing 1300 pages. Users are able to add and remove pages from it. If I want to store the new PDF Document I have to convert it to data with (.dataRepresentation() ). This takes about 10 seconds which is way to long (What if the user terminates the app).
Solution: Split the document in 1300 PDF's, each one containing 1 page. Store this PDF inside an array called var pages = Data. Users can now add and remove new Pages from this array easily. I don't have to call .dataRepresentation() anymore.
Problem 2: When I use this method i have a new problem. The memory for this array is very huge. About 400mb. The PDF document itself is only 46mb.
How can i solve this problem ? Is there maybe another way ? Please help me out i can't find any solutions :(

Related

Titles of .txt files saved locally are loading in random order in tableview - how to force a specific order?

I have a list of .txt files saved to Bundle and I list their titles to a tableview and load contents when row is clicked. I'm having a 2 fold issue.
1. The .txt files load randomly and in no particular order. I'm loading files like this right now:
func loadStories() {
stories = Bundle.main.urls(forResourcesWithExtension: "txt", subdirectory: nil)!
}
Is there a way to force a particular order for the list?
2. I'm also having a loading lag of a few seconds the longer the .txt file is and it was suggested that I should maybe convert my files to .xml instead to speed this up. Is this a good solution?
I'm also using firebase for authentication but as I understand it, firebase would not be a faster solution for files that are read only and not going to be changed. What can I do to help speed up the load?
1. The .txt files load randomly and in no particular order. I'm loading files like this right now:
I suppose stories is a collection (Dictionary / Array). Apply sorting in this array before reloading the UITableView
2. I'm also having a loading lag of a few seconds the longer the .txt file is and it was suggested that I should maybe convert my files to .xml instead to speed this up. Is this a good solution?
I think you are talking about the content of the files when showing details. You can add pagination in this case load part of the file (a few lines) show it. Then when further paged load further.
Example : Sorting on string objects in swift array as asked in comment:a
let months = ["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"]
var sortedArray = months.sorted { $0.localizedCaseInsensitiveCompare($1) == ComparisonResult.orderedAscending }

Generate multiple tables using ajax call

I am using jsPDF and jsAutotable to generate pdf for the table that is in the DOM.
First of all I want to create multiple tables that are present in the DOM using a button click.
Secondly I also want to create pdf file for multiple tables using an ajax call to the server using another button. I have tried to look around for some tutorial but have not found anything specific.
Can anybody help please.
I have been able to create multiple tables. Since I needed to create two tables in my pdf file, so I needed to call autoTableHTMLToJson function twice after getting the information from my html tables. After doing this you can define the options for each of the table also. Since there is very limited assistance available for js auto table so if anyone needs help in this regard just comment below, I might be able to help.
var elem = document.getElementById('employee-table');
var data = doc.autoTableHtmlToJson(elem);
var elem2 = document.getElementById('employee-table2');
var data2 = doc.autoTableHtmlToJson(elem2);

ios creating multiple-page pdfs

How would I go about creating a multiple page pdf from a scrolling view? I am trying to convert an invoice pdf and it is much longer than 1 page; not sure how to create more.
also while on this, the pdf also seems to be quite choppy in quality ( very rasterized ) - any tips to improve this? i realize it's not vectorized, hence the choppy look, just looking for a way to make it better? thanks
To create multiple pdf, after creating each page you can convert the entire page to an image an store it in an array, one by one. Then you can show each image from the array as scrollview if thats what you meant.
You can create pdf pages and write it to a file with following function. Call it for each page.
-(void)savePDFImageToDocumentDirectory:(UIImage *)pdfImage withPageNumber:(int )pageNumber{
NSString *tmpPngPath = PDFTempDirectoryPath;
NSString *pageName = [NSString stringWithFormat:#"PDFPage%d.png",pageNumber];
NSString *imagePath = [tmpPngPath stringByAppendingPathComponent:pageName];
[UIImagePNGRepresentation(pdfImage) writeToFile:imagePath atomically:YES];
}
You can follow two approaches tom create pdf. One through html method and the other is from xib files. Html method is fast but pdf will be of less quality. xib method gives you high quality pdf but uses a lot of memory.
If you are happy for the PDF generation to be remote you could use a service like Docmosis cloud services or Aspose to create the Document and stream it back to the device (or email it or both etc).
Typically these PDF tools wouldn't build documents from images like screen shots - you would send the data you want populated instead. This means the quality is very good (and text is selectable etc) and multiple pages is expected making the PDFs more generally useful.
Please note I work for the company that created Docmosis.
Hope that helps.

How to store a picture within Active Directory using Ruby in a Rail3App?

All I want to do is to upload an image into the Active Directory. So far I can update any AD information but the image. I have tried to search for some idea but came up with nothing so far.
Do I have to encode an image in a certain way? Do I just ldap-replace the jpegPhoto attribute with a byte-string of the photo?
Any hint towards a solution would be great.
Thanks in advance!
First of all, there is an attribute in Active directory called thumbnailPhoto. According to this Microsoft article The thumbNailPhoto attribute contains octet string type data. The AD interprets octet string data as an array of bytes.
If you want a sample code in C# you can get something here.
On the theorical point of view you can also inject a photo with LDIF using tools like "B64" to code your image file in base 64.
Secondly, On my point of view a Directory is not a database.
So, even if the attribute exists (created by netscape according to the OID 2.16.840.1.113730.3.1.35), even if Microsoft explain us how to put a picture into Active Directory, I think that it's better to register an URL, or a path to a file from a file system into a Directory.
I have no idea of the impact on performance of AD if I load each entry with 40 Ko (average size of a thumbnail photo). But I know that if there are bad written programs on the network, I mean kind of program that load all the attributes when they search an entry into the directory, this will considerably load the network.
I hope it helps.
JP
I had this issue and was able to get it working by creating a File stream and passing it through to #ldap.replace_attribute as a binary file. i.e.
thumbnail_stream = open("path_to_file")
#ldap.replace_attribute USERS_DN, :thumbnailPhoto, File.binread(thumbnail_stream)
Where #ldap is an instance of net/ldap, bound to AD. i.e.
#ldap = Net::LDAP.new
#ldap.host = ''
#ldap.port = ''
#ldap.auth USERNAME, PASSWORD
#ldap.bind

How to export MovieClip to SWF via AS3?

I've wrote some application in Flash cs5, wich allow users to make their own Christmas Cards, but at the end of programming I realized, that I should to provide some function to save user's card to seperate SWF-file...
Please, anyone who knows, help me! I tried to find something in Google, but all what I understand is that I should use ByteArray. But I can't really get, HOW I can use it in my case?
All I have found is this four lines:
var buffer:ByteArray = new ByteArray();
buffer.writeObject(MOVIE_CLIP_HERE);
buffer.position = 0;
buffer.writeBytes(...);
For seniors maybe it can help, but I can't get how with help of this lines I can solve my problem... thank you very much)))
You will need some server-side technology, like PHP or ASP, because Flash Player can't save anything on disk. And if you think about creating a swf file programmatically, that can be very difficult. That being said, this is how I would do this:
First, I would write the movieclip to a ByteArray, just like in your example:
var buffer:ByteArray = new ByteArray();
buffer.writeObject(card_mc);
Then I would send the byte array to a PHP script which would save the data from the byte array in a file (a text file will do). The saved data will actually be your serialized movieclip.
Then, I would create a swf file which will serve as the actual card, but it will be in fact a container for the saved movieclip. This file will load the data from the text file into a ByteArray and deserialize the movieclip:
var loadedClip:MovieClip = MovieClip(byteArray.readObject());
Once you have managed this, you're done. When users save their cards to their computer, you can send them the container swf file and keep the data file on your server (but in this case the swf will need to load the movieclip from your server), or you can give them both files.
I hope this helped.

Resources