Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 60

AussieRyan
Aspiring developer
Profile
Posts: 148
Reg: Mar 21, 2012
Margate, QLD Au...
1,480
03/08/13 05:05 AM (12 years ago)

PDF Print Option & Viewer Optimization - revisited

I have followed the thread at: http://www.buzztouch.com/forum/thread.php?tid=A45B68E6B90EF8D23D8CCD3 and used the PDF: http://jc-evans.com/wp-content/uploads/2012/07/Add-a-Print-Button-to-a-BT-App.pdf I added the amendments by @GraciousWolf_PE and it works, to a degree. It will only work if the PDF is included with the source code. It does not work for an external URL. I have no obj-c coding experience, but it appears that in the file BT_screen_pdfDoc.m (around line 70) the amended code uses the variable localFileName, but when an external URL is entered in the Control Panel, this sets the variable setSaveAsFilename. I tried substituting the variables, but it does not print. Can anyone provide an answer?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/08/13 05:29 AM (12 years ago)
Don't have a computer in front of me to see the code, but saveAsFilename is just a string with a name in it, not a reference to an actual file. It (should) take this string and apply it to the NSData object (which is the downloaded file) to save it to the device for offline use. I don't remember what the method name is for handling that save off the top of my head, but it probably uses the BT_FileManager class. Similarly, the localFileName variable is just a string with a name. It has to be applied to some file on disk and assigned to an object. You need to figure out what that object is and point it to the NSData downloaded from the internet
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/08/13 05:42 AM (12 years ago)
Just took a look at the how-to and found the code. Lol. Here is the important part: -(IBAction)printdoc { NSArray *components = [shareTitle componentsSeparatedByString:@"."]; NSString *newString = [components objectAtIndex:0]; NSString *path = [[NSBundle mainBundle] pathForResource:newString ofType:@"pdf"]; NSData *myData = [NSData dataWithContentsOfFile: path]; What this is doing is loading the file (NSData object) from the "bundled" files on disk. This means files bundled at time of compile, not run time. You need to add support for other files by pointing to the path used for saving files to disk. Your saveAsFileName string should be appended to a path on disk in a similar manner as the NSString *Path is above. Probably in the "documents" directory. Interesting note about this directory: Buzztouch deletes everything in this directory whenever the app is refreshed, unless the filename begins with "persist_". That way it is treated like a cache directory that gets renewed when the app is refreshed.
 
AussieRyan
Aspiring developer
Profile
Posts: 148
Reg: Mar 21, 2012
Margate, QLD Au...
1,480
like
03/08/13 02:00 PM (12 years ago)
Thanks, but that is way beyond my lack of knowledge.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/09/13 12:07 PM (12 years ago)
@AussieRyan -- have another shot of courage. You're doing great by diving into that code. The rays of light will hit for each time you revisit the tips from Chris. It requires nibbles with multiple readings. Comprehension will come to you eventually! @Chris -- you made me laugh with glee! In less than a year, we've seen you mature from a rookie to a codeslinger! Makes us wonder when you are the one confusing folks with all the Dev talk! :-) All smiles, -- Niraj
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.