Evernote and SBApplication bridge - createNoteWithENML issue - resources added twice - objective-c

The problem:
//Create Evernote App SBApplication
EvernoteApplication *evernoteApp = [SBApplication applicationWithBundleIdentifier:#"com.evernote.Evernote"];
evernoteApp.delegate = self;
//Take this ENML Code
NSString *enml = #"<div>This is an encrypted text for OneNote Saferoom.</div><div><br/></div><div>PDF file</div><div><en-media type=\"application/pdf\" style=\"cursor:pointer;\" height=\"43\" hash=\"fa7d7e650b2cec68f302b31ba28235d8\"/></div><div><br/></div><div>Image</div><div><en-media style=\"height: auto;\" type=\"image/png\" hash=\"64957a2bd851f625383a5b9e410965d7\"/></div>";
//Create correct Array of URLS for above (Set the URLs before)
NSArray *resourceURLs = [NSArray arrayWithObjects:url2,url1,nil];
//Upload the note to Evernote
[evernoteApp createNoteFromFile:nil fromUrl:nil withText:nil withHtml:nil withEnml:[NSString stringWithFormat:#"<en-note>%#</en-note>",enml] title:noteTitle notebook:workingNotebook tags:tags attachments:resourceURLs created:nil];
And now I get the note with additional duplicated resources (Evernote app just adds all resources from resourceURLs array to the end of the note):
Tried the following
remove resourceURLs array - no resources added
using HTML and adding resource URLs - structure is not kept, resources appear at the end only
converting from ENML to HTML using Inline resources function (ENMLUtility) - resources are not displayed
I am starting to believe that there is a bug in how Evernote.app handles createNote request.
Resources to test
PDF sample file for above resource:
https://www.dropbox.com/s/t8pgzzexms0nl7w/dec-pdf-sample.pdf?dl=0
Image sample
https://www.dropbox.com/s/nagaei1hng6ziwc/dec-touchID_blue_80%403x.png?dl=0
Generated Evernote.h file for bridging:
https://www.dropbox.com/s/7u1zdb8c71ydwag/Evernote.h?dl=0
Any help will be appreciated.
Update 1:
Tested with pure AppleScript, still resources are duplicated:
https://www.dropbox.com/s/rvpc4est8ef7q4c/EvernoteAppleScript_bug.scpt?dl=0
Thanks,
Ilia

Related

Generating and Downloading a PDF

I am developing an Android app for flight reservation and i am using firebase Database for storing and retriving data. I need to generate a PDF of Ticket and contents should be changed as per passenger details and stored in local directory. I have a template of Ticket. What should i do?
Thank you in advance.
Since Android 5 you can use PdfDocument and its friend classes to generate a PDF document on Android device. The official documentation is here. There is no library to use a template with PdfDocument. You have to use some drawing primitive to accomplish your task.
Here is a sample to generate a PDF with a single page A4:
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(595, 842, 1).create();
// start a page
Page page = document.startPage(pageInfo);
Canvas canvas=page.getCanvas());
// draw something on the page
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawCircle(50, 50, 30, paint);
// finish the page
document.finishPage(page);
// write the document content
document.writeTo(getOutputStream());
// close the document
document.close();
The page content is defined with Canvas object. Just another example. I hope this helps you.

How do you add a picture to the ID3 Album tag using taglib#

I've been searching the internet and trying various methods to save a picturbox image to the the id3 Album picture tag. One sample code says the Album cover tag name is taglib.ipicture another says taglibVariable.Image and yet another says taglibVariable.picture(0).
I am becoming so confused I'm starting to repeat sample test code.
Where is the documentation that will explain what I have to do.?
What little information I can find are dead links to sample code or incomplete code using variables without explanations. When I look up the commands and try to format or convert to the needed data type, I get an error. Usually system.image.bmp cannot be converted to iPicture.
Can anyone give me some working code or a pointer on how to word the proper search term to add a picturebox.image to the Album picture tag. Saving the image as a file then opening as image to put in tag then deleting file is not an option. I need to create a memory image and add that to the picture tag.
This is what I use:
public void SavePicture(string fileName, string picName) {
try {
IPicture[] pics = new TagLib.IPicture[1];
pics[0] = new TagLib.Picture(picName);
using (var songTag = TagLib.File.Create(fileName)) {
songTag.Tag.Pictures = pics;
songTag.Save();
}
}
catch {
// process
// mpeg header is corrupt
}
}
fileName is the full path to the audio file;
picName is the full path to the picture.
You can add multiple pics by setting the array size for the IPicture array accordingly...

HTML string to PDF conversion

I need to create various reports in PDF format and email it to specific person. I managed to load HTML template into string and am replacing certain "custom markers" with real data. At the end I have a fulle viewable HTML file. This file must now be printed into PDF format which I am able todo after following this link : https://www.appcoda.com/pdf-generation-ios/. My problem is that I do not understand how to determine the number of pages from the HTML file as the pdf renderer requires creating page-by-page.
I know this is an old thread, I would like to leave this answer here. I also used the same tutorial you've mention and here's what I did to make multiple pages. Just modify the drawPDFUsingPrintPageRenderer method like this:
func drawPDFUsingPrintPageRenderer(printPageRenderer: UIPrintPageRenderer) -> NSData! {
let data = NSMutableData()
UIGraphicsBeginPDFContextToData(data, CGRect.zero, nil)
printPageRenderer.prepare(forDrawingPages: NSMakeRange(0, printPageRenderer.numberOfPages))
let bounds = UIGraphicsGetPDFContextBounds()
for i in 0...(printPageRenderer.numberOfPages - 1) {
UIGraphicsBeginPDFPage()
printPageRenderer.drawPage(at: i, in: bounds)
}
UIGraphicsEndPDFContext()
return data
}
In your custom PrintPageRenderer you can access the numberOfPages to have the total count of the pages

Objc scriptingbridge how open new Finder window in a specific folder

I want to open a new Finder window of a specific size in a specific position and displaying a specific folder.
In ScriptingBridge (XCode 6, Mavericks 9.4) I can open a new Finder window and have figured out how to read the URL of the folder it opens. But I am really struggling with how to set the folder to something different.
I have tried to assign the window a 'target' SBObject initialised with a 'URL' property.
but the URL property is readonly although 'target' seems not to be. I've used 'get' to ensure there is a FinderFolder object and a FinderFinderWindow object.
I've tried using a dictionary of properties with a URL key and creating a 'folder'.
FinderFolder *folder = [[[_finder classForScriptingClass:#"folder"] alloc]
initWithProperties:dict];
[[_finder folders] addObject:folder];
I have read the Apple docs and looked for examples all over but cannot find an instance of someone assigning the folder path.
// open folder "Documents" of home folder
FinderFolder *theHomeFolder = [theFinder home];
NSLog(#"theHomeFolder: %#",theHomeFolder);
SBElementArray * theHomeFolderFolders = [theHomeFolder folders];
NSLog(#"theHomeFolderFolders: %#",theHomeFolderFolders);
FinderFolder *theDocsFolder = [theHomeFolderFolders objectWithName:#"Documents"];
NSLog(#"theDocsFolder: %#",theDocsFolder);
[theDocsFolder openUsing:nil withProperties:nil];
FinderFinderWindow * docsFolderWindow = (FinderFinderWindow*) [theDocsFolder containerWindow];
NSLog(#"docsFolderWindow: %#",docsFolderWindow);
docsFolderWindow = [docsFolderWindow get];
NSLog(#"docsFolderWindow: %#",docsFolderWindow);
// change its bounds
docsFolderWindow.bounds = NSMakeRect(64., 64., 800, 600.);
// other fun stuff…
[docsFolderWindow setCurrentView:FinderEcvwListView];
[[docsFolderWindow iconViewOptions] setArrangement:FinderEarrArrangedByName];
[docsFolderWindow cleanUpBy:#selector(name)];
docsFolderWindow.toolbarVisible = NO;
docsFolderWindow.statusbarVisible = NO;
docsFolderWindow.sidebarWidth = 0;
There are a few different ways. The other answer works, or you could explicitly make a new Finder window and set its target property:
NSURL *u = [NSURL fileURLWithPath:#"/tmp"];
FinderFinderWindow *w = [[[theFinder classForScriptingClass:#"Finder window] alloc] init];
[[theFinder finderWindows] addObject:w];
[w setTarget:u];
You could also set it to an SBObject referring to a Finder item, such as theDocsFolder from the other answer.

How to upload photo with Rubymotion?

I am building an iOS app using Rubymotion.
I need to let the user snap a photo with the camera and then upload it to a Rails 3 backend (with Paperclip) using the BubbleWrap Http module (or any better?).
How can I do this?
This is my code:
controller = UIImagePickerController.alloc.init
controller.sourceType = UIImagePickerControllerSourceTypeCamera
controller.mediaTypes = [KUTTypeImage]
controller.allowsEditing = true
controller.delegate = self
self.navigationController.presentModalViewController(controller, animated:true)
This I use after taking the shot:
metadata = info.objectForKey(UIImagePickerControllerMediaMetadata)
the_image = info.objectForKey(UIImagePickerControllerOriginalImage)
image = view.viewWithTag 3
image.image = the_image
picker.dismissModalViewControllerAnimated(true)
This is my upload code:
data = {access_token: TOKEN, id: task, image: image}
BubbleWrap::HTTP.get("#{URL}#{project}/message", {payload: data}) do |response|
if response.ok?
json = BubbleWrap::JSON.parse(response.body)
if json['total'] > 0
infos = json['taskinfos'].map {|ej| self.from_json(ej["taskinfo"])}
block.call(true, infos)
else
block.call(false, nil)
end
else
block.call(false, nil)
end
end
Uploading images should be done via a POST request and not a GET request like you have done. Most web servers have a limit to how big a GET request can be, and it is usually 8k, read here for more info maximum length of HTTP GET request? , so it's not suitable for images.
Play around with bubble motion and look at the requests in the log files on the server to see what comes out. Try to make the request look like a request made from within rails itself, ie from a web page where you upload to the the controller.
So you could change the request to POST and let people know what error messages you get.